public override void Evaluate(double CurrentTime) { base.Evaluate(CurrentTime); FCommand = TLAutomataCommand.NoChange; if (FCurrentState != null) { TLStateKeyFrame lastState = FCurrentState; TLStateKeyFrame tmpState = (FKeyFrames.Find(delegate(TLBaseKeyFrame s) { return(s.Time > CurrentTime); }) as TLStateKeyFrame); if (tmpState.Time > lastState.Time) //lastState is over, so execute action of lastState { SetCurrentStateAndCommand(lastState.Events[0], lastState, lastState.Time); } //else { //go through all events of FCurrentState and see if their inputs are ON double on = 0; foreach (TLEvent e in FCurrentState.Events) { if (e.EventPin != null) { e.EventPin.GetValue(0, out on); if (on > 0.5) { SetCurrentStateAndCommand(e, lastState, CurrentTime); break; } } } } OutputAsString = FCurrentState.Name; } }
private void SetCurrentStateAndCommand(TLEvent Event, TLStateKeyFrame LastState, double CurrentTime) { switch (Event.Action.Command) { case TLActionCommand.next: { FCurrentState = (FKeyFrames.Find(delegate(TLBaseKeyFrame s) { return(s.Time > LastState.Time); }) as TLStateKeyFrame); FCommand = TLAutomataCommand.Jump; break; } case TLActionCommand.previous: { FCurrentState = (FKeyFrames.FindLast(delegate(TLBaseKeyFrame s) { return(s.Time < LastState.Time); }) as TLStateKeyFrame); FCommand = TLAutomataCommand.Jump; break; } case TLActionCommand.loop: { FCurrentState = LastState; FCommand = TLAutomataCommand.Jump; break; } case TLActionCommand.play: { FCurrentState = (FKeyFrames.Find(delegate(TLBaseKeyFrame s) { return(s.Time > CurrentTime); }) as TLStateKeyFrame); FCommand = TLAutomataCommand.Play; break; } case TLActionCommand.pause: { FCurrentState = LastState; FPauseTime = CurrentTime; FCommand = TLAutomataCommand.Pause; break; } case TLActionCommand.jump: { FCurrentState = (TLStateKeyFrame)FKeyFrames.Find(delegate(TLBaseKeyFrame k) { return((k as TLStateKeyFrame).Name == Event.GotoState); }); if (FCurrentState == null) { FCurrentState = LastState; FCommand = TLAutomataCommand.Pause; } else { FCommand = TLAutomataCommand.Jump; } break; } } }