Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- public class Cubicos : EditorWindow
- {
- static Vector3 p; // posición
- static GameObject c; // cubicos
- [MenuItem("Window/Cubicos")]
- static void i() // inicia
- {
- EditorWindow.GetWindow<Cubicos>().Show();
- }
- void OnEnable()
- {
- SceneView.onSceneGUIDelegate -= this.OnSceneGUI;
- SceneView.onSceneGUIDelegate += this.OnSceneGUI;
- p = Vector3.zero;
- }
- void OnDestroy()
- {
- UnityEditor.SceneView.onSceneGUIDelegate -= this.OnSceneGUI;
- if (c != null)
- DestroyImmediate(c.gameObject);
- }
- void OnGUI()
- {
- pc();
- GUILayout.BeginArea(new Rect(4, 4, 150, 150));
- {
- GUILayout.BeginVertical();
- {
- GUILayout.BeginHorizontal();
- {
- if (GUILayout.Button("* U"))
- m(Vector3.forward);
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("^ I"))
- m(Vector3.up);
- GUILayout.FlexibleSpace();
- }
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- {
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("< J"))
- m(Vector3.left);
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("> L"))
- m(Vector3.right);
- }
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- {
- if (GUILayout.Button("o M"))
- m(Vector3.back);
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("v K"))
- m(Vector3.down);
- GUILayout.FlexibleSpace();
- }
- GUILayout.EndHorizontal();
- GUILayout.Space(8);
- GUILayout.BeginHorizontal();
- {
- if (GUILayout.Button("+ spc"))
- d();
- if (GUILayout.Button("- del"))
- b();
- }
- GUILayout.EndHorizontal();
- }
- GUILayout.EndVertical();
- }
- GUILayout.EndArea();
- c.transform.position = p;
- }
- void OnSceneGUI(
- SceneView sv)
- {
- pc();
- Event e = Event.current;
- if (e.type == EventType.KeyDown)
- {
- switch (e.keyCode)
- {
- case KeyCode.I:
- m(Vector3.up);
- break;
- case KeyCode.J:
- m(Vector3.left);
- break;
- case KeyCode.K:
- m(Vector3.down);
- break;
- case KeyCode.L:
- m(Vector3.right);
- break;
- case KeyCode.U:
- m(Vector3.forward);
- break;
- case KeyCode.M:
- m(Vector3.back);
- break;
- case KeyCode.Space:
- d();
- break;
- case KeyCode.Delete:
- case KeyCode.Backspace:
- b();
- break;
- }
- c.transform.position = p;
- }
- }
- void pc() // prepara cúbicos
- {
- if (c == null)
- {
- c = GameObject.Find("[Cubicos]");
- if (c == null)
- {
- c = GameObject.CreatePrimitive(PrimitiveType.Cube);
- c.name = "[Cubicos]";
- c.GetComponent<Renderer>().enabled = false;
- c.GetComponent<Collider>().isTrigger = true;
- }
- }
- Selection.activeObject = c;
- }
- void m( // mueve
- Vector3 d) // dirección
- {
- p += d;
- }
- void d() // dibuja
- {
- var mr = Transform.FindObjectsOfType<MeshRenderer>(); // Transforms
- foreach (var imr in mr) // índice de MeshRenderer
- {
- if (imr.gameObject != c && Vector3.Distance(imr.transform.position, p) < 0.001f)
- return;
- }
- GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = p;
- }
- void b() // borra
- {
- var mr = Transform.FindObjectsOfType<MeshRenderer>(); // Transforms
- foreach (var imr in mr) // índice de MeshRenderer
- {
- if (imr.gameObject != c && Vector3.Distance(imr.transform.position, p) < 0.001f)
- DestroyImmediate(imr.gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment