public void SetState(T state)
    {
        int stateIndex = (int)(object)state;

        if (stateIndex == m_CurrentStateIndex)
        {
            return;
        }

        // Leave current state
        if (m_CurrentStateCallbacks != null && m_CurrentStateCallbacks.exitStateCallback != null)
        {
            m_CurrentStateCallbacks.exitStateCallback();
        }

        // Set state
        m_CurrentStateIndex     = stateIndex;
        m_CurrentStateCallbacks = m_StateCallbacks[m_CurrentStateIndex];

        // Enter new state
        if (m_CurrentStateCallbacks != null && m_CurrentStateCallbacks.enterStateCallback != null)
        {
            m_CurrentStateCallbacks.enterStateCallback();
        }
    }
    public void SetStateCallbacks(T state, System.Action enterStateCallback, System.Action updateStateCallback, System.Action exitStateCallback)
    {
        int            index          = (int)(object)state;
        StateCallbacks stateCallbacks = m_StateCallbacks[index];

        stateCallbacks.enterStateCallback  = enterStateCallback;
        stateCallbacks.updateStateCallback = updateStateCallback;
        stateCallbacks.exitStateCallback   = exitStateCallback;
    }
    public SimpleEnumStateMachine()
    {
        int enumCount = System.Enum.GetValues(typeof(T)).Length;

        m_StateCallbacks = new StateCallbacks[enumCount];

        for (int i = 0; i < enumCount; ++i)
        {
            m_StateCallbacks[i] = new StateCallbacks();
        }
    }
        public State(StateCallbacks callback, IPhy phy)
        {
            _callback = callback;
            phy.GetDeviceAddress(out aExtendedAddress);
            int phyMtu;

            phy.GetMtuSize(out phyMtu, out phyFrameHead, out phyFrameTail);

            phy.IsCapabilitySupported(Capabilities.Ieee2006, out phySupports2006);

            Reset();
        }
Beispiel #5
0
        /// @param stateNameHash
        ///     The name hash of the exited state
        ///
        private void OnExitStateRequested(int stateNameHash)
        {
            if (m_currentState != null && m_currentState.m_stateID == stateNameHash)
            {
                var callback = m_currentState.m_exitState;
                m_currentState = null;
                callback.SafeInvoke();

                // Check if there is a next state request
                if (m_nextState != 0)
                {
                    EnterState(m_nextState);
                    m_nextState = 0;
                }
            }
        }
Beispiel #6
0
        /// @param stateName
        ///     The name of the state
        /// @param onEnter
        ///     The enter callback of the state
        /// @param onUpdate
        ///     The update callback of the state
        /// @param onExit
        ///     The exit callback of the state
        ///
        public void OverrideStateCallback(string stateName, Action onEnter, Action onUpdate, Action onExit)
        {
            int nameHash = Animator.StringToHash(stateName);

            if (m_states.ContainsKey(nameHash) == true)
            {
                m_states[nameHash] = new StateCallbacks()
                {
                    m_stateID     = nameHash,
                    m_enterState  = onEnter,
                    m_updateState = onUpdate,
                    m_exitState   = onExit
                };
            }
            else
            {
                RegisterStateCallback(stateName, onEnter, onUpdate, onExit);
            }
        }
Beispiel #7
0
        public State(StateCallbacks callback, IPhy phy)
        {
            _callback = callback;
            phy.GetDeviceAddress(out aExtendedAddress);
            int phyMtu;
            phy.GetMtuSize(out phyMtu, out phyFrameHead, out phyFrameTail);

            phy.IsCapabilitySupported(Capabilities.Ieee2006, out phySupports2006);

            Reset();
        }
Beispiel #8
0
 /// @param stateNameHash
 ///     The name hash to enter
 ///
 private void EnterState(int stateNameHash)
 {
     m_currentState = m_states[stateNameHash];
     m_currentState.m_enterState.SafeInvoke();
 }