playMaker

Author Topic: How to get a static variable?[SOLVED]  (Read 3207 times)

alexlange

  • Playmaker Newbie
  • *
  • Posts: 16
How to get a static variable?[SOLVED]
« on: June 04, 2015, 09:20:10 PM »
Hi, How to get static var in playmaker? GetProperty function seems can't get static vars.
Code: [Select]
public static class MyGlobal{
public static string MyString;
}
« Last Edit: June 05, 2015, 05:47:30 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to get a static variable?
« Reply #1 on: June 05, 2015, 01:13:16 AM »
Hi,

 Indeed, it can't. The only solution right now is to create a Custom Action.

It's very easy, and you can simply copy paste an existing one like for example:

Code: [Select]
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Application)]
[Tooltip("Get the current resolution")]
public class GetCurrentResolution : FsmStateAction
{
[Tooltip("The current resolution width")]
[UIHint(UIHint.Variable)]
public FsmFloat width;

[Tooltip("The current resolution height")]
[UIHint(UIHint.Variable)]
public FsmFloat height;

[Tooltip("The current resolution refrehs rate")]
[UIHint(UIHint.Variable)]
public FsmFloat refreshRate;

[Tooltip("The current resolution ( width, height, refreshRate )")]
[UIHint(UIHint.Variable)]
public FsmVector3 currentResolution;

public override void Reset()
{
width = null;
height = null;
refreshRate = null;
currentResolution = null;
}

public override void OnEnter()
{

width.Value = Screen.currentResolution.width;
height.Value = Screen.currentResolution.height;
refreshRate.Value = Screen.currentResolution.refreshRate;

currentResolution.Value = new Vector3(Screen.currentResolution.width,Screen.currentResolution.height,Screen.currentResolution.refreshRate);

Finish();
}


}
}

which would be in your case something like:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("")]
[Tooltip("")]
public class GetMyGlobalMyString : FsmStateAction
{
[Tooltip("")]
[UIHint(UIHint.Variable)]
public FsmString myString;


public override void Reset()
{
myString = null;
}

public override void OnEnter()
{

myString.Value = MyGlobal.MyString;
Finish();
}


}
}

Bye,

 Jean

alexlange

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to get a static variable?
« Reply #2 on: June 05, 2015, 03:48:51 AM »
Thank you :)

Hi,

 Indeed, it can't. The only solution right now is to create a Custom Action.

It's very easy, and you can simply copy paste an existing one like for example:

Code: [Select]
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Application)]
[Tooltip("Get the current resolution")]
public class GetCurrentResolution : FsmStateAction
{
[Tooltip("The current resolution width")]
[UIHint(UIHint.Variable)]
public FsmFloat width;

[Tooltip("The current resolution height")]
[UIHint(UIHint.Variable)]
public FsmFloat height;

[Tooltip("The current resolution refrehs rate")]
[UIHint(UIHint.Variable)]
public FsmFloat refreshRate;

[Tooltip("The current resolution ( width, height, refreshRate )")]
[UIHint(UIHint.Variable)]
public FsmVector3 currentResolution;

public override void Reset()
{
width = null;
height = null;
refreshRate = null;
currentResolution = null;
}

public override void OnEnter()
{

width.Value = Screen.currentResolution.width;
height.Value = Screen.currentResolution.height;
refreshRate.Value = Screen.currentResolution.refreshRate;

currentResolution.Value = new Vector3(Screen.currentResolution.width,Screen.currentResolution.height,Screen.currentResolution.refreshRate);

Finish();
}


}
}

which would be in your case something like:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("")]
[Tooltip("")]
public class GetMyGlobalMyString : FsmStateAction
{
[Tooltip("")]
[UIHint(UIHint.Variable)]
public FsmString myString;


public override void Reset()
{
myString = null;
}

public override void OnEnter()
{

myString.Value = MyGlobal.MyString;
Finish();
}


}
}

Bye,

 Jean