[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static GameObject Peek(int poolKey, TPObjectState state = TPObjectState.Auto, bool createNew = false) { #if TPObjectPoolSafeChecks if (!SafeKey(poolKey)) { return(null); } #endif var obj = pool[poolKey].Peek(state); if (obj == null && createNew) { obj = pool[poolKey].Peek(); if (obj != null) { obj = UnityEngine.Object.Instantiate(obj); obj.SetActive(state.ActiveSelf()); pool[poolKey].Push(obj); } else { Debug.LogError("You can't create new object from empty pool! Pool key: " + poolKey); } } return(obj); }
/// <summary> This checks for existing key. Returns true if is safe </summary> private static bool SafeObject(int poolKey, TPObjectState state, GameObject poolObject) { if (poolObject == null) { Debug.LogWarning("No objects with state " + state + " found. Pool key: " + poolKey); return(false); } return(true); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public void ToggleState(TPObjectState state = TPObjectState.Auto) { var popObject = Pop(state); if (popObject != null) { popObject.SetActive(!popObject.activeSelf); Push(popObject); } }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static List <GameObject> PopObjectsList(int poolKey, TPObjectState state = TPObjectState.Auto) { int length = Length(poolKey, state); List <GameObject> list = ReusableList; for (int i = 0; i < length; i++) { list.Add(PopObject(poolKey, state)); } return(list); }
internal void AddCoroutine(int poolKey, float delay, TPObjectState state, Vector3 position, Quaternion rotation, bool createNew = false, bool toggleAll = false) { AddNew(new PoolCoroutine { PoolKey = poolKey, Delay = delay, State = state, PoolObject = null, Position = position, Rotation = rotation, PushObject = true, CreateNew = createNew, ToggleAll = toggleAll, }); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActiveAll(int poolKey, TPObjectState state, Quaternion rotation) { #if TPObjectPoolSafeChecks if (!SafeKey(poolKey)) { return; } #endif int length = Length(poolKey, state); var poolObjects = PopObjectsList(poolKey, state); for (int i = 0; i < length; i++) { ToggleActive(poolKey, poolObjects[i], rotation, true); } }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public GameObject Peek(TPObjectState state = TPObjectState.Auto) { switch (state) { case TPObjectState.Deactive: return(DeactiveLength > 0 ? deactiveObjects.Peek() : null); case TPObjectState.Active: return(ActiveLength > 0 ? activeObjects.Peek() : null); case TPObjectState.Auto: var freeObj = Peek(TPObjectState.Deactive); return(freeObj ?? Peek(TPObjectState.Active)); } return(null); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActive(int poolKey, TPObjectState state, Quaternion rotation, bool createNew = false) { #if TPObjectPoolSafeChecks if (!SafeKey(poolKey)) { return; } #endif GameObject poolObject = PopObject(poolKey, state, createNew); #if TPObjectPoolSafeChecks if (!SafeObject(poolKey, state, poolObject)) { return; } #endif ToggleActive(poolKey, poolObject, rotation, true); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public GameObject Pop(TPObjectState state = TPObjectState.Auto) { if (ObjectsLength > 0) { if (state == TPObjectState.Auto) { var obj = Pop(TPObjectState.Deactive); return(obj ?? Pop(TPObjectState.Active)); } else if (state == TPObjectState.Deactive) { return(PopDeactive()); } else { return(PopActive()); } } return(null); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static int Length(int poolKey, TPObjectState state = TPObjectState.Auto) { #if TPObjectPoolSafeChecks if (!SafeKey(poolKey)) { return(0); } #endif switch (state) { case TPObjectState.Deactive: return(pool[poolKey].DeactiveLength); case TPObjectState.Active: return(pool[poolKey].ActiveLength); case TPObjectState.Auto: return(pool[poolKey].ObjectsLength); } return(0); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActiveAll(int poolKey, float delay, TPObjectState state, Quaternion rotation) { ToggleActiveAll(poolKey, delay, state, Vector3.zero, rotation); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActiveAll(int poolKey, float delay, TPObjectState state, Vector3 position) { ToggleActiveAll(poolKey, delay, state, position, Quaternion.identity); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActiveAll(int poolKey, float delay, TPObjectState state, Vector3 position, Quaternion rotation) { MonoCoroutineManager.AddCoroutine(poolKey, delay, state, position, rotation, false, true); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActive(int poolKey, float delay, TPObjectState state, Quaternion rotation, bool createNew = false) { ToggleActive(poolKey, delay, state, Vector3.zero, rotation, createNew); }
/// <summary> Converts State to GameObject activeSelf </summary> public static bool ActiveSelf(this TPObjectState state) { return(state == TPObjectState.Active ? true : false); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static async void ToggleActive(int poolKey, float delay, TPObjectState state, Vector3 position, bool createNew = false) { await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(delay)); ToggleActive(poolKey, state, position, createNew); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static async void ToggleActiveAll(int poolKey, float delay, TPObjectState state, Quaternion rotation) { await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(delay)); ToggleActiveAll(poolKey, state, rotation); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActive(int poolKey, float delay, TPObjectState state, bool createNew = false) { MonoCoroutineManager.AddCoroutine(poolKey, delay, state, Vector3.zero, Quaternion.identity, createNew); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static bool HasAnyObject(int poolKey, TPObjectState state = TPObjectState.Auto) { return(Length(poolKey, state) > 0); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActive(int poolKey, float delay, TPObjectState state, Vector3 position, Quaternion rotation, bool createNew = false) { MonoCoroutineManager.AddCoroutine(poolKey, delay, state, position, rotation, createNew); }
/// <summary> Returns true if poolObject has given state </summary> public static bool HasState(this GameObject poolObject, TPObjectState state) { return(state == GetState(poolObject) || state == TPObjectState.Auto); }
[MethodImpl((MethodImplOptions)0x100)] // agressive inline public static void ToggleActive(int poolKey, float delay, TPObjectState state, Vector3 position, bool createNew = false) { ToggleActive(poolKey, delay, state, position, Quaternion.identity, createNew); }