/// <summary> /// Removes an ObjectComponent from this. /// </summary> /// <param name="component">The ObjectComponent to be removed.</param> public virtual void RemoveComponent(ObjectComponent component) { if (component != null && comps.Contains(component)) { if (component is IUpdate) { if (component is IPriorityComponent) { priorities.Remove(component as IPriorityComponent); } else { updateComps.Remove(component as IUpdate); } } if (component is IPostUpdate) { postUpdateComps.Remove(component as IPostUpdate); } if (component is IDispose) { ((IDispose)component).Dispose(true); disposableComps.Remove(component as IDispose); } if (unInit.Contains(component)) { unInit.Remove(component); } comps.Remove(component); } }
/// <summary> /// Finds a ObjectComponent matching the given type. /// </summary> /// <param name="type">The type of the ObjectComponent to find</param> /// <returns>The result of the search.</returns> public ObjectComponent FindComponent(Type type) { ObjectComponent comp = null; comp = (from c in comps where c.GetType() == type select c).FirstOrDefault(); return(comp); }
/// <summary> /// Finds a ObjectComponent matching the given id. /// </summary> /// <param name="id">The id of the ObjectComponent to find.</param> /// <returns>The result of the search.</returns> public ObjectComponent FindComponent(string id) { ObjectComponent comp = null; comp = (from c in comps where c.ID == id select c).FirstOrDefault(); return(comp); }
/// <summary> /// Removes an ObjectComponent with the given id. /// </summary> /// <param name="type">The id of the ObjectComponent to be remove.</param> public void RemoveComponent(string id) { ObjectComponent comp = null; comp = (from c in comps where c.ID == id select c).FirstOrDefault(); if (comp != null) { RemoveComponent(comp); } }
/// <summary> /// Used to send a message to Components. /// </summary> /// <param name="message">The message to be sent.</param> /// <param name="target">The target Component for the message (if any).</param> public object SendMessage(string message, string target, params object[] parameters) { MethodInfo info = GetType().GetMethod(message); if (info != null) { info.Invoke(this, parameters); } else { if (target == null) { var cs = (from c in comps where c.GetType().GetMethod(message) != null select c).ToList(); object obj = null; foreach (var comp in cs) { obj = comp.GetType().GetMethod(message).Invoke(comp, parameters); } return(obj); } else { ObjectComponent comp = FindComponent(target); if (comp == null) { comp = FindComponent(AssemblyManager.GetType(target)); } object obj = null; if (comp != null) { if (comp.GetType().GetMethod(message) != null) { obj = comp.GetType().GetMethod(message).Invoke(comp, parameters); } } return(obj); } } return(null); }
/// <summary> /// Attaches an ObjectComponent to this GameObject. /// </summary> /// <param name="component">The ObjectComponent to be attached.</param> public void AttachComponent(ObjectComponent component) { ObjectComponent comp = null; comp = (from c in comps where c.ID == component.ID select c).FirstOrDefault(); if (comp == null) { component.Owner = this; if (component is IUpdate) { if (component is IPriorityComponent) { priorities.Add(component as IPriorityComponent); } else { updateComps.Add((IUpdate)component); } } if (component is IPostUpdate) { postUpdateComps.Add((IPostUpdate)component); } if (component is IDispose) { disposableComps.Add((IDispose)component); } AttachComponentAction(component); comps.Add(component); unInit.Add(component); } }
/// <summary> /// Used to further define what happends /// when an ObjectComponent is attached to this GameObject. /// </summary> /// <param name="component">The ObjectComponent to be attached to this GameObject.</param> protected virtual void AttachComponentAction(ObjectComponent component) { }