Ejemplo n.º 1
0
 // Check if any or a specific behaviour is currently overriding the active one.
 public bool IsOverriding(MyGenericBehaviour behaviour = null)
 {
     if (behaviour == null)
     {
         return(overridingBehaviours.Count > 0);
     }
     return(overridingBehaviours.Contains(behaviour));
 }
Ejemplo n.º 2
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(MyGenericBehaviour behaviour)
 {
     if (overridingBehaviours.Contains(behaviour))
     {
         overridingBehaviours.Remove(behaviour);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
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(MyGenericBehaviour 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 (MyGenericBehaviour 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);
 }
Ejemplo n.º 4
0
 // Put a new behaviour on the behaviours watch list.
 public void SubscribeBehaviour(MyGenericBehaviour behaviour)
 {
     behaviours.Add(behaviour);
 }