Beispiel #1
0
        /// <summary>
        /// The other collider has exited the trigger.
        /// </summary>
        /// <param name="other">The collider which exited the trigger.</param>
        private void OnTriggerExit(Collider other)
        {
            if (m_Duration > 0 || !MathUtility.InLayerMask(other.gameObject.layer, m_LayerMask))
            {
                return;
            }

            StateBehavior stateBehavior;

            if ((m_RequireCharacter && (stateBehavior = other.GetComponentInParent <Character.UltimateCharacterLocomotion>()) != null) ||
                (!m_RequireCharacter && (stateBehavior = other.GetComponentInParent <StateBehavior>()) != null))
            {
                if (m_ActivateStateEvent != null && m_ActivateStateEvent.Active)
                {
                    SchedulerBase.Cancel(m_ActivateStateEvent);
                    m_ActivateStateEvent = null;
                }
                else
                {
                    // The state shouldn't change when the object dies. It can be changed when the character respawns.
                    var health = other.gameObject.GetCachedParentComponent <Traits.Health>();
                    if (health != null && !health.IsAlive())
                    {
                        // When the character respawns the trigger enter/exit event may not fire. Register that the state should be deactivated so when the
                        // character respawns the state can then be disabled.
                        if (m_DeathDeactivations == null)
                        {
                            m_DeathDeactivations = new List <GameObject>();
                        }
                        if (!m_DeathDeactivations.Contains(stateBehavior.gameObject))
                        {
                            m_DeathDeactivations.Add(stateBehavior.gameObject);
                            EventHandler.RegisterEvent(stateBehavior.gameObject, "OnRespawn", OnRespawn);
                        }
                        return;
                    }

                    StateManager.SetState(stateBehavior.gameObject, m_StateName, false);
                    if (m_CharacterTransformChange)
                    {
                        EventHandler.ExecuteEvent(stateBehavior.gameObject, "OnCharacterImmediateTransformChange", true);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Activates or deactivates the state on the specified GameObject.
        /// </summary>
        /// <param name="gameObject">The GameObject to activate the state on.</param>
        /// <param name="activate">Should the state be activated?</param>
        private void ChangeState(GameObject gameObject, bool activate)
        {
            StateManager.SetState(gameObject, m_StateName, activate);
            m_ActivateStateEvent = null;
            int index;

            if (m_DeathDeactivations != null && (index = m_DeathDeactivations.IndexOf(gameObject)) > 0)
            {
                m_DeathDeactivations.RemoveAt(index);
                EventHandler.UnregisterEvent(gameObject, "OnRespawn", OnRespawn);
            }

            // The state can be disabled automatically.
            if (activate && m_Duration > 0)
            {
                Scheduler.Schedule(m_Duration, ChangeState, gameObject, false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Activates or deactivates the state on the specified GameObject.
        /// </summary>
        /// <param name="stateGameObject">The GameObject to activate the state on.</param>
        /// <param name="activate">Should the state be activated?</param>
        private void ChangeState(GameObject stateGameObject, bool activate)
        {
            StateManager.SetState(stateGameObject, m_StateName, activate);
            if (m_CharacterTransformChange)
            {
                EventHandler.ExecuteEvent(stateGameObject, "OnCharacterImmediateTransformChange", true);
            }
            m_ActivateStateEvent = null;
            int index;

            if (m_DeathDeactivations != null && (index = m_DeathDeactivations.IndexOf(stateGameObject)) > 0)
            {
                m_DeathDeactivations.RemoveAt(index);
                EventHandler.UnregisterEvent(stateGameObject, "OnRespawn", OnRespawn);
            }

            // The state can be disabled automatically.
            if (activate && m_Duration > 0)
            {
                SchedulerBase.Schedule(m_Duration, ChangeState, stateGameObject, false);
            }
        }
 /// <summary>
 /// Activates or deactivates the specified state.
 /// </summary>
 /// <param name="stateName">The name of the state to change the active status of.</param>
 /// <param name="active">Should the state be activated?</param>
 public void SetState(string stateName, bool active)
 {
     StateManager.SetState(this, m_States, stateName, active);
 }