Skip to content

Instantly share code, notes, and snippets.

@Demkeys
Created December 4, 2018 16:31
Show Gist options
  • Save Demkeys/cdaab2b249261f5fba76ad864facca48 to your computer and use it in GitHub Desktop.
Save Demkeys/cdaab2b249261f5fba76ad864facca48 to your computer and use it in GitHub Desktop.
Example code showing how to use the GUIStyles provided in UnityEditor.EditorStyles class.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class GUIStylesExample : EditorWindow {
string textFieldString = "This is a textbox that looks like a bold Label.";
[MenuItem("My Tools/GUI Styles Example")]
static void ShowWindow()
{
EditorWindow window = GetWindow(typeof(GUIStylesExample));
window.Show();
}
void OnGUI()
{
// -----------------------------------------------------------------------
// GUIStyles applied to GUI controls
// -----------------------------------------------------------------------
EditorGUILayout.LabelField("Mini Label", EditorStyles.miniLabel);
EditorGUILayout.LabelField("Large Label", EditorStyles.largeLabel);
EditorGUILayout.LabelField("Bold Label", EditorStyles.boldLabel);
if(GUILayout.Button("Regular Button"))
Debug.Log("Regular Button pressed.");
if(GUILayout.Button("Mini Button",EditorStyles.miniButton))
Debug.Log("Mini Button pressed.");
if(GUILayout.Button("Toolbar Button",EditorStyles.toolbarButton))
Debug.Log("Toolbar Button pressed.");
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// GUIStyles a certain GUI control applied to another GUI control
// -----------------------------------------------------------------------
// TextField with Bold Label GUI Style
textFieldString = EditorGUILayout.TextField(textFieldString, EditorStyles.boldLabel);
// Button with ColorField GUI Style
if(GUILayout.Button("ColorField Button",EditorStyles.colorField))
Debug.Log("ColorField Button.");
// Button with Centered Grey Mini Label Button GUI Style
if(GUILayout.Button("Centered Grey Mini Label Button",EditorStyles.centeredGreyMiniLabel))
Debug.Log("Centered Grey Mini Label Button.");
// -----------------------------------------------------------------------
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment