public bool RemoveBehaviour <T> () where T : SteeringBehaviour
        {
            T t = FindBehaviour <T>();

            if (t != null)
            {
                SteeringBehaviour.Destroy(t);
                DeregisterBehaviour(t);
                return(true);
            }
            return(false);
        }
        internal void RegisterBehaviour(SteeringBehaviour behaviour)
        {
            if (behaviours == null)
            {
                behaviours = new Dictionary <BehaviourType, SteeringBehaviour>();
            }

            BehaviourType bt = behaviour.type;

            if (behaviours.ContainsKey(bt))
            {
                SteeringBehaviour.Destroy(behaviour);
                DeregisterBehaviour(behaviour);
            }
            behaviours[bt] = behaviour;
        }
        internal void DeregisterBehaviour(SteeringBehaviour behaviour)
        {
            if (behaviours == null)
            {
                return;
            }

            BehaviourType bt = behaviour.type;

            if (behaviours.ContainsKey(bt))
            {
                if (behaviours[bt] == behaviour)
                {
                    behaviours.Remove(bt);
                }
            }
        }
        private void UpdateBehaviours()
        {
            bool _idle = true;

            if (behaviours != null)
            {
                foreach (KeyValuePair <BehaviourType, SteeringBehaviour> kvp in behaviours)
                {
                    SteeringBehaviour behaviour = kvp.Value;
                    if (behaviour != null && behaviour.enabled && behaviour.active)
                    {
                        if (!behaviour.idle)
                        {
                            _idle = false;
                        }
                        behaviour.Behave();
                    }
                }
            }
            if (_idle)
            {
                AddDesiredVelocity(Vector3.zero, 1);
            }
        }