Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static GameObject orig_Spawn(GameObject prefab, Transform parent, Vector3 position, Quaternion rotation)
- {
- bool flag = prefab.GetComponent<ActiveRecycler>() != null;
- List<GameObject> list;
- if (ObjectPool.instance.pooledObjects.TryGetValue(prefab, ref list))
- {
- GameObject gameObject = null;
- Transform transform;
- if (list.Count > 0)
- {
- while (gameObject == null && list.Count > 0)
- {
- gameObject = list[0];
- list.RemoveAt(0);
- }
- if (gameObject != null)
- {
- transform = gameObject.transform;
- transform.parent = parent;
- transform.localPosition = position;
- transform.localRotation = rotation;
- if (flag)
- {
- FSMUtility.SendEventToGameObject(gameObject, "A SPAWN");
- }
- else
- {
- gameObject.SetActive(true);
- }
- ObjectPool.instance.spawnedObjects.Add(gameObject, prefab);
- return gameObject;
- }
- }
- Debug.LogWarningFormat("Object Pool attached to {0} has run out of {1} prefabs, Instantiating an additional one.", new object[]
- {
- ObjectPool.instance.name,
- prefab.name
- });
- gameObject = Object.Instantiate<GameObject>(prefab);
- transform = gameObject.transform;
- transform.parent = parent;
- transform.localPosition = position;
- transform.localRotation = rotation;
- if (flag)
- {
- FSMUtility.SendEventToGameObject(gameObject, "A SPAWN");
- }
- ObjectPool.instance.spawnedObjects.Add(gameObject, prefab);
- return gameObject;
- }
- if (prefab == null)
- {
- Debug.LogErrorFormat("Object Pool attached to {0} was asked for a NULL prefab.", new object[]
- {
- ObjectPool.instance.name
- });
- return null;
- }
- Debug.LogWarningFormat("Object Pool attached to {0} could not find a copy of {1}, Instantiating a new one.", new object[]
- {
- ObjectPool.instance.name,
- prefab.name
- });
- ObjectPool.CreatePool(prefab.gameObject, 1);
- return ObjectPool.Spawn(prefab);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement