Пример #1
0
        /// <summary>
        /// BehaviourMachine callback to update the members.
        /// </summary>
        public virtual void UpdateLogic()
        {
            // Validate Blackboard
            if (m_Blackboard == null)
            {
                m_Blackboard = GetComponent <InternalBlackboard>();
            }

            // Validate name
            if (string.IsNullOrEmpty(m_StateName))
            {
                m_StateName = GetType().Name;
            }

            // Validate parent
            if (m_Parent != null && m_Parent.gameObject != gameObject)
            {
                m_Parent     = m_LastParent != null && m_LastParent.gameObject == gameObject ? m_LastParent : null;
                this.enabled = m_Parent == null;
            }

            // Check for invalid events destinations
            for (int i = 0; i < m_Transitions.Length; i++)
            {
                // The destination state is not in this game object?
                var destination = m_Transitions[i].destination;
                if (destination != null && destination.parent != m_Parent)
                {
                    m_Transitions[i].destination = null;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Returns True if the supplied parent is an ancestor of the state.
 /// <param name="parent">The parent to test.</param>
 /// <returns>True if the node is in the supplied parent hierarchy; False otherwise.</returns>
 /// </summary>
 public bool IsAncestor(ParentBehaviour parent)
 {
     for (var grandfather = m_Parent; grandfather != null; grandfather = grandfather.parent)
     {
         if (grandfather == parent)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
        /// <summary>
        /// Use the event to change the enabled state in the StateMachine.
        /// The event is processed top-down, starting from the root InternalStateBehaviour.
        /// <param name="eventID">The id of the event.</param>
        /// <returns>Returns True if the event was used; False otherwise.</returns>
        /// </summary>
        public bool SendEvent(int eventID)
        {
            // Try to call ProcessEvent on the root parent
            ParentBehaviour rootParent = this.root;

            if (rootParent != null)
            {
                return(rootParent.ProcessEvent(eventID));
            }

            // Process event
            return(ProcessEvent(eventID));
        }
Пример #4
0
 /// <summary>
 /// Returns the full state name relative to the parent parent.
 /// <param name="parent"></param>
 /// <returns>the full state name relative to supplied parent.</returns>
 /// </summary>
 public string GetFullStateNameRelativeTo(ParentBehaviour parent)
 {
     return(parent != this && m_Parent != null ? (m_Parent.GetFullStateNameRelativeTo(parent) + "/" + m_StateName) : m_StateName);
 }
Пример #5
0
 /// <summary>
 /// Saves the last parent.
 /// </summary>
 void SaveLastParent()
 {
     m_LastParent = m_Parent;
 }