public void Update() { Debug.Assert(_MasterCondition != null); Debug.Assert(_SlaveSubroutine != null); switch (_CurrentState) { case WhileNodeState.Running: { if (!_MasterCondition()) { // Condition is false now, reset the slave (interrupt it) _SlaveSubroutine.Reset(); _CurrentState = WhileNodeState.Complete; } else { // Master is not finished, continue updating the slave, if applicable // Note that this doesn't automatically reset the slave! _SlaveSubroutine.Update(); } } break; case WhileNodeState.Complete: // Nothing to do break; case WhileNodeState.Disposed: throw new System.Exception("MasterSlave node is disposed and should not be updated"); } }
public While(ICoroutine slaveNode, System.Func <bool> masterCondition) { // Create our slave subroutine _SlaveSubroutine = slaveNode; // Store the condition function _MasterCondition = masterCondition; // We start running _CurrentState = WhileNodeState.Running; }
public void Dispose() { // Clean up _MasterCondition = null; if (_SlaveSubroutine != null) { _SlaveSubroutine.Dispose(); _SlaveSubroutine = null; } _CurrentState = WhileNodeState.Disposed; }
public void Reset() { _SlaveSubroutine.Reset(); _CurrentState = WhileNodeState.Running; }