Created
March 29, 2024 03:12
-
-
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.
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
/// <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