/// <summary> /// Attach update methods to this entity. /// </summary> /// <param name="behaviors">Behaviors to be executed during this entity's update method.</param> public void AddBehavior(params EntityUpdateBehavior[] behaviors) { if (Behaviors == null) { Behaviors = new Dictionary <string, List <EntityUpdateBehavior> >(); } foreach (var behavior in behaviors) { var group = behavior.Group ?? string.Empty; behavior.Entity = this; if (Behaviors.ContainsKey(group)) { Behaviors[group].Add(behavior); } else { Behaviors[group] = new List <EntityUpdateBehavior> { behavior } }; behavior.Attached(); } }
public T GetBehavior <T>() where T : Behavior { return(Behaviors.ContainsKey(typeof(T)) ? Behaviors[typeof(T)] as T : null); }