-
-
Save kirillrybin/4509130 to your computer and use it in GitHub Desktop.
Переписанный на C# класс тестовой сцены из фреймворка Detonator Pack для Unity3D.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class DetonatorTest2 : MonoBehaviour | |
{ | |
public GameObject currentDetonator; | |
private int _currentExpIdx = -1; | |
private bool buttonClicked = false; | |
public GameObject[] detonatorPrefabs; | |
public float explosionLife = 10; | |
public float timeScale = 1.0F; | |
public float detailLevel = 1.0F; | |
public GameObject wall; | |
private GameObject _currentWall; | |
private float _spawnWallTime = -1000; | |
private Rect _guiRect; | |
void Start() | |
{ | |
SpawnWall(); | |
if (!currentDetonator) NextExplosion(); | |
else _currentExpIdx = 0; | |
} | |
private bool toggleBool = false; | |
void OnGUI() | |
{ | |
_guiRect = new Rect(7, Screen.height - 180, 250, 200); | |
GUILayout.BeginArea(_guiRect); | |
GUILayout.BeginVertical(); | |
string expName = currentDetonator.name; | |
if (GUILayout.Button(expName + " (Click For Next)")) | |
{ | |
NextExplosion(); | |
} | |
if (GUILayout.Button("Rebuild Wall")) | |
{ | |
SpawnWall(); | |
} | |
if (GUILayout.Button("Camera Far")) | |
{ | |
Camera.main.transform.position = new Vector3(0, 0, -7); | |
Camera.main.transform.eulerAngles = new Vector3(13.5F, 0, 0); | |
} | |
if (GUILayout.Button("Camera Near")) | |
{ | |
Camera.main.transform.position = new Vector3(0, -8.664466F, 31.38269F); | |
Camera.main.transform.eulerAngles = new Vector3(1.213462F, 0, 0); | |
} | |
GUILayout.Label("Time Scale"); | |
timeScale = GUILayout.HorizontalSlider(timeScale, 0.0F, 1.0F); | |
GUILayout.Label("Detail Level (re-explode after change)"); | |
detailLevel = GUILayout.HorizontalSlider(detailLevel, 0.0F, 1.0F); | |
GUILayout.EndVertical(); | |
GUILayout.EndArea(); | |
} | |
void NextExplosion() | |
{ | |
if (_currentExpIdx >= detonatorPrefabs.Length - 1) _currentExpIdx = 0; | |
else _currentExpIdx++; | |
currentDetonator = detonatorPrefabs[_currentExpIdx]; | |
} | |
void SpawnWall() | |
{ | |
if (_currentWall) Destroy(_currentWall); | |
_currentWall = Instantiate(wall, new Vector3(-7, -12, 48), Quaternion.identity) as GameObject; | |
_spawnWallTime = Time.time; | |
} | |
private Rect checkRect = new Rect(0, 0, 260, 180); | |
void Update() | |
{ | |
//keeps the UI in the corner in case of resize... | |
_guiRect = new Rect(7, Screen.height - 150, 250, 200); | |
//keeps the play button from making an explosion | |
if ((Time.time + _spawnWallTime) > 0.5) | |
{ | |
//don't spawn an explosion if we're using the UI | |
if (!checkRect.Contains(Input.mousePosition)) | |
{ | |
if (Input.GetMouseButtonDown(0)) | |
{ | |
SpawnExplosion(); | |
} | |
} | |
Time.timeScale = timeScale; | |
} | |
} | |
void SpawnExplosion() | |
{ | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
RaycastHit hit; | |
GameObject exp; | |
if (Physics.Raycast(ray, out hit, 1000)) | |
{ | |
var offsetSize = currentDetonator.GetComponent<Detonator>().size / 3; | |
var hitPoint = hit.point + ((Vector3.Scale(hit.normal, new Vector3(offsetSize, offsetSize, offsetSize)))); | |
exp = Instantiate(currentDetonator, hitPoint, Quaternion.identity) as GameObject; | |
exp.GetComponent<Detonator>().detail = detailLevel; | |
Destroy(exp, explosionLife); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment