Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. public static GameObject orig_Spawn(GameObject prefab, Transform parent, Vector3 position, Quaternion rotation)
  2.     {
  3.         bool flag = prefab.GetComponent<ActiveRecycler>() != null;
  4.         List<GameObject> list;
  5.         if (ObjectPool.instance.pooledObjects.TryGetValue(prefab, ref list))
  6.         {
  7.             GameObject gameObject = null;
  8.             Transform transform;
  9.             if (list.Count > 0)
  10.             {
  11.                 while (gameObject == null && list.Count > 0)
  12.                 {
  13.                     gameObject = list[0];
  14.                     list.RemoveAt(0);
  15.                 }
  16.                 if (gameObject != null)
  17.                 {
  18.                     transform = gameObject.transform;
  19.                     transform.parent = parent;
  20.                     transform.localPosition = position;
  21.                     transform.localRotation = rotation;
  22.                     if (flag)
  23.                     {
  24.                         FSMUtility.SendEventToGameObject(gameObject, "A SPAWN");
  25.                     }
  26.                     else
  27.                     {
  28.                         gameObject.SetActive(true);
  29.                     }
  30.                     ObjectPool.instance.spawnedObjects.Add(gameObject, prefab);
  31.                     return gameObject;
  32.                 }
  33.             }
  34.             Debug.LogWarningFormat("Object Pool attached to {0} has run out of {1} prefabs, Instantiating an additional one.", new object[]
  35.             {
  36.                 ObjectPool.instance.name,
  37.                 prefab.name
  38.             });
  39.             gameObject = Object.Instantiate<GameObject>(prefab);
  40.             transform = gameObject.transform;
  41.             transform.parent = parent;
  42.             transform.localPosition = position;
  43.             transform.localRotation = rotation;
  44.             if (flag)
  45.             {
  46.                 FSMUtility.SendEventToGameObject(gameObject, "A SPAWN");
  47.             }
  48.             ObjectPool.instance.spawnedObjects.Add(gameObject, prefab);
  49.             return gameObject;
  50.         }
  51.         if (prefab == null)
  52.         {
  53.             Debug.LogErrorFormat("Object Pool attached to {0} was asked for a NULL prefab.", new object[]
  54.             {
  55.                 ObjectPool.instance.name
  56.             });
  57.             return null;
  58.         }
  59.         Debug.LogWarningFormat("Object Pool attached to {0} could not find a copy of {1}, Instantiating a new one.", new object[]
  60.         {
  61.             ObjectPool.instance.name,
  62.             prefab.name
  63.         });
  64.         ObjectPool.CreatePool(prefab.gameObject, 1);
  65.         return ObjectPool.Spawn(prefab);
  66.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement