Esempio n. 1
0
 internal void ReleaseInFactory()
 {
     if (!m_isReleased)
     {
         Release();
         m_view       = null;
         m_isReleased = true;
     }
 }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        private static ViewObject InstanceViewFromPrefab(string prefabName, string defaultPrefabName)
        {
            GameObject prefab = Resources.Load <GameObject>(prefabName);

            if (prefab == null)
            {
                prefab = Resources.Load <GameObject>(defaultPrefabName);
            }

            if (prefab == null)
            {
                return(null);
            }

            GameObject go       = GameObject.Instantiate(prefab);
            ViewObject instance = go.GetComponent <ViewObject>();

            if (instance == null)
            {
                Debugger.LogError(LOG_TAG, "InstanceViewFromPrefab() prefab = {0} do not find!", prefabName);
            }

            return(instance);
        }