DetonatorTest.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using UnityEngine;
  3. public class DetonatorTest : MonoBehaviour
  4. {
  5. private void Start()
  6. {
  7. this.SpawnWall();
  8. if (!this.currentDetonator)
  9. {
  10. this.NextExplosion();
  11. }
  12. else
  13. {
  14. this._currentExpIdx = 0;
  15. }
  16. }
  17. private void OnGUI()
  18. {
  19. this._guiRect = new Rect(7f, (float)(Screen.height - 180), 250f, 200f);
  20. GUILayout.BeginArea(this._guiRect);
  21. GUILayout.BeginVertical(new GUILayoutOption[0]);
  22. string name = this.currentDetonator.name;
  23. if (GUILayout.Button(name + " (Click For Next)", new GUILayoutOption[0]))
  24. {
  25. this.NextExplosion();
  26. }
  27. if (GUILayout.Button("Rebuild Wall", new GUILayoutOption[0]))
  28. {
  29. this.SpawnWall();
  30. }
  31. if (GUILayout.Button("Camera Far", new GUILayoutOption[0]))
  32. {
  33. Camera.main.transform.position = new Vector3(0f, 0f, -7f);
  34. Camera.main.transform.eulerAngles = new Vector3(13.5f, 0f, 0f);
  35. }
  36. if (GUILayout.Button("Camera Near", new GUILayoutOption[0]))
  37. {
  38. Camera.main.transform.position = new Vector3(0f, -8.664466f, 31.38269f);
  39. Camera.main.transform.eulerAngles = new Vector3(1.213462f, 0f, 0f);
  40. }
  41. GUILayout.Label("Time Scale", new GUILayoutOption[0]);
  42. this.timeScale = GUILayout.HorizontalSlider(this.timeScale, 0f, 1f, new GUILayoutOption[0]);
  43. GUILayout.Label("Detail Level (re-explode after change)", new GUILayoutOption[0]);
  44. this.detailLevel = GUILayout.HorizontalSlider(this.detailLevel, 0f, 1f, new GUILayoutOption[0]);
  45. GUILayout.EndVertical();
  46. GUILayout.EndArea();
  47. }
  48. private void NextExplosion()
  49. {
  50. if (this._currentExpIdx >= this.detonatorPrefabs.Length - 1)
  51. {
  52. this._currentExpIdx = 0;
  53. }
  54. else
  55. {
  56. this._currentExpIdx++;
  57. }
  58. this.currentDetonator = this.detonatorPrefabs[this._currentExpIdx];
  59. }
  60. private void SpawnWall()
  61. {
  62. if (this._currentWall)
  63. {
  64. UnityEngine.Object.Destroy(this._currentWall);
  65. }
  66. this._currentWall = UnityEngine.Object.Instantiate<GameObject>(this.wall, new Vector3(-7f, -12f, 48f), Quaternion.identity);
  67. this._spawnWallTime = Time.time;
  68. }
  69. private void Update()
  70. {
  71. this._guiRect = new Rect(7f, (float)(Screen.height - 150), 250f, 200f);
  72. if (Time.time + this._spawnWallTime > 0.5f)
  73. {
  74. if (!this.checkRect.Contains(Input.mousePosition) && Input.GetMouseButtonDown(0))
  75. {
  76. this.SpawnExplosion();
  77. }
  78. Time.timeScale = this.timeScale;
  79. }
  80. }
  81. private void SpawnExplosion()
  82. {
  83. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  84. RaycastHit raycastHit;
  85. if (Physics.Raycast(ray, out raycastHit, 1000f))
  86. {
  87. Detonator detonator = (Detonator)this.currentDetonator.GetComponent("Detonator");
  88. float num = detonator.size / 3f;
  89. Vector3 position = raycastHit.point + Vector3.Scale(raycastHit.normal, new Vector3(num, num, num));
  90. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.currentDetonator, position, Quaternion.identity);
  91. detonator = (Detonator)gameObject.GetComponent("Detonator");
  92. detonator.detail = this.detailLevel;
  93. UnityEngine.Object.Destroy(gameObject, this.explosionLife);
  94. }
  95. }
  96. public GameObject currentDetonator;
  97. private int _currentExpIdx = -1;
  98. public GameObject[] detonatorPrefabs;
  99. public float explosionLife = 10f;
  100. public float timeScale = 1f;
  101. public float detailLevel = 1f;
  102. public GameObject wall;
  103. private GameObject _currentWall;
  104. private float _spawnWallTime = -1000f;
  105. private Rect _guiRect;
  106. private Rect checkRect = new Rect(0f, 0f, 260f, 180f);
  107. }