public Pool(string poolName, GameObject poolObjectPrefab, GameObject rootPoolObj, int initialCount, PoolInflationType type) { lastUsedTime = Time.time; if (poolObjectPrefab == null) { #if UNITY_EDITOR Debug.LogError("[ObjPoolManager] null pool object prefab !"); #endif return; } this.poolName = poolName; this.inflationType = type; this.rootObj = new GameObject(poolName + "Pool"); this.rootObj.transform.SetParent(rootPoolObj.transform, false); // In case the origin one is Destroyed, we should keep at least one GameObject go = GameObject.Instantiate(poolObjectPrefab); PoolObject po = go.GetComponent<PoolObject>(); if (po == null) { po = go.AddComponent<PoolObject>(); } po.poolName = poolName; AddObjectToPool(po); //populate the pool populatePool(Mathf.Max(initialCount, 1)); }
public Pool(string poolName, GameObject poolObjectPrefab, GameObject rootPoolObj, int initialCount, PoolInflationType type, System.Action <GameObject> handler) { if (poolObjectPrefab == null) { #if UNITY_EDITOR Debug.LogError("[ObjPoolManager] null pool object prefab !"); #endif return; } this.poolName = poolName; this.inflationType = type; this.rootObj = new GameObject(poolName + "Pool"); this.rootObj.transform.SetParent(rootPoolObj.transform, false); // In case the origin one is Destroyed, we should keep at least one GameObject go = GameObject.Instantiate(poolObjectPrefab); PoolObject po = go.GetComponent <PoolObject>(); if (po == null) { po = go.AddComponent <PoolObject>(); if (null != handler) { handler(go); } } po.poolName = poolName; AddObjectToPool(po); //populate the pool populatePool(Mathf.Max(initialCount, 1)); }
// poolObjectPrefab: 池子原始prefab对象 // poolName: 池子的名称,会创建名称为poolName+"Pool"对应的GameObject // rootPoolObj:新创建的pool的rootObj的父亲 public Pool(string poolName, GameObject poolObjectPrefab, GameObject rootPoolObj, int initialCount, PoolInflationType type) { if (poolObjectPrefab == null) { #if UNITY_EDITOR Debug.LogError("[ObjPoolManager] null pool object prefab !"); #endif return; } this.poolName = poolName; this.inflationType = type; this.rootObj = new GameObject(poolName + "Pool"); this.rootObj.transform.SetParent(rootPoolObj.transform, false); // In case the origin one is Destroyed, we should keep at least one // 为了防止池子模板丢失 // 至少会创建1个模板的实例 // 并且添加PoolObject控件 GameObject go = GameObject.Instantiate(poolObjectPrefab); PoolObject po = go.GetComponent <PoolObject>(); if (po == null) { po = go.AddComponent <PoolObject>(); } po.poolName = poolName; // 将创建出来的此实例 // 添加到池子内 AddObjectToPool(po); //populate the pool populatePool(Mathf.Max(initialCount, 1)); }
public Pool(int poolId, GameObject poolObjectPrefab, GameObject rootPoolObj, int initialCount, PoolInflationType type) { if (poolObjectPrefab == null) { #if UNITY_EDITOR Debug.LogError("[ObjPoolManager] null pool object prefab !"); #endif return; } this.poolId = poolId; this.inflationType = type; this.rootObj = new GameObject(string.Format("Pool Key: {0}-{1}", poolObjectPrefab.name, this.poolId)); this.rootObj.transform.SetParent(rootPoolObj.transform, false); this.poolName = poolObjectPrefab.name; // In case the origin one is Destroyed, we should keep at least one GameObject go = GameObject.Instantiate(poolObjectPrefab); PoolObject po = go.GetComponent <PoolObject>(); if (po == null) { po = go.AddComponent <PoolObject>(); } po.poolId = poolId; AddObjectToPool(po); //populate the pool populatePool(Mathf.Max(initialCount, 1)); }
public UIObjectPool(string poolName, GameObject poolObjectPrefab, GameObject rootPoolObj, int initialCount, PoolInflationType type) { lastUsedTime = Time.time; if (poolObjectPrefab == null) { #if UNITY_EDITOR Debug.LogError("[ObjPoolManager] null pool object prefab !"); #endif return; } this.poolName = poolName; this.inflationType = type; this.rootObj = ResourcesMgr.Instance.Instantiate(poolName + "Pool"); this.rootObj.transform.SetParent(rootPoolObj.transform, false); // In case the origin one is Destroyed, we should keep at least one GameObject go = ResourcesMgr.Instance.Instantiate(poolObjectPrefab, rootObj.transform, false); PoolObject po = go.GetAddComponent <PoolObject>(); po.poolName = poolName; AddObjectToPool(po); //populate the pool populatePool(Mathf.Max(initialCount, 1)); }
public void InitPool(GameObject prefabGO, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (prefabGO == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling : prefab is null"); return; } if (poolDict.ContainsKey(prefabGO.name)) { return; } poolDict[prefabGO.name] = new Pool(prefabGO.name, prefabGO, gameObject, size, type); }
public void InitPool(GameObject objectToPool, int size, PoolInflationType type = PoolInflationType.DOUBLE) { string poolName = objectToPool.name; if (poolDict.ContainsKey(poolName)) { return; } else { poolDict[poolName] = new Pool(poolName, objectToPool, gameObject, size, type); } }
/// <summary> /// 通过prefab初始化 /// 扩展by qingqing-zhao /// </summary> /// <param name="poolPrefab"></param> /// <param name="size"></param> /// <param name="type"></param> public void InitPool(GameObject poolPrefab, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolPrefab == null) { return; } var poolName = poolPrefab.name; if (!poolDict.ContainsKey(poolName)) { poolDict[poolName] = new Pool(poolName, poolPrefab, gameObject, size, type); } }
public void InitPool(string poolName, int size, GameObject prefab, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { if (prefab == null) { Debug.LogError("prefab is null"); return; } poolDict[poolName] = new Pool(poolName, prefab, gameObject, size, type); } }
public void InitPool(string poolName, GameObject prefab, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { if (prefab == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } poolDict[poolName] = new Pool(poolName, prefab, gameObject, size, type); } }
public void InitPool(GameObject itemTemplate, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(itemTemplate.name)) { return; } else { //GameObject pb = Resources.Load<GameObject>(poolName); //if (pb == null) //{ // Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); // return; //} poolDict[itemTemplate.name] = new Pool(itemTemplate.name, itemTemplate, gameObject, size, type); } }
public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { GameObject pb = Assets.Scripts.Framework.GalaSports.Service.ResourceManager.Load <GameObject>("module/" + poolName); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }
public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { GameObject pb = Resources.Load<GameObject>(poolName); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }
public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { GameObject pb = SG.CoreEntry.gResLoader.Load(poolName) as GameObject; if (pb == null) { LogMgr.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }
public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { GameObject pb = Resources.Load <GameObject>(poolName);//GameObject pb = AssetHelper.LoadUIPrefab_ScrollRectItem(poolName); if (pb == null) { Debug.LogError("[LsrResManager] Invalide prefab name for pooling :" + poolName); return; } poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }
public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { GameObject pb = Resources.Load <GameObject>(poolName); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } // poolName.Remove(0, UnityEngine.UI.LoopScrollPrefabSource._PrefabPath.Length) poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }
public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { // GameObject pb = Resources.Load<GameObject>(poolName); GameObject pb = Resources.Load(path + poolName) as GameObject; if (pb == null) { VKDebug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }
public void InitPool(string poolName, int size, GameObject prefab, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { // GameObject pb = Resources.Load<GameObject>(poolName); if (prefab == null) { Debug.LogError("[ResourceManager] Received a null prefab for pool!"); return; } poolDict[poolName] = new Pool(poolName, prefab, gameObject, size, type); } }
public void InitPool(UnityEngine.UI.LoopScrollPrefabSource source, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(source.prefabName)) { return; } else { //GameObject pb = Resources.Load<GameObject>(poolName); GameObject pb = GameObject.Instantiate(source.itemprefab); pb.gameObject.SetActive(false); pb.gameObject.SetActive(true); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + source.prefabName); return; } poolDict[source.prefabName] = new Pool(source.prefabName, pb, gameObject, source.poolSize, type); } }
public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { string stackInfo = new System.Diagnostics.StackTrace().ToString(); Debug.Log(stackInfo); if (poolDict.ContainsKey(poolName)) { return; } else { GameObject pb = Resources.Load <GameObject>(poolName); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }
public void InitPool(GameObject prefab, int size, PoolInflationType type = PoolInflationType.DOUBLE) { int key = prefab.GetInstanceID(); if (poolDict.ContainsKey(key)) { return; } else { GameObject pb = Instantiate(prefab); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + prefab.name); return; } poolDict[key] = new Pool(key, pb, gameObject, size, type); } }
public void InitPool(string bname, string prefabName, string localPath, int size, System.Action <GameObject> handler, PoolInflationType type = PoolInflationType.DOUBLE) { string poolName = bname + prefabName; if (poolDict.ContainsKey(poolName)) { return; } else { GameObject pb = null;// ResManager.GetInstance().LoadAsset<GameObject>(bname, prefabName, localPath); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + bname + "/" + prefabName); return; } handlers[poolName] = handler; poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type, handler); } }
// poolName:池子名称,同时也是要缓存的go的名称 // 新建的pool,会挂载在自己的下面 public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE) { if (poolDict.ContainsKey(poolName)) { return; } else { // 加载要缓存的go模板 GameObject pb = Resources.Load <GameObject>(poolName); if (pb == null) { Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName); return; } // 参数顺序; // poolName // poolObjectPrefab // rootPoolObj // initialCount // type poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type); } }