internal static void DestroyGameObjectComponent(XObject obj) { XGameObject xgo = null; XComponent xcom = null; if (obj is XGameObject) { xgo = (XGameObject)obj; List <XComponent> components; if (!m_XComponentMap.TryGetValue(xgo, out components)) { throw new Exception(string.Concat("m_XComponentMap :", xgo, " null")); } int count = components.Count; for (int i = 0; i < count; i++) { if (m_StartMap.ContainsKey(components[i].GetInstanceID())) { m_StartMap.Remove(components[i].GetInstanceID()); } components[i].OnDestory(); components[i].SetDestroy(); } //可回收List 偷个懒 xgo.SetDestroy(); m_XComponentMap.Remove(xgo); } else if (obj is XComponent) { xcom = (XComponent)obj; List <XComponent> components; xgo = ((XComponent)obj).xGameObject; if (!m_XComponentMap.TryGetValue(xgo, out components)) { throw new Exception(string.Concat("m_XComponentMap :", xgo, " null")); } int idx = components.IndexOf(xcom); if (idx < 0 || idx >= components.Count) { throw new Exception(string.Concat("m_XComponentMap : XComponent", xcom, " null")); } xcom.OnDestory(); xcom.SetDestroy(); components.RemoveAt(idx); if (m_StartMap.ContainsKey(xcom.GetInstanceID())) { m_StartMap.Remove(xcom.GetInstanceID()); } } }
private static XComponent AddGameObjectComponentInternal(XGameObject xgameObject, Type type) { List <XComponent> components = null; if (!m_XComponentMap.TryGetValue(xgameObject, out components)) { //可优化池 先懒一下 components = new List <XComponent>(); m_XComponentMap.Add(xgameObject, components); } XComponent component = (XComponent)Activator.CreateInstance(type); component.XGameObject = xgameObject; components.Add(component); if (!m_StartMap.ContainsKey(component.GetInstanceID())) { m_StartMap.Add(component.GetInstanceID(), component); } component.OnAwake(); return(component); }