Skip to content

Instantly share code, notes, and snippets.

@SolarianZ
Created March 29, 2024 03:12
Show Gist options
  • Save SolarianZ/10ed22f36b8fe0e5b540ab2830c39b32 to your computer and use it in GitHub Desktop.
Save SolarianZ/10ed22f36b8fe0e5b540ab2830c39b32 to your computer and use it in GitHub Desktop.
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, UI, Skin, Style"} Get gui style by name in the Unity Editor.
/// <summary>
/// Get gui style by name.
/// </summary>
/// <param name="styleName"></param>
/// <returns></returns>
public static GUIStyle GetStyleByName(string styleName)
{
GUIStyle style = GUI.skin.FindStyle(styleName);
if (style == null)
{
style = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle(styleName);
}
if (style == null)
{
style = new GUIStyle { name = "StyleNotFoundError" };
Debug.LogError($"Missing built-in gui style '{styleName}'.");
}
return style;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment