public virtual void Shutdown() { if (SystemDic != null) { SystemDic.Clear(); SystemDic = null; } if (SingletonComponentDic != null) { SingletonComponentDic.Clear(); SingletonComponentDic = null; } if (ComponentDic != null) { ComponentDic.Clear(); ComponentDic = null; } if (EntityDic != null) { foreach (var v in EntityDic) { if (v.Value != null) { v.Value.Dispose(); } } EntityDic.Clear(); EntityDic = null; } }
public HashSet <T> AllEntityComponents <T>() where T : ComponentBase { HashSet <ComponentBase> coll = null; if (ComponentDic.TryGetValue(typeof(T), out coll)) { return(new HashSet <T>(coll.Cast <T>())); } return(null); }
public T AnyEntityComponent <T>() where T : ComponentBase { HashSet <ComponentBase> coll = null; if (ComponentDic.TryGetValue(typeof(T), out coll)) { return(coll.First() as T); } return(null); }
public void OnEntityAddComponent(ComponentBase component) { if (component == null) { return; } HashSet <ComponentBase> coll = null; if (ComponentDic.TryGetValue(component.GetType(), out coll)) { coll.Add(component); } else { coll = new HashSet <ComponentBase> { component }; ComponentDic[component.GetType()] = coll; } }
public void OnEntityRemoveComponent(ComponentBase component) { if (!component) { return; } HashSet <ComponentBase> coll = null; if (ComponentDic.TryGetValue(component.GetType(), out coll)) { try { coll.Remove(component); } catch (System.Exception e) { Debug.LogError(e); } } }