public static void AddComponent(MonoComponent component, int prio) { if (component.GetType() == typeof(RenderComponent) || component.GetType().IsSubclassOf(typeof(RenderComponent))) { if (!renderComps.ContainsKey(prio)) { renderComps[prio] = new List <RenderComponent>(); } renderComps[prio].Add((RenderComponent)component); } else if (component.GetType() == typeof(CircleCollider)) { if (!colliderComps.ContainsKey(prio)) { colliderComps[prio] = new List <CircleCollider>(); } colliderComps[prio].Add((CircleCollider)component); } else { if (!comps.ContainsKey(prio)) { comps[prio] = new List <MonoComponent>(); } comps[prio].Add(component); } }
private new void Update() { Time.currentTime = DateTime.Now.TimeOfDay; for (int i = 0; i < comps.Keys.Count; i++) { KeyValuePair <int, List <MonoComponent> > kvP = comps.ElementAt(i); for (int v = 0; v < kvP.Value.Count; v++) { if (v < 0) { break; } MonoComponent comp = kvP.Value[v]; if (comp.Owner.isActive) { comp.Update(); } if (comp.Owner.isDestroyed) { comp.Owner.RemoveComponent(comp); v--; } } if (kvP.Value.Count == 0) { i--; } } Time.lastUpdate = DateTime.Now.TimeOfDay; }
public MonoComponent AddComponent(MonoComponent component) { comps.Add(component); component.Owner = this; Form1.AddComponent(component, component.Priority); return(component); }
public static void RemoveComponent(MonoComponent component) { if (component.GetType() == typeof(RenderComponent) || component.GetType().IsSubclassOf(typeof(RenderComponent))) { if (renderComps.ContainsKey(component.Priority)) { if (renderComps[component.Priority].Contains(component)) { renderComps[component.Priority].Remove((RenderComponent)component); if (renderComps[component.Priority].Count == 0) { renderComps.Remove(component.Priority); } } } } else if (component.GetType() == typeof(CircleCollider)) { if (colliderComps.ContainsKey(component.Priority)) { if (colliderComps[component.Priority].Contains(component)) { colliderComps[component.Priority].Remove((CircleCollider)component); if (colliderComps[component.Priority].Count == 0) { colliderComps.Remove(component.Priority); } } } } else { if (comps.ContainsKey(component.Priority)) { if (comps[component.Priority].Contains(component)) { comps[component.Priority].Remove(component); if (comps[component.Priority].Count == 0) { comps.Remove(component.Priority); } } } } }
public IEnumerable <MonoComponent> GetComponents(MonoComponent c) { return(comps.Where(x => x.GetType() == c.GetType())); }
public bool RemoveComponent(MonoComponent component) { Form1.RemoveComponent(component); return(comps.Remove(component)); }