playMaker

Author Topic: Is there a way to get Action Parameters from Action?  (Read 3511 times)

Kingpin

  • Playmaker Newbie
  • *
  • Posts: 5
Is there a way to get Action Parameters from Action?
« on: March 17, 2014, 08:13:32 AM »
Hi,

How I can get Action Paramaters in C#?

For example, at State Inspector I see actions,  like: Play Animation (https://hutonggames.fogbugz.com/default.asp?W152)

But how I can get info about which variables and values is used for this action via my C#-script?

Code: [Select]
   // get objcet from scene
   object[] objects= FindObjectsOfType (typeof(GameObject));
 
   // and I get gameObjects componets
   PlayMakerFSM[] components = objects[0].GetComponets<PlayMakerFSM>();
   
   int count = components[0].FsmStates[0].ActionData.ActionCount;
   if(count>0)
   {
      // I can get name of action like this
     string name = components[0].FsmStates[0].Actions[0].ToString();

     // is enabled
     bool enabled = components[0].FsmStates[0].Actions[0].Enabled;
     
    // etc...

   }



/Kingpin

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Is there a way to get Action Parameters from Action?
« Reply #1 on: March 17, 2014, 11:45:12 PM »
Here's an example:

Code: [Select]
var playAnimationAction = myFsm.States[0].Actions[0] as PlayAnimation;
playAnimationAction .animName = "myAnimName";

Make sure you also add:

Code: [Select]
using HutongGames.PlayMaker.Actions;

Kingpin

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Is there a way to get Action Parameters from Action?
« Reply #2 on: March 19, 2014, 03:07:04 AM »
Thank you for your answer Alex Chouls.

I want to get those variables from ActionData, but this dont work. 

Code: [Select]
FieldInfo[] data = myFsm.States[0].Actions[0].ActionData.GetFields();

I know there is a public static member GetFields at ActionData but I cannot access it.

MonoDeveloper gives me an error: "FieldInfo" could not be found.

But this works:
Code: [Select]
int count = myFsm.States[0].Actions[0].ActionData.ActionCount;
/Kingpin
 

Kingpin

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Is there a way to get Action Parameters from Action?
« Reply #3 on: March 19, 2014, 04:51:58 AM »
ok ... What I found:

I  can get field info like this:
Code: [Select]
FiledInfo [info] = ActionData.GetFileds(myFsm.States[0].Actions[0].GetType());
var name = info[0].ToString();

But still I dont know how I can get filed value?

Code: [Select]

// typedReference ?
TypedReference obj;  // I dont know where to get this ???

var value = info[0].GetValueDirect(obj).ToString();

What is TypedReference?
I dont know where to get this ???

/Kingpin
 

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Is there a way to get Action Parameters from Action?
« Reply #4 on: March 19, 2014, 06:40:12 AM »
ActionData is packed data used to initialize actions in the Actions array (this is a workaround for Unity not supporting polymorphic serialization). ActionData is not designed to be read directly. Why do you want to read from ActionData instead of from Actions?

Kingpin

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Is there a way to get Action Parameters from Action?
« Reply #5 on: March 19, 2014, 06:49:49 AM »
I want to get information from those actions, like names, what variables(and type they) are they using and of course values.

In other words, I want to collect actions parameter info.

thanks for the clarification, Alex Chouls
/Kingpin
« Last Edit: March 19, 2014, 07:01:20 AM by Kingpin »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Is there a way to get Action Parameters from Action?
« Reply #6 on: March 19, 2014, 08:57:52 AM »
You can access the actions in the Actions array. E.g, use GetType() to get the action type. You have to cast the action to the specific type to access its parameters (see the first example I posted).

Kingpin

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Is there a way to get Action Parameters from Action?
« Reply #7 on: March 20, 2014, 06:19:45 PM »
thanks, Alex Chouls

Now I can get those fileds as you told me before.

Is there a way to get information from UIHint.variable (Dropdown menu) like which variable is there, name of variable and its type?

For example: StringCompare action have :
Code: [Select]
[UIHint(UIHint.Variable)
public FsmString stringVariable;
//etc..


So I want to know is there any variable selected or is that dropdown empy at my c# script. I dont know how to get that information.

/kingpin