playMaker

Author Topic: Send list of PlayMaker Variables to Action?[SOLVED]  (Read 6905 times)

Krileon

  • Full Member
  • ***
  • Posts: 107
Send list of PlayMaker Variables to Action?[SOLVED]
« on: April 08, 2013, 04:56:43 PM »
Is it possible to build and send a list of PlayMaker Variables in the same way the LayerMask works? Basically it gives you an integer field and you supply a digit of how many layers you want. You then select the layers from the dropdown as needed. It then sends that to PlayMaker as a list. Can you do this with other variables such as booleans, strings, etc..?

My PlayMaker action for CoherentUI lets me send variables to it, but so far I have 5 string variables, 5 boolean variables, and 5 integer variables. As you can image this makes the action quite large and would be great if I could dynamically build lists of variables to send to it.
« Last Edit: April 15, 2013, 01:06:12 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send list of PlayMaker Variables to Action?
« Reply #1 on: April 09, 2013, 01:44:01 AM »
Hi,

 have you looked at ArrayMaker? that would be a good start for what you want to do I guess.

https://hutonggames.fogbugz.com/default.asp?W715

bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Send list of PlayMaker Variables to Action?
« Reply #2 on: April 09, 2013, 09:54:37 AM »
Is there no way to do this in the same way LayerMask does? I don't want a proxy component. This should work internally in the same way LayerMask works. I wish PlayMaker could be extended with custom FSM types properly so these proxies aren't needed.
« Last Edit: April 09, 2013, 09:56:56 AM by Krileon »

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Send list of PlayMaker Variables to Action?
« Reply #3 on: April 10, 2013, 06:45:48 PM »
Anyone have any idea? Is this planned to be added? Already implemented? Would be very helpful in reducing the number of variables I have to provide for my custom action.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send list of PlayMaker Variables to Action?
« Reply #4 on: April 11, 2013, 01:31:58 AM »
Hi,

 I don't think it's planned. You can use custom class now in actions, have you tried that?

Could you give us a use case of how you would like this to work? maybe there is indeed a possible way out of your current worflow.

bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Send list of PlayMaker Variables to Action?
« Reply #5 on: April 11, 2013, 01:23:16 PM »
Quote
You can use custom class now in actions, have you tried that?
Custom class how? For what? What do they do? Can I have custom FSM variable types now? I don't understand. I mean no offense but the API documentation is terrible so I have to use existing Actions as examples, which is very limited as none of them are advanced usages. All the API References are "TODO".

I want it to work exactly like LayerMask except I don't want the list being a list of LayerMasks and instead be a list of booleans, strings, integers, or whatever else I want. The way it works with LayerMasks is you have an integer field where you supply the number of layers you want, say 4, and it then displays variables below it based off that number, again 4, and you select a layer for each one. I want basically the same thing except to work with FSM variables so I can send a List of variables to a Action of an undefined amount.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send list of PlayMaker Variables to Action?
« Reply #6 on: April 12, 2013, 02:47:34 AM »
Hi,

 Yes, I agree with you, the api doc need some love. I never tested that functionnality, so I tried, and it works amazingly!!!

ok, custom class is now something that custom action understands, so if you create your own class with public variables, and use that class as a public property of a custom action, then it will understand and display the various public fields declared on that custom class.

which means you can have built in lists :)


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

public class TestClass {

public bool oneBool;
public bool[] manyBools;
}


you can use this class as a pubic property in a custom action:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

public class CustomClassTest : FsmStateAction
{

public TestClass test;

}
}

and voila! you can have now your completly flexible amount of bool within a confined space of a custom action public property.

Does that make more sense? I guess this is exactly what you are looking for actually!
Else could you define your need better? maybe with a pseudo code of how you would like it to perform?


Now, I also tried to inject actual action Hints so that for example you can reference a Fsm variables within your custom class, and that works!!! this is amazing!

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

using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;

public class TestClass : FsmStateAction {


public bool oneBool;

public bool[] manyBools;

[UIHint(UIHint.Variable)]
public FsmString hello;

}

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

public class CustomClassTest : FsmStateAction
{

public TestClass test;

public override void OnEnter()
{
Debug.Log(test.hello.Value);
}


}
}


 Bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Send list of PlayMaker Variables to Action?
« Reply #7 on: April 12, 2013, 08:22:32 AM »
I see, I'm not looking for custom classes as I'm not trying to interact with PlayMaker from outside of PlayMaker. I'm making a Custom Action that allows me from within a PlayMaker State to send List of variables to that Action. The best I can describe how I want it to work is exactly like LayerMask (see Raycast Action for example) except I don't want to send a LayerMask List, but instead a list of Booleans, etc..

However, if I can supply public bool[] manyBools; in my Custom Action and PlayMaker then lets me supply FSM Booleans to it that'd work too, but if I can't pass FSM Booleans to it then does me no good.

Basically I'd like to use public FsmBool[] boolVariables; and be able to supply a list of Boolean FSM values to it in PlayMaker that is sent to my custom action. I know I can do stuff like int[], bool[], string[], etc.. but that doesn't let me supply FSM Variables to it and is just traditional Unity script variable handling.

Is it possible to easily extend PlayMaker with new FsmVariable types in the same way it's easily extended with custom actions? This would probably solve my issues entirely as I could create a new FsmBool[] type that handles lists of FsmBool.

