public override bool IsConditionMet(StateMachineComponent stateMachine) { ITimelineStateTimer timer = TimelineState.GetTimer(stateMachine.gameObject); _time -= timer.GetDeltaTime(); return(_time <= 0.0f); }
public override IEnumerator PerformState(StateMachineComponent stateMachine) { if (_timeline != null && _timeline._events.Length > 0) { ITimelineStateTimer timer = GetTimer(stateMachine.gameObject); float currentTime = 0.0f; List <Event> nonInstantEvents = new List <Event>(); int eventIndex = 0; Event currentEvent = _timeline._events[eventIndex]; while (currentEvent != null || nonInstantEvents.Count > 0) { ITimelineStateEvent currentStateMachineEvent = currentEvent as ITimelineStateEvent; if (currentStateMachineEvent == null && currentEvent != null) { throw new Exception("Event doesn't implement ITimelineStateEvent"); } float nextEventTime = currentEvent != null ? _timeline._events[eventIndex].GetTime() : 0.0f; //Wait until event time while (currentTime < nextEventTime || (currentEvent == null && nonInstantEvents.Count > 0)) { currentTime += timer.GetDeltaTime(); #if DEBUG StateMachineDebug.OnTimelineStateTimeProgress(stateMachine, this, currentTime); #endif //Updated non instant events, if any now wants to exit the state then break out of coroutine if (UpdateNonInstantEvents(stateMachine, ref nonInstantEvents, currentTime)) { EndNonInstantEvents(stateMachine, ref nonInstantEvents); yield break; } yield return(null); } if (currentEvent == null) { break; } //Trigger event eEventTriggerReturn status = currentStateMachineEvent.Trigger(stateMachine); switch (status) { case eEventTriggerReturn.EventFinished: //Do nothing, just move on to next event break; case eEventTriggerReturn.EventFinishedExitState: //Exit state so break out of coroutine EndNonInstantEvents(stateMachine, ref nonInstantEvents); yield break; case eEventTriggerReturn.EventOngoing: //Track timed event, move on to next event nonInstantEvents.Add(currentEvent); break; } //Get next currentEvent = ++eventIndex < _timeline._events.Length ? _timeline._events[eventIndex] : null; } } #if DEBUG StateMachineDebug.OnTimelineStateStoped(stateMachine); #endif stateMachine.GoToState(StateMachine.Run(stateMachine, _goToState)); yield break; }