playMaker

Author Topic: Array maker via script[SOLVED]  (Read 9349 times)

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Array maker via script[SOLVED]
« on: November 05, 2013, 08:20:44 AM »
I'm trying to access an Array, created with Array maker, via a script. I have connected to playmaker via script before, but wondering if the same thing is done for Array maker? I cannot find any documentation on this. I am creating a texture atlas at runtime and would like to use the textures from an array. The script I have though creates new arrays and I want to use my array maker ones instead. Any suggestions, seems it will be pretty simple if you can program :-)

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;

public class Atlas : MonoBehaviour {
    public Texture2D[] LogoDecals;
    public Rect[] rects;
    void Start() {
        Texture2D atlas = new Texture2D(8192, 8192);
        rects = atlas.PackTextures(LogoDecals, 2, 8192);
    }
}

Thanks
« Last Edit: July 15, 2015, 11:02:24 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array maker via script
« Reply #1 on: November 05, 2013, 08:38:44 AM »
Hi,

 ArrayMaker use monobehaviors, so they are accessed and used just like any other components, the arrayList and Hashtable are public variables, so it's all available for you. Simply open the scripts PlayMakerArrayListProxy.cs and PlayMakerHashTableProxy.cs

you'll need to use the variable _arrayList or _hashtable, they are the collections variables.

bye,

 Jean


adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Array maker via script
« Reply #2 on: November 05, 2013, 08:39:42 AM »
Thanks Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Array maker via script
« Reply #3 on: November 05, 2013, 02:50:34 PM »
Just had a chance to look at this and I am not sure what you mean to be honest. On the script I posted, there are two arrays being created, which I obviously don't need as I have already created them with Arraymaker. I just need to reference them and tell the atlas to build from the texture array and put the rect results in that array. I have played around with a few things to try and work out what you mean but I am still at a loss about it.

