/// <summary> /// 实例化一个实体对象 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T InstanceEntity <T>() where T : EntityObject, new() { EntityObject obj = null; bool useRecycler = true; // 先从回收池中寻找 Type type = typeof(T); obj = m_recycler.Pop(type.FullName) as EntityObject; if (obj == null) { useRecycler = false; obj = new T(); } obj.InstanceInFactory(); m_objectList.Add(obj); if (EnableLog && Debugger.EnableLog) { Debugger.Log(LOG_TAG, "InstanceEntity() {0}:{1}, UseRecycler:{2}", obj.GetType().Name, obj.GetHashCode(), useRecycler); } return(obj as T); }
public static void CreateView(string resPath, string resDefaultPath, EntityObject entity, Transform parent = null) { ViewObject viewObj = null; string recycleType = resPath; bool useRecycler = true; viewObj = m_recycler.Pop(recycleType) as ViewObject; if (viewObj == null) { useRecycler = false; viewObj = InstanceViewFromPrefab(recycleType, resDefaultPath); } if (viewObj == null) { return; } if (!viewObj.gameObject.activeSelf) { viewObj.gameObject.SetActive(true); } viewObj.transform.SetParent(parent != null ? parent : m_viewRoot, false); viewObj.CreateInFactory(entity, recycleType); if (EnableLog && Debugger.EnableLog) { Debugger.Log(LOG_TAG, "CreateView() {0}:{1} -> {2}:{3}, UseRecycler:{4}", entity.GetType().Name, entity.GetHashCode(), viewObj.GetRecycleType(), viewObj.GetInstanceID(), useRecycler); } if (m_objMap.ContainsKey(entity)) { Debugger.LogError(LOG_TAG, "CreateView() 不应该存在重复的映射!"); } m_objMap[entity] = viewObj; }