playMaker

Author Topic: ArrayMaker is now available [JANUARY 2016]  (Read 75641 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: ArrayMaker is now available
« Reply #30 on: May 17, 2012, 05:02:08 AM »
Hi,

 While I am at it, I have also created am easier iteration class to loop through items of an arrayList ( I haven't made it for hash tables, but can do if you so wish). thanks to this original post:

http://hutonggames.com/playmakerforum/index.php?topic=1577.0

Code: [Select]
// (c) Jean Fabre, 2012 All rights reserved.
// http://www.fabrejean.net
//  contact: http://www.fabrejean.net/contact.htm
//
// Version Alpha 0.7

// INSTRUCTIONS
// Drop a PlayMakerArrayList script onto a GameObject, and define a unique name for reference if several PlayMakerArrayList coexists on that GameObject.
// In this Action interface, link that GameObject in "arrayListObject" and input the reference name if defined.
// Note: You can directly reference that GameObject or store it in an Fsm variable or global Fsm variable

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Each time this action is called it gets the next item from a PlayMaker ArrayList Proxy component. \n" +
"This lets you quickly loop through all the children of an object to perform actions on them.\n" +
"NOTE: To get to specific item use ArrayListGet instead.")]
public class ArrayListGetNext : ArrayListActions
{
[ActionSection("Set up")]

[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;

[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject")]
public FsmString reference;

[Tooltip("Event to send to get the next item.")]
public FsmEvent loopEvent;

[Tooltip("Event to send when there are no more items.")]
public FsmEvent finishedEvent;

[UIHint(UIHint.FsmEvent)]
[Tooltip("The event to trigger if the action fails ( likely and index is out of range exception)")]
public FsmEvent failureEvent;



[ActionSection("Data Storage")]
[UIHint(UIHint.Variable)]
public FsmBool getBoolData;
[UIHint(UIHint.Variable)]
public FsmInt getIntData;
[UIHint(UIHint.Variable)]
public FsmFloat getFloatData;
[UIHint(UIHint.Variable)]
public FsmVector3 getVector3Data;
[UIHint(UIHint.Variable)]
public FsmString getStringData;
[UIHint(UIHint.Variable)]
public FsmGameObject getGameObjectData;
[UIHint(UIHint.Variable)]
public FsmRect getRectData;
[UIHint(UIHint.Variable)]
public FsmQuaternion getQuaternionData;
[UIHint(UIHint.Variable)]
public FsmMaterial getMaterialData;
[UIHint(UIHint.Variable)]
public FsmTexture getTextureData;
[UIHint(UIHint.Variable)]
public FsmColor getColorData;
[UIHint(UIHint.Variable)]
public FsmObject getObjectData;



// increment that index as we loop through item
private int nextItemIndex = 0;


public override void Reset()
{

gameObject = null;
loopEvent = null;
finishedEvent = null;

failureEvent = null;

getBoolData = null;
getIntData = null;
getFloatData = null;
getVector3Data = null;
getStringData = null;
getGameObjectData = null;
getRectData = null;
getQuaternionData = null;
getMaterialData = null;
getTextureData = null;
getColorData = null;
getObjectData = null;
}


public override void OnEnter()
{
if (nextItemIndex == 0)
{
if ( ! SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
{
Fsm.Event(failureEvent);

Finish();
}
}

DoGetNextItem();

Finish();
}


void DoGetNextItem()
{

// no more children?
// check first to avoid errors.

if (nextItemIndex >= proxy.arrayList.Count)
{
nextItemIndex = 0;
Fsm.Event(finishedEvent);
return;
}

// get next item

GetItemAtIndex();


// no more items?
// check a second time to avoid process lock and possible infinite loop if the action is called again.
// Practically, this enabled calling again this state and it will start again iterating from the first child.

if (nextItemIndex >= proxy.arrayList.Count)
{
nextItemIndex = 0;
Fsm.Event(finishedEvent);
return;
}

// iterate the next child
nextItemIndex++;

if (loopEvent != null)
{
Fsm.Event(loopEvent);
}
}


public void GetItemAtIndex(){

if (! isProxyValid())
return;

System.Type valueType = null;
object element = null;

try{
valueType = proxy.arrayList[nextItemIndex].GetType();
element = proxy.arrayList[nextItemIndex];
}catch(System.Exception e){
Debug.LogError(e.Message);
Fsm.Event(failureEvent);
return;
}

if (valueType == typeof(bool) ){
getBoolData.Value = (bool)element;
}else if(valueType == typeof(Color) ){
getColorData.Value = (Color)element;
}else if(valueType == typeof(float) ){
getFloatData.Value = (float)element;
}else if(valueType == typeof(GameObject) ){
getGameObjectData.Value = (GameObject)element;
}else if(valueType == typeof(int) ){
getIntData.Value = (int)element;
}else if(valueType == typeof(Material) ){
getMaterialData.Value = (Material)element;
}else if(valueType == typeof(Object) ){
getObjectData.Value = (Object)element;
}else if(valueType == typeof(Quaternion) ){
getQuaternionData.Value = (Quaternion)element;
}else if(valueType == typeof(Rect) ){
getRectData.Value = (Rect)element;
}else if(valueType == typeof(string) ){
getStringData.Value = (string)element;
}else if(valueType == typeof(Texture2D) ){
getTextureData.Value = (Texture2D)element;
}else if(valueType == typeof(Vector3) ){
getVector3Data.Value = (Vector3)element;
}else{
//  don't know, should I put in FsmObject?
}

}
}
}


 Bye,

 Jean

Jos Yule

  • Playmaker Newbie
  • *
  • Posts: 33
    • View Profile
Re: ArrayMaker is now available
« Reply #31 on: May 17, 2012, 07:20:29 AM »
Thanks for this and the Randomize/Shuffle actions. I will checkout the GetNextChild action too, for further hints on how to best use this new action!

When i've tried these out i will report back with any feedback too.

Peace
jos


balasco

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: ArrayMaker is now available
« Reply #32 on: May 28, 2012, 01:44:54 PM »
Is there any chance you could add a new script to support multi dimension arrays? I need to build a 2D array for a game that uses a tile grid and using ArrayMaker would be ideal. Thanks

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: ArrayMaker is now available
« Reply #33 on: May 28, 2012, 02:46:59 PM »
in case your in a hurry you might want to create a jagged array. It's kinda cheating but it worked like a charm for me in the past :D
To make it, you just create an array which contains game objects that themselves contain an array. Then to get to say 5/2 on your field you just get the 5th object of your first array and then save it to a gameObject variable, and then use that variable to access the 2nd  value of the array on that gameObject.

Jagged arrays are awesome btw, because with  them you can finally create non rectangular 2D arrays :D
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: ArrayMaker is now available
« Reply #34 on: May 28, 2012, 10:57:39 PM »
Hi,

 I would love to be able to build a multi dimensionnal array system but it's going to be tricky because of the action User Interface limitations, It's getting in the way of building more complex systems.

 What I have in mind actually would be to create a csv/xml system very much like ArrayMaker, but dealing with xml under the hood, with a csv parser as well ( and why not json), then it would open fantastic perspectives usch as xpath queries.

right now, I would recommand to just split your multi dimensionnal arra yinto a set of arrays and simply maintain references, I do that all the time, it's working very well ( and exposes more, because a multid array would be difficult to display its content in the inspector)

So as kiriri is explaining, I would ( and actually am) use this technic for now.

 I unfortunately seriously lack of spare time to tackle this xmlMaker project ( I have input.touches framework and vectrosity framework currently cooking :) ), but if a project has sufficient fundings to support the initial kick to get that up and running, I would be delighted to make it. I know exactly how I would do it,

I make some initial tests, for example to parse csv and make it as an xml: http://hutonggames.com/playmakerforum/index.php?topic=891.msg3876#msg3876


Bye,

