public SteeringMovementModule(IAgent agent)
            : base(agent)
        {
            steeringOwner = agent as SteeringAgent;

            steeringBehaviours = new Dictionary <SteeringBehaviourId, SteeringBehaviour>();

            avoidanceBehaviour = steeringBehaviours[SteeringBehaviourId.Avoidance] = new Avoidance(steeringOwner);
        }
        public void setBehaviour <T>() where T : SteeringBehaviour
        {
            var type            = typeof(T);
            var typeBehaviourId = behavioursMappings.FirstOrDefault(x => x.Value == type).Key;

            if (steeringBehaviours.ContainsKey(typeBehaviourId))
            {
                currentBehaviour = steeringBehaviours[typeBehaviourId];
            }
            else
            {
                currentBehaviour = (T)Activator.CreateInstance(type, owner);
                steeringBehaviours[typeBehaviourId] = currentBehaviour;
            }
        }
 public void setBehaviour(SteeringBehaviourId id)
 {
     if (steeringBehaviours.ContainsKey(id))
     {
         currentBehaviour = steeringBehaviours[id];
     }
     else
     {
         Type type;
         bool found = behavioursMappings.TryGetValue(id, out type);
         if (found)
         {
             currentBehaviour       = (SteeringBehaviour)Activator.CreateInstance(type, owner);
             steeringBehaviours[id] = currentBehaviour;
         }
         else
         {
             throw new System.ArgumentException("Parameter behaviour id not recognised.", id.ToString());
         }
     }
 }
示例#4
0
 public void addBehaviour(SteeringBehaviour b, float weight = 1f)
 {
     behaviours.Add(b);
     weights.Add(weight);
 }