Custom FsmVariables seams possible as from what I can see in the assembly for FsmVariables they're pretty easy to write, but would PlayMaker pick them up? Can I have the source for at least 1 of these so I can try making a new Variable? This would be exponentially easier if we could at least see source (DLLs are nice to avoid conflicts, but horrible for API usage review).
« Last Edit: April 12, 2013, 08:43:29 AM by Krileon »

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Send list of PlayMaker Variables to Action?
« Reply #8 on: April 13, 2013, 05:11:34 PM »
Anyone have any ideas? Is there no way to write custom FSM Variables? For example:

public class FsmBoolList : FsmBool {

public FsmBoolList boolList;

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Send list of PlayMaker Variables to Action?
« Reply #9 on: April 13, 2013, 06:59:39 PM »
Ok, it looks like you can do FsmBool[] and FsmInt[], but it throws the below to the console. Any ideas how to clear the error?

Code: [Select]
ArgumentException: GUILayout: Mismatched LayoutGroup.Ignore
UnityEngine.GUILayoutUtility.BeginLayoutGroup (UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options, System.Type LayoutType) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/GUILayoutUtility.cs:208)
UnityEditor.EditorGUILayout.BeginHorizontal (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/MonoGenerated/Editor/EditorGUI.cs:4682)
UnityEditor.EditorGUILayout.BeginHorizontal (UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/MonoGenerated/Editor/EditorGUI.cs:4678)
HutongGames.PlayMakerEditor.VariableEditor.FsmBoolField (UnityEngine.GUIContent label, HutongGames.PlayMaker.Fsm fsm, HutongGames.PlayMaker.FsmBool fsmBool)
HutongGames.PlayMakerEditor.ActionEditor.EditFsmBool (UnityEngine.GUIContent label, System.Object fieldValue, System.Object[] attributes)
HutongGames.PlayMakerEditor.ActionEditor.GUIForFieldTypes (System.String labelText, System.Type type, System.Object fieldValue, System.Object[] attributes)
HutongGames.PlayMakerEditor.ActionEditor.EditArray (UnityEngine.GUIContent label, System.Type elementType, System.Object fieldValue, System.Object[] attributes)
HutongGames.PlayMakerEditor.ActionEditor.GUIForFieldTypes (System.String labelText, System.Type type, System.Object fieldValue, System.Object[] attributes)
HutongGames.PlayMakerEditor.ActionEditor.EditField (System.Object obj, System.Reflection.FieldInfo field, System.String labelText, System.Type fieldType, System.Object fieldValue, System.Object[] attributes)
HutongGames.PlayMakerEditor.ActionEditor.OnGUI (HutongGames.PlayMaker.FsmStateAction action, Boolean debugVariables, Boolean isPreview)
HutongGames.PlayMakerEditor.StateInspector.DoActionGUI (HutongGames.PlayMaker.FsmStateAction action)
HutongGames.PlayMakerEditor.StateInspector.DoActionsListGUI (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMakerEditor.StateInspector.DoActionsPanel ()
HutongGames.PlayMakerEditor.StateInspector.OnGUI ()
HutongGames.PlayMakerEditor.InspectorPanel.OnGUI (Rect area)
HutongGames.PlayMakerEditor.FsmEditor.OnGUI ()
FsmEditorWindow.OnGUI () (at Assets/PlayMaker/Editor/FsmEditorWindow.cs:93)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

Note this only happens when changing the number of variables from 0 to 1 or something of the sort. Still testing to see if this actually works in my custom action.. if it does then this is perfect for what I need.
« Last Edit: April 13, 2013, 07:09:07 PM by Krileon »

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Send list of PlayMaker Variables to Action?
« Reply #10 on: April 13, 2013, 07:28:36 PM »
Awesome, the above works perfectly. Below is an example of how to use array FSM Variables.

Code: [Select]
using System.Collections.Generic;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory("Variable List")]
public class VariableListSample : FsmStateAction {
public FsmInt[] intVariables;
public FsmBool[] boolVariables;
public FsmString[] stringVariables;
public bool everyFrame;

public override void Reset() {
intVariables = new FsmInt[0];
boolVariables = new FsmBool[0];
stringVariables = new FsmString[0];
everyFrame = false;
}

public override void OnEnter() {
DoAction();

if ( ! everyFrame ) {
Finish();
}
}

public override void OnUpdate() {
DoAction();
}

void DoAction() {
List<object> options = new List<object>();

if ( intVariables.Length > 0 ) foreach ( FsmInt intVariable in intVariables ) {
if ( ! intVariable.IsNone ) {
options.Add( intVariable.Value );
}
}

if ( boolVariables.Length > 0 ) foreach ( FsmBool boolVariable in boolVariables ) {
if ( ! boolVariable.IsNone ) {
options.Add( boolVariable.Value );
}
}

if ( stringVariables.Length > 0 ) foreach ( FsmString stringVariable in stringVariables ) {
if ( ! stringVariable.IsNone ) {
options.Add( stringVariable.Value );
}
}
}
}
}

Hope this helps others as is completely awesome if you want an infinite list of FSM Variables to be able to be sent to your custom action.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send list of PlayMaker Variables to Action?
« Reply #11 on: April 15, 2013, 01:05:53 AM »
Hi,

 ok, I guess I did not understand your initial questions. it's indeed a feature used in many official actions like FormatString, SelectRandomString etc.

 one more thing you should be aware at this point, action interface have a special way to combine several lists together, study PlayRandomAnimation action and the "compoundArray" set up.

bye,

 Jean