Hi,
Following a request, please find IntBetween action that check that an int is between two values. There is an option to check for inclusive limits or not, it sends events, store the result in a boll and work everyframe if you want. So that should cover all situations.
[EDIT] modified to allow for reordering limits if min>max
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Check if an int is between two values, ou can define limits as inclusive. Send Events and store results")]
public class IntBetween : FsmStateAction
{
[RequiredField]
public FsmInt integer;
[RequiredField]
public FsmInt integerMin;
[RequiredField]
public FsmInt integerMax;
[Tooltip("IF true, will pass test if integer is equal to the limits")]
public FsmBool inclusive;
[Tooltip("IF true, will reorder min and max ( if for example max is less then min, it will adjust). If False it will enforce the right limits declaration as per labels.")]
public FsmBool autoOrderLimits;
[Tooltip("Event sent if integer is between integerMin and integerMax")]
public FsmEvent isBetweenEvent;
[Tooltip("Event sent if Int 1 is less than Int 2")]
public FsmEvent isNotBetweenEvent;
[UIHint(UIHint.Variable)]
public FsmBool isInBetween;
public bool everyFrame;
public override void Reset()
{
integer = null;
integerMin = null;
integerMax = null;
inclusive = true;
autoOrderLimits = true;
isBetweenEvent = null;
isNotBetweenEvent = null;
isInBetween = null;
everyFrame = false;
}
public override void OnEnter()
{
DoIntBetween();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoIntBetween();
}
void DoIntBetween()
{
int min = integerMin.Value;
int max = integerMax.Value;
if (autoOrderLimits.Value && min > max)
{
min = integerMax.Value;
max = integerMin.Value;
}
if (integer.Value < min || integer.Value > max)
{
Fsm.Event(isNotBetweenEvent);
isInBetween.Value = false;
return;
}
if (inclusive.Value)
{
if (integer.Value >= min && integer.Value <= max)
{
Fsm.Event(isBetweenEvent);
isInBetween.Value = true;
return;
}
}else
{
if (integer.Value > min && integer.Value < max)
{
Fsm.Event(isBetweenEvent);
isInBetween.Value = true;
return;
}
}
Fsm.Event(isNotBetweenEvent);
isInBetween.Value = false;
}
}
}
Bye,
Jean