Last active
August 29, 2015 14:20
-
-
Save grimmdev/85081e996b41e5110f31 to your computer and use it in GitHub Desktop.
TransformEditor HUD for SceneView
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
// Put this file in the folder Editor | |
// 2015 | |
// Sean Loper | |
// TransformEditor 1.1 | |
// HUD For sceneview | |
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
[CustomEditor(typeof(Transform))] | |
public class TransformEditor : Editor { | |
static private bool hide = false; | |
static private bool options = false; | |
static private bool minimal = true; | |
static private Vector2 Offset = new Vector2 (50, -100); | |
private Vector3 TransformPosition; | |
static private Color FontColor = Color.white; | |
static private Color BackgroundColor = Color.white; | |
public override void OnInspectorGUI() | |
{ | |
// We get some funky things happening when we use Drawdefaultinspector as opposed to redrawing our own fields. | |
Selection.activeTransform.position = EditorGUILayout.Vector3Field ("Position", Selection.activeTransform.position); | |
Selection.activeTransform.eulerAngles = EditorGUILayout.Vector3Field ("Rotation", Selection.activeTransform.eulerAngles); | |
Selection.activeTransform.localScale = EditorGUILayout.Vector3Field ("Scale", Selection.activeTransform.localScale); | |
// Let's allow people to show it in editor | |
GUILayout.BeginHorizontal(); | |
if (GUILayout.Button ("Show GUI")) { | |
hide = false; | |
} | |
if (GUILayout.Button ("Toggle Options")) { | |
options = !options; | |
} | |
GUILayout.EndHorizontal(); | |
if (options) { | |
Offset = EditorGUILayout.Vector2Field("Offset", Offset); | |
FontColor = EditorGUILayout.ColorField("Font Color", FontColor); | |
BackgroundColor = EditorGUILayout.ColorField("Background Color", BackgroundColor); | |
minimal = EditorGUILayout.Toggle("Minimal", minimal); | |
} | |
} | |
void OnSceneGUI() | |
{ | |
// let's set font and background color for the window. | |
GUI.color = FontColor; | |
GUI.backgroundColor = BackgroundColor; | |
// We use this to get the screen position of the selected transform so that we can put our window next to him | |
if(Selection.activeTransform != null) | |
TransformPosition = Camera.current.WorldToScreenPoint (Selection.activeTransform.position); | |
Handles.BeginGUI(); | |
if (!hide && Selection.activeTransform != null) { | |
GUILayout.Window (2, new Rect (TransformPosition.x+Offset.x, Screen.height-TransformPosition.y+Offset.y, 250, 100), (id) => { | |
// now we just display the editor values here | |
Selection.activeTransform.position = EditorGUILayout.Vector3Field ("Position", Selection.activeTransform.position); | |
Selection.activeTransform.eulerAngles = EditorGUILayout.Vector3Field ("Rotation", Selection.activeTransform.eulerAngles); | |
Selection.activeTransform.localScale = EditorGUILayout.Vector3Field ("Scale", Selection.activeTransform.localScale); | |
// if the minimal option isn't set, we show a few more options to edit in the window.. | |
if(!minimal){ | |
Selection.activeTransform.name = EditorGUILayout.TextField("Name", Selection.activeTransform.name); | |
Selection.activeTransform.tag = EditorGUILayout.TagField("Tag", Selection.activeTransform.tag); | |
} | |
// this is just so people can hide it.. if they want to that is. | |
if (GUILayout.Button ("Hide GUI")) { | |
hide = true; | |
} | |
}, Selection.activeTransform.name); | |
} | |
Handles.EndGUI(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment