Skip to content

Instantly share code, notes, and snippets.

@attilam
Last active June 21, 2017 08:31
Show Gist options
  • Save attilam/4753898 to your computer and use it in GitHub Desktop.
Save attilam/4753898 to your computer and use it in GitHub Desktop.
Quick Measuring Tape Unity Editor Script
using UnityEngine;
using System.Collections;
public class MeasuringTape : MonoBehaviour {
public Vector3 target = Vector3.zero;
}
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