As soon as a script becomes involved, things go down the drain for me lol  :-[

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array maker via script
« Reply #4 on: November 06, 2013, 12:39:58 AM »
Hi,

 Yep, you need what I mentionned, cut down the problem:

-- Can you reference a component in a public variable? for example:

Code: [Select]

public PlayMakerArrayListProxy myArray;

Do that and see what it exposes on Unity Inspector, and simply drag the arrayList you have done with ArrayMaker there, it will accept it.

Then further down your logic, you can do:

Code: [Select]

myArray.ArrayList.xxx(), and access each component you have added to this array

Does that make more sense?

Bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Array maker via script
« Reply #5 on: December 05, 2013, 06:44:44 AM »
Taken me a while to get back on to this. Sorry but that doesn't make much sense still. You mentioned using _arrayList, but that isn't in the example you provided. I have opened up the .cs files you mentioned, but again looking at your example and the information I can see in there, I cant work out what needs to be put together.

Code: [Select]
myArray.ArrayList.xxx(), and access each component you have added to this array
This line is confusing me, I don't understand how that should be used in what I need to do, or what the xxx would actually be replaced with. This is what I have if I insert the example, but without knowing what the xxx should be, or if I am using the right arguments, I am still a little stuck.

Code: [Select]
public class Example : MonoBehaviour {
   
public PlayMakerArrayListProxy texArray;
public PlayMakerArrayListProxy rectArray;

void createAtlas ()
{
var atlas = new Texture2D(2048, 2048);
rectArray.ArrayList.xxx() = atlas.PackTextures(texArray.ArrayList.xxx(), 2, 2048);

Thanks Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array maker via script
« Reply #6 on: December 09, 2013, 03:00:51 PM »
Hi,

 Simply study the bunch of arrayList actions, they will show you the full range of what xxx() can be. it's basically what you want to do with the array, add, remove, delete, insert, sort, etc etc.

http://www.dotnetperls.com/arraylist

http://msdn.microsoft.com/en-us/library/system.collections.arraylist(v=vs.110).aspx

bye,

 Jean

psypol

  • Playmaker Newbie
  • *
  • Posts: 39
Re: Array maker via script
« Reply #7 on: July 07, 2015, 02:45:04 PM »
Hello

i'm reading what you wrote here and the documentation ..
but i cant manage to make the simpliest thing possible :
read the value of a ArrayMaker cell in a cs script

by the examples i conclude that there is no such thing as
_arrayList.Get() so i was trying to do this :

Code: [Select]
public PlayMakerArrayListProxy ArrayName;
value = this.ArrayName[0]

i get an error in unity saying :
Quote
Cannot apply indexing with [] to an expression of type `PlayMakerArrayListProxy'

So how exactely do you read a value from ArrayMaker and assign it to a variable in a Cs script ?

thanks for your help

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array maker via script
« Reply #8 on: July 08, 2015, 07:56:41 AM »
Hi,

 The arrayProxy is not the array itself, it's a class that has a public property that is the array. so in your case, it's like this:

Code: [Select]
value = ArrayName.ArrayList[0]

Bye,

 Jean

psypol

  • Playmaker Newbie
  • *
  • Posts: 39
Re: Array maker via script
« Reply #9 on: July 14, 2015, 03:21:52 PM »
thanks a lot for your help. it worked.
the exact syntax is ArrayName.arrayList[0] (so no Caps on a of array list)

for people with same problem here is an additional info =>
if you are loading to an array of strings this is the right way :
Code: [Select]
ValueFromProxyArray = this.Arrayname.arrayList[row].ToString();
Cheers
« Last Edit: July 15, 2015, 04:56:02 AM by psypol »

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Array maker via script[SOLVED]
« Reply #10 on: October 14, 2015, 09:59:32 AM »
Hello.

I follow the discussion and I understand better how to access an Playmaker array list.
My script component is searching for a gameobject with a tag, and everything fine. But I'm wondering how to find an array by name on this gameobject, basically with a string value for the name of the array.

Can you help me please?
« Last Edit: October 14, 2015, 10:09:56 AM by Sly »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array maker via script[SOLVED]
« Reply #11 on: October 15, 2015, 08:26:44 AM »
Hi,

 you just use GetComponents<>() and iterate through them until you find a match reference. this is how it's done internaly.

 Bye,

 Jean

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Array maker via script[SOLVED]
« Reply #12 on: October 15, 2015, 08:51:50 AM »
Hello Jean,

Yes I'm using get component, but I don't succeed to find an arraylist by a name (as string).
I'm using this:
var ArrayName = StoreGO.GetComponent<PlayMakerArrayListProxy>()

What I'm supposed to add to my line for this?

For example, I'm look for PlayMakerArrayListProxy with reference name "WaterSprite" (this name is contain into the string variable RefName)
« Last Edit: October 15, 2015, 09:14:25 AM by Sly »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array maker via script[SOLVED]
« Reply #13 on: October 15, 2015, 09:40:05 AM »
Hi,

 I have pasted below the code I am using to find an arrayProxy on a GameObject by reference:

it's in script CollectionsActions, method GetArrayListProxyPointer()

and it's used in all array actions basically. the same exists for hashtables.

Code: [Select]

PlayMakerArrayListProxy[] proxies = aProxy.GetComponents<PlayMakerArrayListProxy>();
if (proxies.Length>1){

if (nameReference == ""){
if (!silent) Debug.LogError("Several ArrayList Proxies coexists on the same GameObject and no reference is given to find the expected ArrayList");
}

foreach (PlayMakerArrayListProxy iProxy in proxies) {
        if (iProxy.referenceName == nameReference){
return iProxy;
}
    }

if (nameReference != ""){
if (!silent) LogError("ArrayList Proxy not found for reference <"+nameReference+">");
return null;
}

}else if (proxies.Length>0){
if (nameReference!="" && nameReference != proxies[0].referenceName){
if (!silent) Debug.LogError("ArrayList Proxy reference do not match");
return null;
}

return proxies[0];



this is basically what you need to do. you can skip the checks and logs, but the basic algorythm is here.

Bye,

 Jean

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Array maker via script[SOLVED]
« Reply #14 on: October 19, 2015, 04:20:36 PM »
It work perfectly. There is my code: (it's trying to find a game object withtag, and take a random item into an Playmaker array list

Code: [Select]
using UnityEngine;
using System.Collections;
//using PlayMaker;

public class ArrayListGetRandom : MonoBehaviour {

public string GameObjectName;
public string withTag;
public string reference; //Name of the array List
public object result;

PlayMakerArrayListProxy ArrayListName;

GameObject StoreGO;
PlayMakerArrayListProxy proxy;
string proxyRefName;

void Reset()
{
GameObjectName = null;
reference = null;
withTag = null;
}

// Use this for initialization
void Start () {
FindGameObject ();
FindArrayList();
GetRandomItem();
}

void FindGameObject () {
if (withTag != "Untagged")
{
if (!string.IsNullOrEmpty(GameObjectName))
{
var possibleGameObjects = GameObject.FindGameObjectsWithTag(withTag);

foreach (var go in possibleGameObjects)
{
if (go.name == GameObjectName)
{
StoreGO = go;
return;
}
}

StoreGO = null;
return;
}

StoreGO = GameObject.FindGameObjectWithTag(withTag);
return;
}

StoreGO = GameObject.Find(GameObjectName);
}

void FindArrayList ()
{

PlayMakerArrayListProxy[] proxies = StoreGO.GetComponents<PlayMakerArrayListProxy>();

if (proxies.Length>1){

if (reference == ""){
Debug.LogError("Several ArrayList Proxies coexists on the same GameObject and no reference is given to find the expected ArrayList");
}

foreach (PlayMakerArrayListProxy iProxy in proxies) {
if (iProxy.referenceName == reference){
//Succeed to have it!
proxy = iProxy;
proxyRefName = iProxy.referenceName;
return;
}
}
if (reference != ""){
Debug.LogError("ArrayList Proxy not found for reference <"+reference+">");
//Array not found with name
return;
}
}else if (proxies.Length>0){
if (reference!="" && reference != proxies[0].referenceName){
Debug.LogError("ArrayList Proxy reference do not match");
return;
}
//iProxy = ;
proxy = StoreGO.GetComponent<PlayMakerArrayListProxy>();
//It's the correct one!

return;
}
}

public void GetRandomItem()
{

int index = Random.Range(0,proxy.arrayList.Count);// IS THIS TRUE? if I do count-1 I never get the last item picked...


object element = null;

try{

element = proxy.arrayList[index];
}catch(System.Exception e){
Debug.LogWarning(e.Message);
return;
}

if (element != null)
{
result = element;
}
else if (element == null)
{
Debug.LogError("Nothing return from ArrayList random Object! Please check if your arrayList as entry!");
}
}


}

Merci Jean, c'est très apprécié!