Exemplo n.º 1
0
 public FSMStateMachineLogic(Type stateClass, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     this.m_ChildrenTypes = new List <Type>();
     this.m_StateClass    = stateClass;
     this.m_OwnerSM       = ownerSM;
     this.m_Parent        = parent;
 }
 public FSMStateMachineLogic(System.Type stateClass, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     m_ChildrenTypes = new List<System.Type>();
     m_StateClass = stateClass;
     m_OwnerSM = ownerSM;
     m_Parent = parent;
 }
Exemplo n.º 3
0
 public FSMStateMachineLogic(System.Type stateClass, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     m_ChildrenTypes = new List <System.Type>();
     m_StateClass    = stateClass;
     m_OwnerSM       = ownerSM;
     m_Parent        = parent;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Try to make one of my children transition to the specified state
        /// </summary>
        /// <param name="child"> The state that will be transitioned </param>
        /// <param name="nextState"> The state you need to transition to. This should a sibling of child.</param>
        /// <param name="args"> The arguments passed in the transition. </param>
        public bool RequestChildTransition(FSMStateMachineLogic child, System.Type nextState, object[] args)
        {
            if (m_StateType == FSMStateType.Type_AND)
            {
                return(false);
            }

            for (int i = 0; i < m_ChildSMs.Count; i++)
            {
                if (m_ChildSMs[i] == child)
                {
                    // found the child, now find the definition of nextState

                    for (int j = 0; j < m_ChildrenTypes.Count; j++)
                    {
                        if (m_ChildrenTypes[j] == nextState)
                        {
                            // found the next state's definition
                            m_ChildSMs[i].Exit();
                            m_ChildSMs[i] = new FSMStateMachineLogic(nextState, m_OwnerSM, this);
                            m_ChildSMs[i].Enter(args);
                            return(true);
                        }
                    }

                    return(false);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
 public bool RequestChildTransition(FSMStateMachineLogic child, Type nextState, object[] args)
 {
     if (this.m_StateType == FSMStateType.Type_AND)
     {
         return(false);
     }
     for (int i = 0; i < this.m_ChildSMs.Count; i++)
     {
         if (this.m_ChildSMs[i] == child)
         {
             for (int j = 0; j < this.m_ChildrenTypes.Count; j++)
             {
                 if (this.m_ChildrenTypes[j] == nextState)
                 {
                     this.m_ChildSMs[i].Exit();
                     this.m_ChildSMs[i] = new FSMStateMachineLogic(nextState, this.m_OwnerSM, this);
                     this.m_ChildSMs[i].Enter(args);
                     return(true);
                 }
             }
             return(false);
         }
     }
     return(false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Enters the specified state. It will also enter all necessary children state.
        /// </summary>
        /// <param name="args"> The arguments passed in the transition. The state's constructor will be chosen to match the arguments specified.
        /// If args is null, the default constructor will be used.</param>
        public void Enter(object[] args)
        {
            // create an instance of the actual state
            // call enter on it

            if (m_StateClass != null)
            {
                m_State = (BaseFSMState)System.Activator.CreateInstance(m_StateClass, args);
                m_State._InternalSetOwnerLogic(this);
                m_State.SetupDefinition(ref m_StateType, ref m_ChildrenTypes);
                m_State.Enter();
            }

            // create an instance of the necessary child state machines
            // call enter on them


            for (int i = 0; i < m_ChildrenTypes.Count; i++)
            {
                FSMStateMachineLogic childSM = new FSMStateMachineLogic(m_ChildrenTypes[i], m_OwnerSM, this);
                m_ChildSMs.Add(childSM);
                childSM.Enter(null);
                if (m_StateType == FSMStateType.Type_OR)
                {
                    // just add the first child and exit
                    break;
                }
                // else add all the children
            }
        }
Exemplo n.º 7
0
 public FSMStateMachineLogic(FSMStateType stateType, List <Type> childrenTypes, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     this.m_StateClass    = null;
     this.m_StateType     = stateType;
     this.m_ChildrenTypes = childrenTypes;
     this.m_Parent        = parent;
     this.m_OwnerSM       = ownerSM;
 }
Exemplo n.º 8
0
 public FSMStateMachineLogic(FSMStateType stateType, List <System.Type> childrenTypes, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     m_StateClass    = null;
     m_StateType     = stateType;
     m_ChildrenTypes = childrenTypes;
     m_Parent        = parent;
     m_OwnerSM       = ownerSM;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Calling this will trigger Exit() on all active states in the state machine.
 /// </summary>
 public virtual void StopSM()
 {
     if (m_Logic != null)
     {
         m_Logic.Exit();
         m_Logic = null;
     }
 }
 public FSMStateMachineLogic(FSMStateType stateType, List<System.Type> childrenTypes, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     m_StateClass = null;
     m_StateType = stateType;
     m_ChildrenTypes = childrenTypes;
     m_Parent = parent;
     m_OwnerSM = ownerSM;
 }
Exemplo n.º 11
0
 public virtual void StopSM()
 {
     if (this.m_Logic != null)
     {
         this.m_Logic.Exit();
         this.m_Logic = null;
     }
 }
 /// <summary>
 /// Calling this will trigger Exit() on all active states in the state machine.
 /// </summary>
 public virtual void StopSM()
 {
     if (m_Logic != null)
     {
         m_Logic.Exit();
         m_Logic = null;
     }
 }
Exemplo n.º 13
0
        public virtual void StartSM()
        {
            FSMStateType fSMStateType = FSMStateType.Type_OR;
            List <Type>  types        = new List <Type>();

            this.SetupDefinition(ref fSMStateType, ref types);
            this.m_Logic = new FSMStateMachineLogic(fSMStateType, types, this, null);
            this.m_Logic.Enter(null);
        }
        /// <summary>
        /// Calling this will enter the state machine's initial state(s)
        /// </summary>
        public virtual void StartSM()
        {
            FSMStateType stateType = FSMStateType.Type_OR;
            List<System.Type> children = new List<System.Type>();
            SetupDefinition(ref stateType, ref children);

            m_Logic = new FSMStateMachineLogic(stateType, children, this, null);
            m_Logic.Enter(null);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Calling this will enter the state machine's initial state(s)
        /// </summary>
        public virtual void StartSM()
        {
            FSMStateType       stateType = FSMStateType.Type_OR;
            List <System.Type> children  = new List <System.Type>();

            SetupDefinition(ref stateType, ref children);

            m_Logic = new FSMStateMachineLogic(stateType, children, this, null);
            m_Logic.Enter(null);
        }
Exemplo n.º 16
0
 public void Exit()
 {
     for (int i = 0; i < this.m_ChildSMs.Count; i++)
     {
         this.m_ChildSMs[i].Exit();
     }
     if (this.m_State != null)
     {
         this.m_State.Exit();
     }
     this.m_OwnerSM = null;
     this.m_Parent  = null;
     this.m_State   = null;
     this.m_ChildSMs.Clear();
 }
Exemplo n.º 17
0
        /// <summary>
        /// Exits the specified state. All children states will be exited before calling exit on m_State
        /// </summary>
        public void Exit()
        {
            for (int i = 0; i < m_ChildSMs.Count; i++)
            {
                m_ChildSMs[i].Exit();
            }

            if (m_State != null)
            {
                m_State.Exit();
            }

            // reset all the data in case user is holding on to the object
            m_OwnerSM = null;
            m_Parent  = null;
            m_State   = null;
            m_ChildSMs.Clear();
        }
Exemplo n.º 18
0
 public void Enter(object[] args)
 {
     if (this.m_StateClass != null)
     {
         this.m_State = (BaseFSMState)Activator.CreateInstance(this.m_StateClass, args);
         this.m_State._InternalSetOwnerLogic(this);
         this.m_State.SetupDefinition(ref this.m_StateType, ref this.m_ChildrenTypes);
         this.m_State.Enter();
     }
     for (int i = 0; i < this.m_ChildrenTypes.Count; i++)
     {
         FSMStateMachineLogic fSMStateMachineLogic = new FSMStateMachineLogic(this.m_ChildrenTypes[i], this.m_OwnerSM, this);
         this.m_ChildSMs.Add(fSMStateMachineLogic);
         fSMStateMachineLogic.Enter(null);
         if (this.m_StateType == FSMStateType.Type_OR)
         {
             break;
         }
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Internal system function, do not call this from your gameplay code!
 /// </summary>
 public void _InternalSetOwnerLogic(FSMStateMachineLogic ownerLogic)
 {
     m_OwnerLogic = ownerLogic;
 }
        /// <summary>
        /// Try to make one of my children transition to the specified state
        /// </summary>
        /// <param name="child"> The state that will be transitioned </param>
        /// <param name="nextState"> The state you need to transition to. This should a sibling of child.</param>
        /// <param name="args"> The arguments passed in the transition. </param>
        public bool RequestChildTransition(FSMStateMachineLogic child, System.Type nextState, object[] args)
        {
            if (m_StateType == FSMStateType.Type_AND)
            {
                return false;
            }

            for (int i = 0; i < m_ChildSMs.Count; i++)
            {
                if (m_ChildSMs[i] == child)
                {
                    // found the child, now find the definition of nextState

                    for (int j = 0; j < m_ChildrenTypes.Count; j++)
                    {
                        if (m_ChildrenTypes[j] == nextState)
                        {
                            // found the next state's definition
                            m_ChildSMs[i].Exit();
                            m_ChildSMs[i] = new FSMStateMachineLogic(nextState, m_OwnerSM, this);
                            m_ChildSMs[i].Enter(args);
                            return true;
                        }
                    }

                    return false;
                }
            }

            return false;
        }
        /// <summary>
        /// Exits the specified state. All children states will be exited before calling exit on m_State
        /// </summary>
        public void Exit()
        {
            for (int i = 0; i < m_ChildSMs.Count; i++)
            {
                m_ChildSMs[i].Exit();
            }

            if (m_State != null)
            {
                m_State.Exit();
            }

            // reset all the data in case user is holding on to the object
            m_OwnerSM = null;
            m_Parent = null;
            m_State = null;
            m_ChildSMs.Clear();
        }
        /// <summary>
        /// Enters the specified state. It will also enter all necessary children state.
        /// </summary>
        /// <param name="args"> The arguments passed in the transition. The state's constructor will be chosen to match the arguments specified.
        /// If args is null, the default constructor will be used.</param>
        public void Enter(object[] args)
        {
            // create an instance of the actual state
            // call enter on it

            if (m_StateClass != null)
            {
                m_State = (BaseFSMState)System.Activator.CreateInstance(m_StateClass, args);
                m_State._InternalSetOwnerLogic(this);
                m_State.SetupDefinition(ref m_StateType, ref m_ChildrenTypes);
                m_State.Enter();
            }

            // create an instance of the necessary child state machines
            // call enter on them


            for (int i = 0; i < m_ChildrenTypes.Count; i++)
            {
                FSMStateMachineLogic childSM = new FSMStateMachineLogic(m_ChildrenTypes[i], m_OwnerSM, this);
                m_ChildSMs.Add(childSM);
                childSM.Enter(null);
                if (m_StateType == FSMStateType.Type_OR)
                {
                    // just add the first child and exit
                    break;
                }
                // else add all the children
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Internal system function, do not call this from your gameplay code!
 /// </summary>
 public void _InternalSetOwnerLogic(FSMStateMachineLogic ownerLogic)
 {
     m_OwnerLogic = ownerLogic;
 }