 Jean

balasco

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: ArrayMaker is now available
« Reply #35 on: May 29, 2012, 08:01:15 AM »
Thanks guys, will look into using jagged arrays for now, are they easy to iterate through using PlayMaker, or do you think I should stick to normal scripting?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: ArrayMaker is now available
« Reply #36 on: May 29, 2012, 10:25:16 AM »
Hi,

 You don't really iterate hashtables, but arrays yes, I made an action few days ago that ease the process ( while it's perfectly doable as is with PlayMaker): http://hutonggames.com/playmakerforum/index.php?topic=835.msg6941#msg6941

 If you do find actions you would like to see implemented for arrayMaker or else, do not hesitate to ask for them.

 Bye,

 Jean

u0204909

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: ArrayMaker is now available
« Reply #37 on: July 31, 2012, 08:45:27 PM »
Hi Jean, thanks for ArrayMaker!

I couldnt get the Array List Copy To action to work, so I checked the code. I noticed you werent using the source element and were copying from destination proxy to destination proxy. So I changed

System.Array _tmp_ = proxy.arrayList.ToArray()
to
System.Array _tmp_ = source.ToArray()

It worked for me but I wanted to let you know and also check if I made a valid/invalid correction.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: ArrayMaker is now available
« Reply #38 on: August 01, 2012, 03:07:39 AM »
Hi,

 Completely forgot to finish that action! :) thanks for spotting this,

 Here's a version attached that will work with the start index and count properties, so that you can copy only part of the array.

bye,

 Jean

amaranth

  • Full Member
  • ***
  • Posts: 172
    • View Profile
Re: ArrayMaker is now available
« Reply #39 on: August 06, 2012, 04:32:47 PM »
Jean, I think I've found a bug. If I import a text file, using Split Text To Array, with integers, I can't get the integers with Array List Get. If I import the same text file with strings, everything works fine.

(or maybe this isn't a bug? perhaps a little help text that indicates only strings can be imported?)

« Last Edit: August 06, 2012, 05:42:12 PM by amaranth »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: ArrayMaker is now available
« Reply #40 on: August 07, 2012, 05:43:27 AM »
Hi,

It's not a bug, it's just that it needs to be explicitly defined.

Here we go, the action is updated to let you parse the items as int or float, default is string. I'll see if I can extend to other types, such as vectors, rect, bool etc.

bye,

 Jean
« Last Edit: August 08, 2012, 03:24:55 AM by jeanfabre »

amaranth

  • Full Member
  • ***
  • Posts: 172
    • View Profile
Re: ArrayMaker is now available
« Reply #41 on: August 07, 2012, 09:41:28 AM »
Woot! Okay, I have one more hypothetical question...

Is it possible to specify a range in SplitTextToArray? For example, a save game file will probably have many different types of values stored inside. I plan to put strings in one chunk, integers in another chunk, etc. So slot 0-100 are reserved for integers, 101-200 are reserved for strings.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: ArrayMaker is now available
« Reply #42 on: August 08, 2012, 03:25:41 AM »
Hi,

 ok, I can see a good use of that, so I updated the action, redownload it from the post above, you are now able to provide a start index and a range.

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: ArrayMaker is now available
« Reply #43 on: August 08, 2012, 05:12:42 AM »
Hi,

 Here's an updated version of ArrayGetNext where you can now define a start and end index so that you can iterate only a portion of an array.

 Bye,

 Jean

amaranth

  • Full Member
  • ***
  • Posts: 172
    • View Profile
Re: ArrayMaker is now available
« Reply #44 on: August 08, 2012, 10:14:41 AM »
Thank you, Jean! :D