Created
February 6, 2017 20:06
-
-
Save N-Carter/415c7e5b506a201cde9b04048bbf84e3 to your computer and use it in GitHub Desktop.
EditorGUITools
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 UnityEditor; | |
using System.Collections; | |
public class EditorGUITools : GUITools | |
{ | |
public static void DrawOutlineRect(Rect rect) | |
{ | |
DrawHorizontalLine(new Vector2(rect.x, rect.y), rect.width); | |
DrawVerticalLine(new Vector2(rect.x, rect.y), rect.height); | |
DrawHorizontalLine(new Vector2(rect.x, rect.y + rect.height), rect.width); | |
DrawVerticalLine(new Vector2(rect.x + rect.width, rect.y), rect.height); | |
} | |
public static void DrawFilledRect(Rect rect) | |
{ | |
GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture); | |
} | |
public static void DrawHorizontalLine(Vector2 origin, float length) | |
{ | |
DrawFilledRect(new Rect(origin.x, origin.y, length, 1)); | |
} | |
public static void DrawVerticalLine(Vector2 origin, float length) | |
{ | |
DrawFilledRect(new Rect(origin.x, origin.y, 1, length)); | |
} | |
public static void DrawGrid(Rect rect, float divisionsX, float divisionsY) | |
{ | |
for(float x = 0.0f; x < 1.0f; x += 1.0f / divisionsX) | |
DrawVerticalLine(new Vector3(rect.x + rect.width * x, rect.y), rect.height); | |
DrawVerticalLine(new Vector3(rect.x + rect.width, rect.y), rect.height); | |
for(float y = 0.0f; y < 1.0f; y += 1.0f / divisionsY) | |
DrawHorizontalLine(new Vector3(rect.x, rect.y + rect.height * y), rect.width); | |
DrawHorizontalLine(new Vector3(rect.x, rect.y + rect.height), rect.width); | |
} | |
} | |
public class EditorGUIGroupHorizontal : System.IDisposable | |
{ | |
public EditorGUIGroupHorizontal(params GUILayoutOption[] options) | |
{ | |
EditorGUILayout.BeginHorizontal(options); | |
} | |
public EditorGUIGroupHorizontal(GUIStyle style, params GUILayoutOption[] options) | |
{ | |
EditorGUILayout.BeginHorizontal(style, options); | |
} | |
void System.IDisposable.Dispose() | |
{ | |
EditorGUILayout.EndHorizontal(); | |
} | |
} | |
public class EditorGUIGroupVertical : System.IDisposable | |
{ | |
public EditorGUIGroupVertical(params GUILayoutOption[] options) | |
{ | |
EditorGUILayout.BeginVertical(options); | |
} | |
public EditorGUIGroupVertical(GUIStyle style, params GUILayoutOption[] options) | |
{ | |
EditorGUILayout.BeginVertical(style, options); | |
} | |
void System.IDisposable.Dispose() | |
{ | |
EditorGUILayout.EndVertical(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment