Exemplo n.º 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 (GenericBehaviour 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);
    }
Exemplo n.º 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));
 }
Exemplo n.º 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);
 }
Exemplo n.º 4
0
 public bool OverrideWithBehaviour(GenericBehaviour behaviour)
 {
     if (overrideBehaviours.Contains(behaviour) == false)
     {
         if (overrideBehaviours.Count == 0)
         {
             for (int i = 0; i < behaviours.Count; i++)
             {
                 if (behaviours[i].isActiveAndEnabled && currentBehaviour == behaviour.BehaviourCode)
                 {
                     behaviour.OnOverride();
                     break;
                 }
             }
         }
         overrideBehaviours.Add(behaviour);
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
 public bool OverrideWithBehaviour(GenericBehaviour behaviour)
 {
     if (!overridingBehaviours.Contains(behaviour))
     {
         if (overridingBehaviours.Count == 0)
         {
             foreach (GenericBehaviour overriddenBehaviour in behaviours)
             {
                 if (overriddenBehaviour.isActiveAndEnabled && currentBehaviour == overriddenBehaviour.GetBehaviourCode())
                 {
                     overriddenBehaviour.OnOverride();
                     break;
                 }
             }
         }
         overridingBehaviours.Add(behaviour);
         return(true);
     }
     return(false);
 }
Exemplo n.º 6
0
 // Put a new behaviour on the behaviours watch list.
 public void SubscribeBehaviour(GenericBehaviour behaviour)
 {
     behaviours.Add(behaviour);
 }