Example #1
0
    private void SearchInFsm(InternalStateMachine stateMachine)
    {
        var fsm    = BehaviourWindow.activeFsm;
        var states = fsm.states;

        foreach (var state in states)
        {
            var hasMatchNode = false;
            if (state is InternalBehaviourTree)
            {
                var tree = state as InternalBehaviourTree;
                hasMatchNode = tree.GetNodes().Where(e => e.GetType().Name == m_searchNode).Any();
            }
            else if (state is InternalActionState)
            {
                hasMatchNode = ((InternalActionState)state).GetNodes().Where(e => e.GetType().Name == m_searchNode).Any();
            }
            else
            {
                Debug.Log(state.stateName + " not tree or action!");
            }

            state.searchColor = StateColor.Grey;
            if (hasMatchNode)
            {
                state.searchColor = StateColor.Red;
            }
        }
    }
        public static int GetStateMachineDepth(this InternalStateBehaviour state)
        {
            int depth = 0;
            InternalStateMachine fsm = state.fsm;

            while (fsm != null)
            {
                fsm = fsm.fsm;
                depth++;
            }
            return(depth);
        }
Example #3
0
        private void EnsureStateMachine()
        {
            // Ensure state machine exists. (Can be destroyed by script reload)
            if (_stateMachine != null)
            {
                return;
            }

            _state = DefaultState;

            _stateMachine = new InternalStateMachine(() => _state,
                                                     state => _state = state);

            _stateMachine.OnTransitioned(OnStateMachineTransitioned);

            Configure();
        }
        /// <summary>
        /// Sets the state as not concurrent.
        /// Automatically handles undo.
        /// <param name="fsm">The fsm to remove the concurrent state.</param>
        /// </summary>
        public static void RemoveConcurrentState(InternalStateMachine fsm)
        {
            // The fsm is valid and the state is not the start state?
            if (fsm != null && fsm.concurrentState != null)
            {
                // Register undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(fsm, "Concurrent State");
                #else
                Undo.RecordObject(fsm, "Concurrent State");
                #endif

                fsm.concurrentState = null;
                EditorUtility.SetDirty(fsm);

                // EditorUtility.SetDirty(state); // Repaint state inspector
            }
        }
Example #5
0
        /// <summary>
        /// Returns the destination of a transition.
        /// </summary>
        protected InternalStateBehaviour GetDestination(InternalStateMachine fsm, InternalStateBehaviour destination)
        {
            if (fsm == null || destination == null)
            {
                return(null);
            }

            InternalStateMachine currentFsm = destination.fsm;

            if (currentFsm == fsm)
            {
                return(destination);
            }

            while (currentFsm != null && fsm != currentFsm.fsm)
            {
                currentFsm = currentFsm.fsm;
            }

            return(currentFsm);
        }
Example #6
0
        /// <summary>
        /// Returns the states in the supplied fsm hierarchy.
        /// <prama name=f"fsm">The target fsm.</param>
        /// <prama name=f"exclude">Exclude the supplied StateMachine hierarchy.</param>
        /// <returns>All children in the fsm hierarchy.</returns>
        /// </summary>
        InternalStateBehaviour[] GetStatesInHierarchy(InternalStateMachine fsm, InternalStateMachine exclude)
        {
            List <InternalStateBehaviour> states = new List <InternalStateBehaviour>();

            foreach (InternalStateBehaviour state in fsm.states)
            {
                if (!(state is InternalAnyState))
                {
                    states.Add(state);

                    if (state != exclude)
                    {
                        var fsmChild = state as InternalStateMachine;
                        if (fsmChild != null)
                        {
                            states.AddRange(GetStatesInHierarchy(fsmChild, exclude));
                        }
                    }
                }
            }

            return(states.ToArray());
        }