-
-
Save anonymous/d219b4e661432b70867d to your computer and use it in GitHub Desktop.
Unity custom editor by Zamaroth
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
import System.Collections.Generic; | |
@CustomEditor(Interface) | |
var offset : int; | |
var vector2_variable : Vector2; | |
var toggle_variable : boolean; | |
var text_width : float; | |
var slider_width : float; | |
class ScriptInspector extends Editor | |
{ | |
function OnInspectorGUI() | |
{ | |
DrawDefaultInspector(); | |
if(GUILayout.Button("New Window", GUILayout.Height(30))) | |
{ | |
target.windows.Add(null); | |
} | |
EditorGUILayout.Space(); | |
for(var i = 0; i < target.windows.Count - 1; i++) | |
{ | |
var rect : Rect = EditorGUILayout.BeginHorizontal(); | |
target.windows[i].isOpened = EditorGUILayout.Toggle("", target.windows[i].isOpened, GUILayout.Width(10)); | |
target.windows[i].show_window = EditorGUI.Foldout(Rect(rect.x + 15, rect.y, 20, 20), target.windows[i].show_window, ""); | |
target.windows[i].name = GUI.TextField(Rect(rect.x + 28, rect.y + 1, Screen.width - 150, 16), target.windows[i].name); | |
if(GUI.Button(Rect(Screen.width - 105, rect.y - 2, 85, 29), "Remove")) | |
{ | |
target.windows.RemoveAt(i); | |
} | |
EditorGUILayout.EndHorizontal(); | |
BeginSubmenu(false, "", target.windows[i].show_window); | |
if(target.windows[i].show_window == true) | |
{ | |
text_width = GUI.skin.label.CalcSize(new GUIContent("Position: ")).x; | |
slider_width = ((Screen.width - 137) / 2); | |
toggle_variable = target.windows[i].show_window_settings; | |
BeginSubmenu(true, "Settings", toggle_variable); | |
target.windows[i].show_window_settings = toggle_variable; | |
if(target.windows[i].show_window_settings == true) | |
{ | |
target.windows[i].settings.hasFixedSize = EditorGUILayout.Toggle("Has fixed size", target.windows[i].settings.hasFixedSize, GUILayout.Height(13)); | |
vector2_variable = target.windows[i].settings.position; | |
CustomVector2("Position", i); | |
target.windows[i].settings.position = vector2_variable; | |
vector2_variable = target.windows[i].settings.defaultSize; | |
CustomVector2("Size", i); | |
target.windows[i].settings.defaultSize = vector2_variable; | |
} | |
EndSubmenu(); | |
} | |
EndSubmenu(); | |
EditorGUILayout.Space(); | |
GUILayout.Box("", GUILayout.Width(Screen.width - 24), GUILayout.Height(4)); | |
} | |
} | |
} | |
function BeginSubmenu(Foldout : boolean, FoldoutText : String, Variable : Object) | |
{ | |
if(Foldout == true) | |
{ | |
toggle_variable = EditorGUILayout.Foldout(toggle_variable, FoldoutText); | |
} | |
EditorGUILayout.BeginHorizontal(); | |
if(Variable == true) | |
{ | |
EditorGUILayout.LabelField("", GUILayout.Width(16)); | |
} | |
EditorGUILayout.BeginVertical(); | |
offset += 16; | |
} | |
function EndSubmenu() | |
{ | |
EditorGUILayout.EndVertical(); | |
EditorGUILayout.EndHorizontal(); | |
offset -= 16; | |
} | |
function CustomVector2(Text : String, WindowNumber : int) | |
{ | |
rect = EditorGUILayout.BeginHorizontal(); | |
GUILayout.Label(Text+":"); | |
GUI.Label(Rect(text_width + 16 + offset, rect.y, 20, 16), "X"); | |
GUI.Label(Rect(Screen.width - 32 - slider_width + (offset / 2), rect.y, 20, 16), "Y"); | |
if((Text != "Size" && slider_width >= 166) || (Text == "Size" && (Text == "Size" && target.windows[WindowNumber].settings.hasFixedSize == false && slider_width >= 166))) | |
{ | |
vector2_variable.x = EditorGUI.IntSlider(Rect(text_width + 30 + offset, rect.y, slider_width - (offset / 2), 16), vector2_variable.x, 0, 100); | |
vector2_variable.y = EditorGUI.IntSlider(Rect(Screen.width - 20 - slider_width + (offset / 2), rect.y, slider_width - (offset / 2), 16), vector2_variable.y, 0, 100); | |
} | |
else | |
{ | |
vector2_variable.x = EditorGUI.IntField(Rect(text_width + 30 + offset, rect.y, slider_width - (offset / 2), 16), vector2_variable.x); | |
vector2_variable.y = EditorGUI.IntField(Rect(Screen.width - 20 - slider_width + (offset / 2), rect.y, slider_width - (offset / 2), 16), vector2_variable.y); | |
} | |
EditorGUILayout.EndHorizontal(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment