/// <summary> /// 从缓存池里面获得GameObject,并且从缓存池里面去除,返回的Gameobject.active = false /// </summary>resPath 资源路径,也是缓存池名称 /// <param name="poolName">资源路径</param> CSObjectPoolItem GetPoolItem(string resName, string resPath, EPoolType poolType, int poolNum = 0, bool isForever = false) { CSObjectPoolBase pool = null; string poolName = resPath; if (mDic.ContainsKey(poolName)) { pool = mDic[poolName]; } else { if (poolNum == 0) { return(null); } CSStringBuilder.Clear(); GameObject poolGO = new GameObject(); Transform trans = poolGO.transform; trans.parent = transform; if (poolType == EPoolType.Normal) { pool = poolGO.AddComponent <CSObjectPoolNormal>(); CSStringBuilder.Append("Normal Pool->", resName); poolGO.name = CSStringBuilder.ToString(); } else if (poolType == EPoolType.Resource) { pool = poolGO.AddComponent <CSObjectPoolAtlas>(); CSStringBuilder.Append("Atlas Pool->", resName); poolGO.name = CSStringBuilder.ToString(); } pool.resName = resName; //pool.resType = resType; pool.Init(this); mDic.Add(poolName, pool); mList.Add(pool); } pool.poolNum = poolNum; pool.poolName = poolName; pool.isForever = isForever; return(pool.GetGOFromPool()); }
public static object GetIndex(UnityEngine.Object waitFree, EPoolType type = EPoolType.None) { if (m_instance.m_idPool.ContainsKey(type)) { foreach (var item in m_instance.m_idPool[type]) { if (waitFree.name.Contains(item.Value.obj.name)) { return(item.Key); } } lhDebug.LogWarning("LaoHan: pool is nont has waitFree: " + type + " " + waitFree); return(null); } else { lhDebug.LogWarning("LaoHan: pool is nont has this type: " + type); return(null); } }
public static object GetSource(object index, EPoolType type) { if (m_instance.m_idPool.ContainsKey(type)) { var dic = m_instance.m_idPool[type]; if (dic.ContainsKey(index)) { return(dic[index].obj); } else { lhDebug.LogWarning("LaoHan: pool is nont has index: " + index); return(null); } } else { lhDebug.LogWarning("LaoHan: pool is nont has this type: " + type); return(null); } }
public Letter getGridLetterFromPool(EPoolType poolType) { Letter result = null; switch (poolType) { case EPoolType.NORMAL: result = createGridLetter(lettersPool.getNextRandomized()); break; case EPoolType.OBSTACLE: result = createGridLetter(obstaclesLettersPool.getNextRandomized()); break; case EPoolType.TUTORIAL: result = createGridLetter(tutorialLettersPool.getNextRandomized()); break; } return(result); }
public GameObject GetFromPool(EPoolType a_Type, Vector3 a_Pos) { if (m_Pool.ContainsKey(a_Type)) { if (m_Pool[a_Type].Count > 0) { GameObject go = m_Pool[a_Type][0]; m_Pool[a_Type].Remove(go); go.transform.position = a_Pos; go.SetActive(true); if (Camera.main.GetComponent <CameraFollow>()) { Camera.main.GetComponent <CameraFollow>().m_ToFollow = go.transform; } go.GetComponent <PlayerController>().m_OnLifeLost += m_OnLifeLost; return(go); } } Debug.LogError("No More: " + a_Type + " in pool. PLEASE ADD MORE"); return(null); }
/// <summary> /// 从缓存池里面获得GameObject,并且从缓存池里面去除,返回的Gameobject.active = false /// </summary>resPath 资源路径,也是缓存池名称 /// <param name="poolName">资源路径</param> private CSObjectPoolItem GetPoolItem(string resName, string resPath, EPoolType poolType, int poolNum = 0, bool isForever = false) { CSObjectPoolBase pool = null; string poolName = resPath; if (mDic.TryGetValue(poolName, out pool) && pool != null) { pool = mDic[poolName]; } else { if (poolNum == 0) { return(null); } CSStringBuilder.Clear(); GameObject poolGO = new GameObject(); Transform trans = poolGO.transform; trans.parent = transform; if (poolType == EPoolType.Normal) { pool = poolGO.AddComponent <CSObjectPoolNormal>(); CSStringBuilder.Append("Normal Pool->", resName); poolGO.name = CSStringBuilder.ToString(); } pool.resName = resName; //pool.resType = resType; pool.Init(); mDic[poolName] = pool; pool.transform.localScale = Vector3.zero; //mDic.Add(poolName, pool); mList.Add(pool); } pool.poolNum = poolNum; pool.poolName = poolName; pool.isForever = isForever; return(pool.GetGOFromPool()); }
public static void Clear(object index, EPoolType type) { if (m_instance.m_idPool.ContainsKey(type)) { var dic = m_instance.m_idPool[type]; if (dic.ContainsKey(index)) { dic[index].Clear(); dic.Remove(index); } else { lhDebug.LogWarning("LaoHan: pool is nont has this id: " + type + " " + index); return; } } else { lhDebug.LogWarning("LaoHan: pool is nont has this type: " + type); return; } }
public static UnityEngine.Object GetObject(object index, EPoolType type = EPoolType.None) { if (m_instance.m_idPool.ContainsKey(type)) { var dic = m_instance.m_idPool[type]; if (dic.ContainsKey(index)) { var o = dic[index].GetObject(); return(o); } else { if (index is GameObject) { GameObject obj = index as GameObject; var pool = new ObjectPool(); pool.index = index; pool.obj = obj; pool.poolType = type; m_instance.m_idPool[type].Add(index, pool); var o = pool.GetObject(); return(o); } else { lhDebug.LogError((object)("LaoHan: pool dont has this id: " + type + " " + index)); return(null); } } } else { lhDebug.LogError((object)("LaoHan: pool dont has this type: " + type)); return(null); } }
public static void FreeObject(UnityEngine.Object waitFree, float freeTime = -1, EPoolType type = EPoolType.None, bool backParent = true, Action onFreeOver = null) { if (waitFree == null) { return; } var index = GetIndex(waitFree, type); if (index == null) { lhDebug.LogWarning("LaoHan: waitFree dont store: " + waitFree + " " + type); return; } FreeObject(index, waitFree, freeTime, type, backParent, onFreeOver); }
public static void FreeObject(object index, UnityEngine.Object waitFree, float freeTime = -1, EPoolType type = EPoolType.None, bool backParent = true, Action onFreeOver = null) { if (m_instance.m_idPool.ContainsKey(type)) { var dic = m_instance.m_idPool[type]; if (dic.ContainsKey(index)) { if (waitFree != null && !dic[index].Contains(waitFree)) { Action FreeObj = () => { dic[index].FreeObject(waitFree, backParent); if (onFreeOver != null) { onFreeOver(); } }; if (freeTime > 0) { lhInvoke.Invoke(FreeObj, freeTime); } else { FreeObj(); } } } else { lhDebug.LogWarning("LaoHan: pool is nont has this id: " + type + " " + index); return; } } else { lhDebug.LogWarning("LaoHan: pool is nont has this type: " + type); return; } }
public static UnityEngine.Object GetObject(object index, Vector3 position, Quaternion rotation, Transform parent = null, bool activate = true, EPoolType type = EPoolType.None) { UnityEngine.Object obje = GetObject(index, type); if (obje is GameObject) { ((GameObject)obje).transform.SetParent(parent); ((GameObject)obje).transform.localPosition = position; ((GameObject)obje).transform.localRotation = rotation; ((GameObject)obje).SetActive(activate); } else { lhDebug.LogError((object)"obj is dont GameObject and ScriptObject"); } return(obje); }
public static void Store(object index, UnityEngine.Object obj, int count, Action <Object> onCreateHandler = null, Action onStoreOver = null, EPoolType type = EPoolType.None) { if (m_instance.m_idPool.ContainsKey(type)) { if (m_instance.m_idPool[type].ContainsKey(index)) { if (onStoreOver != null) { onStoreOver(); } //m_instance.m_idPool[type][index].Store(count, onCreateHandler, onStoreOver); } else { var pool = new ObjectPool(); pool.index = index; pool.obj = obj; obj.hideFlags = HideFlags.HideInHierarchy; pool.poolType = type; m_instance.m_idPool[type].Add(index, pool); pool.Store(count, onCreateHandler, onStoreOver); } } else { var dic = new Dictionary <object, ObjectPool>(); var pool = new ObjectPool(); pool.index = index; pool.obj = obj; obj.hideFlags = HideFlags.HideInHierarchy; pool.poolType = type; dic.Add(index, pool); m_instance.m_idPool.Add(type, dic); pool.Store(count, onCreateHandler, onStoreOver); } }
public static void Store(object index, string path, int count = 1, Action <Object> OnCreateHandler = null, Action onStoreOver = null, EPoolType type = EPoolType.None) { if (m_instance.m_idPool.ContainsKey(type)) { if (m_instance.m_idPool[type].ContainsKey(index)) { if (m_instance.m_idPool[type][index].obj == null) { m_instance.m_idPool[type][index].storeOverHandler += onStoreOver; } else { if (onStoreOver != null) { onStoreOver(); } } //m_instance.m_idPool[type][index].Store(count, OnCreateHandler, onStoreOver); } else { var pool = new ObjectPool(); pool.index = index; pool.path = path; pool.poolType = type; m_instance.m_idPool[type].Add(index, pool); pool.Store(count, OnCreateHandler, onStoreOver); } } else { var dic = new Dictionary <object, ObjectPool>(); var pool = new ObjectPool(); pool.index = index; pool.path = path; pool.poolType = type; dic.Add(index, pool); m_instance.m_idPool.Add(type, dic); pool.Store(count, OnCreateHandler, onStoreOver); } }
protected GameObject lhInstantiate(GameObject obj, Vector3 position, Quaternion rotation, bool objectPool = false, Transform parent = null, bool activate = true, EPoolType pool = EPoolType.None) { if (objectPool) { return((GameObject)lhObjectManager.GetObject(obj, position, rotation)); } else { return(Instantiate(obj, position, rotation) as GameObject); } }
public void Commit(CCommandList cmd, Graphics.CGfxCamera camera, GamePlay.SceneGraph.CheckVisibleParam param, EPoolType poolType) { switch (poolType) { case EPoolType.Normal: { using (var i = Meshes.Values.GetEnumerator()) { while (i.MoveNext()) { if (i.Current.CurSize == 0) { continue; } i.Current.MeshComp.CommitVisual(cmd, camera, param); i.Current.Flush2VB(cmd); } } } break; case EPoolType.Shadow: { using (var i = ShadowMeshes.Values.GetEnumerator()) { while (i.MoveNext()) { if (i.Current.CurSize == 0) { continue; } i.Current.MeshComp.CommitVisual(cmd, camera, param); i.Current.Flush2VB(cmd); } } } break; } }
//实测,在android上,性能分析工具调用本身开心就很大 //public static Profiler.TimeScope ScopeFind = Profiler.TimeScopeManager.GetTimeScope(typeof(GInstancingManager), "PushInstance.Find", Profiler.TimeScope.EProfileFlag.Windows); //public static Profiler.TimeScope ScopePush = Profiler.TimeScopeManager.GetTimeScope(typeof(GInstancingManager), "PushInstance.Push", Profiler.TimeScope.EProfileFlag.Windows); public void PushInstance(GInstancingComponent inst, int lightNum, ref UInt32_4 lightIndices, Graphics.Mesh.CGfxMesh oriMesh, EPoolType poolType) { var meshComp = inst.HostContainer as GMeshComponent; if (meshComp == null) { return; } //ScopeFind.Begin(); if (oriMesh.mInstancePool == null || oriMesh.mShadowInstancePool == null) { oriMesh.mInstancePool = new GInstancing(); Meshes[oriMesh.Name] = oriMesh.mInstancePool; var task = oriMesh.mInstancePool.Init(oriMesh.Name, false); oriMesh.mShadowInstancePool = new GInstancing(); ShadowMeshes[oriMesh.Name] = oriMesh.mShadowInstancePool; var task1 = oriMesh.mShadowInstancePool.Init(oriMesh.Name, true); } GInstancing instType = null; switch (poolType) { case EPoolType.Normal: instType = oriMesh.mInstancePool; break; case EPoolType.Shadow: instType = oriMesh.mShadowInstancePool; break; } //ScopeFind.End(); //ScopePush.Begin(); instType.PushInstance(ref meshComp.Placement.mDrawPosition, ref meshComp.Placement.mDrawScale, ref meshComp.Placement.mDrawRotation, ref lightIndices, lightNum); //ScopePush.End(); }