Ejemplo n.º 1
0
        [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);
        }
Ejemplo n.º 2
0
 /// <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);
 }
Ejemplo n.º 3
0
        [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);
            }
        }
Ejemplo n.º 4
0
        [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);
        }
Ejemplo n.º 5
0
 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,
     });
 }
Ejemplo n.º 6
0
        [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);
            }
        }
Ejemplo n.º 7
0
        [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);
        }
Ejemplo n.º 8
0
        [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);
        }
Ejemplo n.º 9
0
 [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);
 }
Ejemplo n.º 10
0
        [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);
        }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
0
 [MethodImpl((MethodImplOptions)0x100)] // agressive inline
 public static void ToggleActiveAll(int poolKey, float delay, TPObjectState state, Vector3 position)
 {
     ToggleActiveAll(poolKey, delay, state, position, Quaternion.identity);
 }
Ejemplo n.º 13
0
 [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);
 }
Ejemplo n.º 14
0
 [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);
 }
Ejemplo n.º 15
0
 /// <summary> Converts State to GameObject activeSelf </summary>
 public static bool ActiveSelf(this TPObjectState state)
 {
     return(state == TPObjectState.Active ? true : false);
 }
Ejemplo n.º 16
0
        [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);
        }
Ejemplo n.º 17
0
        [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);
        }
Ejemplo n.º 18
0
 [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);
 }
Ejemplo n.º 19
0
 [MethodImpl((MethodImplOptions)0x100)] // agressive inline
 public static bool HasAnyObject(int poolKey, TPObjectState state = TPObjectState.Auto)
 {
     return(Length(poolKey, state) > 0);
 }
Ejemplo n.º 20
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);
 }
Ejemplo n.º 21
0
 /// <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);
 }
Ejemplo n.º 22
0
 [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);
 }