public void Alloc(GameObject prefab, int capacity, CreateFunction create, ResetFunction reset = null, DestroyFunction destroy = null) { BaseObjectPool <GameObject> .CreateFunction baseCreate = delegate(GameObject type) { return(create(type)); }; BaseObjectPool <GameObject> .ResetFunction baseReset; if (reset != null) { baseReset = delegate(object obj) { reset((GameObject)obj); }; } else { baseReset = null; } BaseObjectPool <GameObject> .DestroyFunction baseDestroy; if (destroy != null) { baseDestroy = delegate(object obj) { destroy((GameObject)obj); }; } else { baseDestroy = null; } Alloc(prefab, capacity, baseCreate, baseReset, baseDestroy); }
public void Alloc(int capacity, CreateFunction create, ResetFunction reset = null, DestroyFunction destroy = null) { BaseObjectPool <System.Type> .CreateFunction baseCreate = delegate(System.Type type) { return(create()); }; BaseObjectPool <System.Type> .ResetFunction baseReset; if (reset != null) { baseReset = delegate(object obj) { reset((TYPE)obj); }; } else { baseReset = null; } BaseObjectPool <System.Type> .DestroyFunction baseDestroy; if (destroy != null) { baseDestroy = delegate(object obj) { destroy((TYPE)obj); }; } else { baseDestroy = null; } Alloc(typeof(TYPE), capacity, baseCreate, baseReset, baseDestroy); m_subPool = m_pool[typeof(TYPE)]; }
private void DrawObjectPool(BaseObjectPool Pool) { GUILayout.Label($"<b>Object Pool: {Pool.PoolName}</b>"); GUILayout.BeginVertical(GUI.skin.box); { GUILayout.Label("<i>Object Pool is Empty ...</i>"); } GUILayout.EndVertical(); }
//TODO: what should happen on failure public bool Remove(IntPtr entityPointer) { if (!entities.TryRemove(entityPointer, out var entity) || !entity.Exists) { return(false); } BaseObjectPool <TEntity> .SetEntityNoLongerExists(entity); return(true); }
private void InitBaseObjectPoolDic() { m_BaseObjectPoolDic = new Dictionary <int, BaseObjectPool>(); var keys = PartIDConfig.GetKeys(); foreach (var key in keys) { int id = PartIDConfig.Get(key).value; BaseObjectPool pool = new BaseObjectPool(id, key, GloblConfig.MAX_POOL_COUNT); m_BaseObjectPoolDic[id] = pool; } }
private void DrawObjectPool(BaseObjectPool objectPool) { string fullName = TextHelper.GetFullName(objectPool.ObjectType, objectPool.Name); bool lastState = m_OpenedItems.Contains(fullName); bool currentState = EditorGUILayout.Foldout(lastState, string.IsNullOrEmpty(objectPool.Name) ? "<Unnamed>" : objectPool.Name); if (currentState != lastState) { if (currentState) { m_OpenedItems.Add(fullName); } else { m_OpenedItems.Remove(fullName); } } if (currentState) { EditorGUILayout.BeginVertical("box"); { EditorGUILayout.LabelField("Type", objectPool.ObjectType.FullName); EditorGUILayout.LabelField("Auto Release Interval", objectPool.AutoReleaseInterval.ToString()); EditorGUILayout.LabelField("Capacity", string.Format("{0} / {1} / {2}", objectPool.CanReleaseCount.ToString(), objectPool.Count.ToString(), objectPool.Capacity.ToString())); EditorGUILayout.LabelField("Expire Time", objectPool.ExpireTime.ToString()); EditorGUILayout.LabelField("Priority", objectPool.Priority.ToString()); ObjectInfo[] objectInfos = objectPool.GetAllObjectInfos(); if (objectInfos.Length > 0) { foreach (ObjectInfo objectInfo in objectInfos) { EditorGUILayout.LabelField(objectInfo.Name, string.Format("{0}, {1}, {2}, {3}", objectInfo.Locked.ToString(), objectPool.AllowMultiSpawn ? objectInfo.SpawnCount.ToString() : objectInfo.IsInUse.ToString(), objectInfo.Priority.ToString(), objectInfo.LastUseTime.ToString("yyyy-MM-dd HH:mm:ss"))); } } else { GUILayout.Label("Object Pool is Empty ..."); } } EditorGUILayout.EndVertical(); EditorGUILayout.Separator(); } }
private void DrawObjectPool(BaseObjectPool Pool) { GUILayout.Label($"<b>Object Pool: {Pool.PoolName}</b>"); GUILayout.BeginVertical(GUI.skin.box); { var Caches = Pool.GetObjectCacheList(); DrawItem("Type", Pool.ObjectType.FullName); DrawItem("Capacity", Pool.Capacity.ToString()); DrawItem("Used Count", Pool.UsedCount.ToString()); DrawItem("Idle Count", Pool.IdleCount.ToString()); GUILayout.BeginHorizontal(); { GUILayout.Label("<b>Is Used</b>", GUILayout.Width(80f)); GUILayout.Label("<b>Use Count</b>", GUILayout.Width(80f)); GUILayout.Label("<b>Use Time</b>", GUILayout.Width(80f)); GUILayout.Label("<b>Last Spawn Time</b>", GUILayout.Width(120f)); GUILayout.Label("<b>Last Recycle Time</b>", GUILayout.Width(120f)); } GUILayout.EndHorizontal(); if (Caches.Length > 0) { foreach (var Cache in Caches) { GUILayout.BeginHorizontal(); { GUILayout.Label(Cache.Used.ToString(), GUILayout.Width(80f)); GUILayout.Label(Cache.Count.ToString(), GUILayout.Width(80f)); GUILayout.Label(Cache.TotalTime.ToString(), GUILayout.Width(80)); GUILayout.Label(Cache.LastSpawnTime.ToString("yyyy-MM-dd HH:mm:ss"), GUILayout.Width(120f)); GUILayout.Label(Cache.LastRecycleTime.ToString("yyyy-MM-dd HH:mm:ss"), GUILayout.Width(120f)); } GUILayout.EndHorizontal(); } } else { GUILayout.Label("<i>Object Pool is Empty ...</i>"); } } GUILayout.EndVertical(); }