private PoolableObject Extract() { PoolableObject po = null; po = unusedObjects.First.Value; unusedObjects.RemoveFirst(); po.node = usedObjects.AddFirst(po); #if UNITY_EDITOR RefreshName(); #endif return(po); }
public void EnablePoolableObject(PoolableObject poolable) { GameObject go = poolable.gameObject; if (go == null) { return; } if (!go.activeSelf) { go.SetActive(true); } go.transform.ResetLocalTRS(); lastGetTime = Time.unscaledTime; }
public void RemoveFromPool(PoolableObject poolable) { if (poolable.node != null) { if (poolable.node.List != null) { poolable.node.List.Remove(poolable); } poolable.node = null; } PoolManager.i.poolables.Remove(poolable.gameObject); PoolManager.i.poolableValues.Remove(poolable); #if UNITY_EDITOR RefreshName(); #endif }
/// <summary> /// This will add a gameObject that is not on any pool to this pool. /// </summary> /// <param name="gameObject"></param> public void AddToPool(GameObject gameObject, bool addActive = true) { if (instantiator != null && !instantiator.IsValid(gameObject)) { Debug.LogError($"ERROR: Trying to add invalid gameObject to pool! -- {gameObject.name}", gameObject); return; } PoolableObject obj = PoolManager.i.GetPoolable(gameObject); if (obj != null) { Debug.LogError($"ERROR: gameObject is already being tracked by a pool! -- {gameObject.name}", gameObject); return; } SetupPoolableObject(gameObject, addActive); }
public ItemType CreateItemFromId <ItemType>(CLASS_ID_COMPONENT id) where ItemType : BaseComponent { EnsureFactoryDictionary(); if (!factoryDict.ContainsKey(id)) { #if UNITY_EDITOR Debug.LogError("Class " + id + " can't be instantiated because the field doesn't exist!"); #endif return(default(ItemType)); } var factoryItem = factoryDict[id]; if (factoryItem.prefab == null) { Debug.LogError("Prefab for class " + id + " is null!"); return(default(ItemType)); } GameObject instancedGo; PoolableObject poolableObject = null; if (factoryItem.usePool) { EnsurePoolForItem(factoryItem); poolableObject = GetPoolForItem(factoryItem).Get(); instancedGo = poolableObject.gameObject; } else { instancedGo = Instantiate(factoryItem.prefab.gameObject); } ItemType item = instancedGo.GetComponent <ItemType>(); item.poolableObject = poolableObject; return(item); }
public void Release(PoolableObject poolable) { #if UNITY_EDITOR if (isQuitting) { return; } #endif if (poolable == null || !PoolManager.i.HasPoolable(poolable)) { return; } DisablePoolableObject(poolable); poolable.node.List.Remove(poolable.node); poolable.node = unusedObjects.AddFirst(poolable); #if UNITY_EDITOR RefreshName(); #endif }
private void MapRenderer_OnUserInfoUpdated(MinimapMetadata.MinimapUserInfo userInfo) { if (usersInfo.TryGetValue(userInfo.userId, out MinimapMetadata.MinimapUserInfo existingUserInfo)) { existingUserInfo = userInfo; if (usersInfoMarkers.TryGetValue(userInfo.userId, out PoolableObject go)) { ConfigureUserIcon(go.gameObject, userInfo.worldPosition, userInfo.userName); } } else { usersInfo.Add(userInfo.userId, userInfo); PoolableObject newUserIcon = usersInfoPool.Get(); newUserIcon.gameObject.name = string.Format("UserIcon-{0}", userInfo.userName); newUserIcon.gameObject.transform.parent = overlayContainer.transform; newUserIcon.gameObject.transform.localScale = Vector3.one; ConfigureUserIcon(newUserIcon.gameObject, userInfo.worldPosition, userInfo.userName); usersInfoMarkers.Add(userInfo.userId, newUserIcon); } }
public PoolableObject Get() { if (PoolManager.i.initializing) { int count = usedObjectsCount; for (int i = unusedObjectsCount; i < Mathf.Min(count * PREWARM_ACTIVE_MULTIPLIER, maxPrewarmCount); i++) { Instantiate(); } Instantiate(); } else if (unusedObjects.Count == 0) { Instantiate(); } PoolableObject poolable = Extract(); EnablePoolableObject(poolable); return(poolable); }
public bool HasPoolable(PoolableObject poolable) { //NOTE(Brian): The only poolableValues use is this. Using ContainsValue in a Dictionary is slow as hell. return(poolableValues.Contains(poolable)); }