Last active
June 21, 2017 08:31
-
-
Save attilam/4753898 to your computer and use it in GitHub Desktop.
Quick Measuring Tape Unity Editor Script
This file contains hidden or 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 MeasuringTape : MonoBehaviour { | |
| public Vector3 target = Vector3.zero; | |
| } |
This file contains hidden or 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; | |
| using UnityEditor; | |
| [CustomEditor(typeof(MeasuringTape))] | |
| public class MeasuringTapeEditor : Editor { | |
| void OnSceneGUI() { | |
| MeasuringTape tape = ((MeasuringTape)target); | |
| tape.target = Handles.PositionHandle(tape.target, Quaternion.identity); | |
| Handles.color = Color.white; | |
| Handles.DrawLine(tape.transform.position, tape.target); | |
| Handles.BeginGUI(); | |
| GUILayout.BeginArea(new Rect(Screen.width-100, Screen.height-80, 90, 50)); | |
| if (GUILayout.Button("Dist: "+Vector3.Distance(tape.transform.position, tape.target))) { | |
| tape.target = tape.transform.position; | |
| } | |
| GUILayout.EndArea(); | |
| Handles.EndGUI(); | |
| } | |
| [MenuItem("GameObject/Create Measuring Tape")] | |
| static void CreateMeasuringTape() { | |
| GameObject go = new GameObject("_MeasuringTape"); | |
| go.AddComponent<MeasuringTape>(); | |
| if (Selection.activeTransform != null) { | |
| go.transform.position = Selection.activeTransform.position; | |
| } | |
| go.GetComponent<MeasuringTape>().target = go.transform.position; | |
| Selection.activeGameObject = go; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment