Esempio n. 1
0
        private void CreateAsset(string uname, string path, Transform parent)
        {
            Transform prefab = GetPrefab <Transform>(path);

            if (prefab == null)
            {
                return;
            }
            Transform      target = Instantiate(prefab);
            PoolObjectInfo info   = new PoolObjectInfo
            {
                path       = path,
                name       = uname,
                gameObject = target.gameObject,
                transform  = target,
                component  = target.GetComponent <ZUIBehaviour>()
            };

            if (info.component == null)
            {
                info.component = target.GetComponent <ZBehaviourBase>();
            }

            assetList.Add(info);
            target.SetParent(parent, false);
            target.gameObject.SetActive(false);
        }
Esempio n. 2
0
        private T GetSleepAsset <T>() where T : MonoBehaviour
        {
            for (int i = 0; i < assetList.Count; i++)
            {
                PoolObjectInfo info = assetList[i];

                if (info.component != null && !info.gameObject.activeInHierarchy && info.name == typeof(T).Name && info.transform.parent == sleepParent)
                {
                    if (typeof(T) == info.component.GetType() || info.component.GetType().IsSubclassOf(typeof(T)))
                    {
                        return(info.component as T);
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
        private T GetSleepAssetByName <T>(string uname) where T : MonoBehaviour
        {
            for (int i = 0; i < assetList.Count; i++)
            {
                PoolObjectInfo info = assetList[i];

                if (info.component != null && !info.gameObject.activeSelf && uname == info.name && info.transform.parent == sleepParent)
                {
                    //Debug.LogError("GetSleepAssetByName...." + uname + ";info = " + info.name + "; active = " + info.gameObject.activeSelf);
                    if (typeof(T) == info.component.GetType() || info.component.GetType().IsSubclassOf(typeof(T)))
                    {
                        return(info.component as T);
                    }
                }
            }
            return(null);
        }
Esempio n. 4
0
        private T GetSleepAsset <T>(string path) where T : Component
        {
            for (int i = 0; i < assetList.Count; i++)
            {
                PoolObjectInfo info = assetList[i];
                GameObject     go   = info.gameObject;

                if (info.component != null && !go.activeSelf && path == info.path && info.transform.parent == sleepParent)
                {
                    if (typeof(T) == info.component.GetType() || info.component.GetType().IsSubclassOf(typeof(T)))
                    {
                        return(info.component as T);
                    }
                }
            }
            return(null);
        }
Esempio n. 5
0
        public void Recover()
        {
            int leng = assetList.Count;

            for (int i = 0; i < leng; i++)
            {
                PoolObjectInfo info = assetList[i];
                if (info.gameObject != null && info.gameObject.activeInHierarchy)
                {
                    info.transform.parent = sleepParent;
                    info.gameObject.SetActive(false);
                }
                else if (info.gameObject == null)
                {
                }
            }

            RecoverEffect();
        }
Esempio n. 6
0
        private T CreateAsset <T>(T prefab, string uname, string path) where T : Component
        {
            if (prefab == null)
            {
                //ZLog.Warning("can not create asset that path = " + path + "!!!");
                return(null);
            }
            T clone             = Instantiate <T>(prefab);
            PoolObjectInfo info = new PoolObjectInfo
            {
                path       = path,
                name       = uname,
                gameObject = clone.gameObject,
                transform  = clone.transform,
                component  = clone
            };

            assetList.Add(info);
            return(clone);
        }