// 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); }
// 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)); }
// 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); }
// Put a new behaviour on the behaviours watch list. public void SubscribeBehaviour(GenericBehaviour behaviour) { behaviours.Add(behaviour); }