private void UpdateInPlayMode()
                {
                    _debugging = false;

                    if (_editorPrefs._debug)
                    {
                        StateMachineComponent       stateMachine = _editorPrefs._debugObject.GetComponent();
                        StateMachineDebug.StateInfo stateInfo    = StateMachineDebug.GetStateInfo(stateMachine != null ? stateMachine.gameObject : null);

                        if (stateInfo != null)
                        {
                            _debugging = true;

                            if (_currentFileName != stateInfo._fileName && stateInfo._fileName != null)
                            {
                                _currentFileName = stateInfo._fileName;
                                SetStateMachine(stateInfo._stateMachine);
                                _timelineEditor.SetTimeline(null);
                            }

                            switch (_currentMode)
                            {
                            case eMode.ViewingStateMachine:
                            {
                                if (_playModeHighlightedState != stateInfo._state)
                                {
                                    GetEditorWindow().DoRepaint();
                                }

                                _playModeHighlightedState = stateInfo._state;

                                if (_editorPrefs._debugLockFocus)
                                {
                                    CenterCameraOn(GetStateGUI(_playModeHighlightedState._stateId));
                                }
                            }
                            break;

                            case eMode.ViewingTimelineState:
                            {
                                if (stateInfo._state._stateId != _editedTimelineState.GetStateId())
                                {
                                    _editedTimelineState = GetStateGUI(stateInfo._state._stateId) as TimeLineStateEditorGUI;

                                    if (_editedTimelineState != null)
                                    {
                                        _timelineEditor.SetTimeline(((TimelineState)stateInfo._state)._timeline);
                                    }
                                }

                                _timelineEditor.SetPlayModeCursorTime(stateInfo._time);
                                GetEditorWindow().DoRepaint();
                            }
                            break;
                            }
                        }
                    }
                }
Exemplo n.º 2
0
            public static IEnumerator Run(StateMachineComponent stateMachine, State startState, GameObject sourceObject = null)
            {
                if (startState != null)
                {
#if UNITY_EDITOR && DEBUG
                    StateMachineDebug.OnStateStarted(stateMachine, startState, null);
#endif
                    return(startState.PerformState(stateMachine));
                }

                return(null);
            }
Exemplo n.º 3
0
            public static IEnumerator Run(StateMachineComponent stateMachine, StateRefProperty startState, GameObject sourceObject = null)
            {
                State state = startState.LoadTimelineState(sourceObject != null ? sourceObject : stateMachine.gameObject);

                if (state != null)
                {
#if UNITY_EDITOR && DEBUG
                    string debugFileName = AssetDatabase.GetAssetPath(startState.GetFile());
                    StateMachineDebug.OnStateStarted(stateMachine, state, debugFileName);
#endif
                    return(state.PerformState(stateMachine));
                }

                return(null);
            }
Exemplo n.º 4
0
            public static IEnumerator Run(StateMachineComponent stateMachine, StateRef startState, GameObject sourceObject = null)
            {
                State state = startState.GetState(sourceObject != null ? sourceObject : stateMachine.gameObject);

                if (state != null)
                {
#if UNITY_EDITOR && DEBUG
                    string debugFileName = startState.GetExternalFile().GetFilePath();
                    StateMachineDebug.OnStateStarted(stateMachine, state, debugFileName);
#endif
                    return(state.PerformState(stateMachine));
                }

                return(null);
            }
Exemplo n.º 5
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;
            }