Beispiel #1
0
        // Attempt to override any active behaviour with the behaviours on queue.
        // Use to change to one or more behaviours that must overlap the active one (ex.: aim behaviour).
        public bool OverrideWithBehaviour(GenericBehaviour behaviour)
        {
            // Behaviour is not on queue.
            if (!overridingBehaviours.Contains(behaviour))
            {
                // No behaviour is currently being overridden.
                if (overridingBehaviours.Count == 0)
                {
                    // Call OnOverride function of the active behaviour before overrides it.
                    foreach (var overriddenBehaviour in behaviours)
                    {
                        if (overriddenBehaviour.isActiveAndEnabled &&
                            currentBehaviour == overriddenBehaviour.GetBehaviourCode())
                        {
                            overriddenBehaviour.OnOverride();
                            break;
                        }
                    }
                }

                // Add overriding behaviour to the queue.
                overridingBehaviours.Add(behaviour);
                return(true);
            }

            return(false);
        }
Beispiel #2
0
 // Check if any or a specific behaviour is currently overriding the active one.
 public bool IsOverriding(GenericBehaviour behaviour = null)
 {
     if (behaviour == null)
     {
         return(overridingBehaviours.Count > 0);
     }
     return(overridingBehaviours.Contains(behaviour));
 }
Beispiel #3
0
        // Attempt to revoke the overriding behaviour and return to the active one.
        // Called when exiting the overriding behaviour (ex.: stopped aiming).
        public bool RevokeOverridingBehaviour(GenericBehaviour behaviour)
        {
            if (overridingBehaviours.Contains(behaviour))
            {
                overridingBehaviours.Remove(behaviour);
                return(true);
            }

            return(false);
        }
Beispiel #4
0
 // Put a new behaviour on the behaviours watch list.
 public void SubscribeBehaviour(GenericBehaviour behaviour)
 {
     behaviours.Add(behaviour);
 }