Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ObjectPool : MonoBehaviour
  5. {
  6.  
  7. private GameObject prefab;
  8. public GameObject prefabType1;
  9. public int objectNumType1;
  10.  
  11. static private Stack StackObjType1Tmp = new Stack();
  12. static private Stack StackObjType1 = Stack.Synchronized(StackObjType1Tmp);
  13.  
  14.  
  15.  
  16. void Awake()
  17. {
  18.  
  19. int typeNum = 0;
  20. Stack StackObjTmp;
  21.  
  22.  
  23.  
  24. typeNum = objectNumType1;
  25. prefab = prefabType1;
  26. StackObjTmp = StackObjType1;
  27.  
  28. for (int j = 0; j < typeNum; j++)
  29. {
  30.  
  31. GameObject gameObjectTmp = MonoBehaviour.Instantiate(prefab) as GameObject;
  32. gameObjectTmp.SetActive(false);
  33. StackObjType1.Push(gameObjectTmp);
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40. }
  41.  
  42. static public GameObject InstantiatePrefab(Vector3 position, Quaternion rotation)
  43. {
  44.  
  45. GameObject obj = null;
  46.  
  47. obj = (GameObject)StackObjType1.Pop();
  48.  
  49. obj.transform.position = position;
  50. obj.transform.rotation = rotation;
  51.  
  52. // Set the object to be active
  53. obj.SetActive(true);
  54.  
  55. return obj;
  56. }
  57.  
  58. static public void Destroy(GameObject objectToDestroy)
  59. {
  60. //Debug.Log("MyClass : param = " + param1 + ", " + param2);
  61.  
  62. objectToDestroy.SetActive(false);
  63. StackObjType1.Push(objectToDestroy);
  64.  
  65.  
  66. }
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement