public eEventTriggerReturn Update(StateMachineComponent stateMachine, float eventTime)
            {
                if (_playableDirector.playableGraph.IsValid() && !_playableDirector.playableGraph.IsDone())
                {
                    return(eEventTriggerReturn.EventOngoing);
                }

                stateMachine.GoToState(StateMachine.Run(stateMachine, _goToState));

                return(eEventTriggerReturn.EventFinishedExitState);
            }
Example #2
0
            public override IEnumerator PerformState(StateMachineComponent stateMachine)
            {
                if (_branches != null)
                {
                    foreach (ConditionalStateBranch branch in _branches)
                    {
                        branch.OnBranchingStarted(stateMachine);
                    }

                    foreach (ConditionalStateBackgroundLogic branch in _backgroundLogic)
                    {
                        branch.OnLogicStarted(stateMachine);
                    }

                    bool branchTaken = false;

                    while (!branchTaken)
                    {
                        foreach (ConditionalStateBackgroundLogic branch in _backgroundLogic)
                        {
                            branch.UpdateLogic(stateMachine);
                        }

                        foreach (ConditionalStateBranch branch in _branches)
                        {
                            if (branch.ShouldBranch(stateMachine))
                            {
                                IEnumerator goToState = branch.GetGoToState(stateMachine);
                                if (goToState != null)
                                {
                                    stateMachine.GoToState(goToState);
                                }

                                branchTaken = true;
                                break;
                            }
                        }

                        yield return(null);
                    }

                    foreach (ConditionalStateBackgroundLogic branch in _backgroundLogic)
                    {
                        branch.OnLogicFinished(stateMachine);
                    }

                    foreach (ConditionalStateBranch branch in _branches)
                    {
                        branch.OnBranchingFinished(stateMachine);
                    }
                }
            }
            public override IEnumerator PerformState(StateMachineComponent stateMachine)
            {
                PlayableDirector director = _director.GetComponent();
                PlayableAsset    playable = _playableAsset.LoadAsset();

                if (director != null && playable != null)
                {
                    director.Play(playable, DirectorWrapMode.None);

                    while (director.playableGraph.IsValid() && !director.playableGraph.IsDone())
                    {
                        yield return(null);
                    }
                }

                stateMachine.GoToState(StateMachine.Run(stateMachine, _goToState));
            }
Example #4
0
            public override IEnumerator PerformState(StateMachineComponent stateMachine)
            {
                yield return(_coroutine.RunCoroutine());

                stateMachine.GoToState(StateMachine.Run(stateMachine, _goToState));
            }
Example #5
0
 public eEventTriggerReturn Trigger(StateMachineComponent stateMachine)
 {
     stateMachine.GoToState(StateMachine.Run(stateMachine, _state));
     return(eEventTriggerReturn.EventFinishedExitState);
 }
Example #6
0
            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;
            }