Hi,
A very simple addition to BoolAllTrue :
https://hutonggames.fogbugz.com/default.asp?W469 so that I can dispatch a event when the test fails, not just when the test passes. Avoids storing and checking, builds cleaner fsm. Also, I build a lot if states acting as "IF" statements with a "YES" and "NO" set of transitions ( or "TRUE" and "FALSE", whatever ). So this addition allows me to keep consistency in my fsms.
This can be easily applied to similar actions.
Here is the code ( also attached as a file as well for convenience).
Comments and feedback welcomed as always.
Bye,
Jean
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Tests if all the given Bool Variables are True. Ability to send event if test fails")]
public class BoolAllTrueTest : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmBool[] boolVariables;
public FsmEvent sendPassEvent;
public FsmEvent sendFailEvent;
[UIHint(UIHint.Variable)]
public FsmBool storeResult;
public bool everyFrame;
public override void Reset()
{
boolVariables = null;
sendPassEvent = null;
sendFailEvent = null;
storeResult = null;
everyFrame = false;
}
public override void OnEnter()
{
DoAllTrue();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoAllTrue();
}
void DoAllTrue()
{
if (boolVariables.Length == 0) return;
bool allTrue = true;
for (int i = 0; i < boolVariables.Length; i++)
{
if (!boolVariables[i].Value)
{
allTrue = false;
break;
}
}
if (allTrue){
Fsm.Event(sendPassEvent);
}else{
Fsm.Event(sendFailEvent);
}
storeResult.Value = allTrue;
}
}
}