Hi Everyone,
Posting this as it really speed up my development and saves me duplicating variables all over.
Yes, it's intended to be used only once, no every frame as it will less effective than checking its own local variable in terms of speed, but for some organization, it makes perfect sense. When for example there is a fsm responsible for storing variables for a given process, while other fsm can check against them when needed. Or simply when you can't be bother spending the extra time of creating a duplicate variable, and making the actions to retrieve it, store it and finally check for it.
For convenience, I have created an Unity package, that can be downloaded here:
http://dl.dropbox.com/u/17356625/Unity/playmaker/actions/FsmBoolTest.unitypackage1: have your unity project opened
2: in the menu, select Assets->Import Package->Custom Package
3: locate and select FsmBoolTest.unitypackage on your computer
4: Click Open
5: there is one file, make sure it's selected and import
6: done, you can now access this new action in the "Logic" Action category
Hope you find it useful,
Bye,
Jean
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// Modified by Jean Fabre : contact@fabrejean.net
// this is a combination of BoolTest and GetFsmBool since I don't want the extras steps required otherwise.
// I also don't feel like saving a variable for every single check from other fsm, I want to avoid redundance sometimes.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends Events based on the value of a Bool Variable from another FSM.")]
public class FsmBoolTest : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.FsmName)]
[Tooltip("Optional name of FSM on Game Object")]
public FsmString fsmName;
[RequiredField]
[UIHint(UIHint.FsmBool)]
public FsmString variableName;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmEvent isTrue;
public FsmEvent isFalse;
public bool everyFrame;
private bool storedValue;
GameObject goLastFrame;
PlayMakerFSM fsm;
public override void Reset()
{
gameObject = null;
fsmName = "";
storedValue = false;
isTrue = null;
isFalse = null;
}
public override void OnEnter()
{
DoGetFsmBool();
Fsm.Event(storedValue ? isTrue : isFalse);
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoGetFsmBool();
Fsm.Event(storedValue ? isTrue : isFalse);
}
void DoGetFsmBool()
{
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;
FsmBool fsmBool = fsm.FsmVariables.GetFsmBool(variableName.Value);
if (fsmBool == null) return;
storedValue = fsmBool.Value;
}
}
}