Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on June 17, 2011, 06:19:46 AM
-
Hi,
Following a post ( http://hutonggames.com/playmakerforum/index.php?topic=351.0 (http://hutonggames.com/playmakerforum/index.php?topic=351.0) ),
please find a custom action ( really just a mix of the existing ones) that allow you to add to an int from another fsm without too much trouble creating events, states, etc etc. You can also store the result locally if you need it.
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Adds a value to an fsm Integer Variable.")]
public class AddToFsmInt : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.FsmName)]
[Tooltip("Optional name of FSM on Game Object")]
public FsmString fsmName;
[RequiredField]
[UIHint(UIHint.FsmInt)]
public FsmString variableName;
[RequiredField]
public FsmInt add;
[Tooltip("Optional storage of the result")]
[UIHint(UIHint.Variable)]
public FsmInt storeResult;
public bool everyFrame;
GameObject goLastFrame;
PlayMakerFSM fsm;
public override void Reset()
{
gameObject = null;
add = null;
fsmName = "";
storeResult = null;
}
public override void OnEnter()
{
DoAddToFsmInt();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoAddToFsmInt();
}
void DoAddToFsmInt()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
// only get the fsm component if go has changed
if (go != goLastFrame)
{
goLastFrame = go;
fsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);
}
if (fsm == null) return;
FsmInt fsmInt = fsm.FsmVariables.GetFsmInt(variableName.Value);
if (fsmInt == null) return;
fsmInt.Value += add.Value;
if (storeResult != null){
storeResult.Value = fsmInt.Value;
}
}// DoAddToFsmInt
}
}
Bye,
Jean
-
It is very useful and should be on the Ecosystem.
Thanks, Jean!
-
Done :)
Bye,
Jean
-
\o/
Thanks!!!
-
Ok this is way Cooler !!! and sure makes life easy :D
Thank you Jean!