Example #1
0
 private void OnDestroy()
 {
     _instance           = null;
     this._onStatRefresh = null;
 }
Example #2
0
    public void RefreshPoolContainer(string prefabName, int count = 1, string objName = "0")
    {
        if (string.IsNullOrEmpty(prefabName))
        {
            return;
        }

        this.count = count;
        if (count > 0 && poolObjectList.Count == count)
        {
            if (GameObjectPool.INSTANCE.IsSamePrefab(poolObjectList[0], prefabName))
            {
                if (objName != "0" && objName != poolObjectName)
                {
                    poolObjectName = objName;
                    if (count == 1 && !forceNameItem)
                    {
                        poolObjectList[0].name = string.IsNullOrEmpty(poolObjectName) ? Path.GetFileName(prefabName) : poolObjectName;
                        OnPoolRefresh(prefabName, 0);
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            poolObjectList[i].name = string.IsNullOrEmpty(poolObjectName) ? string.Format("item_{0}", i + 1) : string.Format("{0}_{1}", poolObjectName, i + 1);
                            OnPoolRefresh(prefabName, i);
                        }
                    }
                }
                return;
            }
        }

        if (poolObjectList.Count != 0)
        {
            int objectCount = poolObjectList.Count;
            for (int i = objectCount - 1; i >= 0; i--)
            {
                GameObjectPool.INSTANCE.Release(poolObjectList[i].gameObject);
            }
            poolObjectList.Clear();
        }

        for (int i = 0; i < count; i++)
        {
            GamePerf.Begin("GOPC_Requset_" + prefabName);
            var poolObject = GameObjectPool.INSTANCE.Request(prefabName, true);
            GamePerf.End();
            poolObjectName = objName == "0" ? poolObjectName : objName;
            if (poolObject != null)
            {
                if (count == 1 && !forceNameItem)
                {
                    poolObject.name = string.IsNullOrEmpty(poolObjectName) ? Path.GetFileName(prefabName) : poolObjectName;
                }
                else
                {
                    poolObject.name = string.IsNullOrEmpty(poolObjectName) ? string.Format("item_{0}", i + 1) : string.Format("{0}_{1}", poolObjectName, i + 1);
                }
                GamePerf.Begin("GOPC_SetParent_" + prefabName);
                poolObject.transform.SetParent(this.transform, false);
                poolObject.poolContainer = this;
                OnPoolRefresh(prefabName, i);
                GamePerf.End();
                poolObjectList.Add(poolObject);
            }
        }
    }
Example #3
0
 private void Awake()
 {
     _instance = this;
     GameObject.DontDestroyOnLoad(this.gameObject);
 }