using System; using UnityEngine; public class DetonatorTest : MonoBehaviour { private void Start() { this.SpawnWall(); if (!this.currentDetonator) { this.NextExplosion(); } else { this._currentExpIdx = 0; } } private void OnGUI() { this._guiRect = new Rect(7f, (float)(Screen.height - 180), 250f, 200f); GUILayout.BeginArea(this._guiRect); GUILayout.BeginVertical(new GUILayoutOption[0]); string name = this.currentDetonator.name; if (GUILayout.Button(name + " (Click For Next)", new GUILayoutOption[0])) { this.NextExplosion(); } if (GUILayout.Button("Rebuild Wall", new GUILayoutOption[0])) { this.SpawnWall(); } if (GUILayout.Button("Camera Far", new GUILayoutOption[0])) { Camera.main.transform.position = new Vector3(0f, 0f, -7f); Camera.main.transform.eulerAngles = new Vector3(13.5f, 0f, 0f); } if (GUILayout.Button("Camera Near", new GUILayoutOption[0])) { Camera.main.transform.position = new Vector3(0f, -8.664466f, 31.38269f); Camera.main.transform.eulerAngles = new Vector3(1.213462f, 0f, 0f); } GUILayout.Label("Time Scale", new GUILayoutOption[0]); this.timeScale = GUILayout.HorizontalSlider(this.timeScale, 0f, 1f, new GUILayoutOption[0]); GUILayout.Label("Detail Level (re-explode after change)", new GUILayoutOption[0]); this.detailLevel = GUILayout.HorizontalSlider(this.detailLevel, 0f, 1f, new GUILayoutOption[0]); GUILayout.EndVertical(); GUILayout.EndArea(); } private void NextExplosion() { if (this._currentExpIdx >= this.detonatorPrefabs.Length - 1) { this._currentExpIdx = 0; } else { this._currentExpIdx++; } this.currentDetonator = this.detonatorPrefabs[this._currentExpIdx]; } private void SpawnWall() { if (this._currentWall) { UnityEngine.Object.Destroy(this._currentWall); } this._currentWall = UnityEngine.Object.Instantiate(this.wall, new Vector3(-7f, -12f, 48f), Quaternion.identity); this._spawnWallTime = Time.time; } private void Update() { this._guiRect = new Rect(7f, (float)(Screen.height - 150), 250f, 200f); if (Time.time + this._spawnWallTime > 0.5f) { if (!this.checkRect.Contains(Input.mousePosition) && Input.GetMouseButtonDown(0)) { this.SpawnExplosion(); } Time.timeScale = this.timeScale; } } private void SpawnExplosion() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit raycastHit; if (Physics.Raycast(ray, out raycastHit, 1000f)) { Detonator detonator = (Detonator)this.currentDetonator.GetComponent("Detonator"); float num = detonator.size / 3f; Vector3 position = raycastHit.point + Vector3.Scale(raycastHit.normal, new Vector3(num, num, num)); GameObject gameObject = UnityEngine.Object.Instantiate(this.currentDetonator, position, Quaternion.identity); detonator = (Detonator)gameObject.GetComponent("Detonator"); detonator.detail = this.detailLevel; UnityEngine.Object.Destroy(gameObject, this.explosionLife); } } public GameObject currentDetonator; private int _currentExpIdx = -1; public GameObject[] detonatorPrefabs; public float explosionLife = 10f; public float timeScale = 1f; public float detailLevel = 1f; public GameObject wall; private GameObject _currentWall; private float _spawnWallTime = -1000f; private Rect _guiRect; private Rect checkRect = new Rect(0f, 0f, 260f, 180f); }