使用默认的一些GUI样式,可以让编辑器扩展外观更佳。Unity自带有很多样式,当要使用这些样式时,只要指定其样式名即可。
所有的样式名称,可以写个脚本遍历出来,另外可以将其样式效果也一并展现出来。这一点已经有插件实现了,即:Editor Style Viewer( https://www.assetstore.unity3d.com/en/#!/content/3282)
所有的样式名称,可以写个脚本遍历出来,另外可以将其样式效果也一并展现出来。这一点已经有插件实现了,即:Editor Style Viewer( https://www.assetstore.unity3d.com/en/#!/content/3282)
查看器代码如下:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
using UnityEngine;
using UnityEditor; public class EditorStyleViewer : EditorWindow { private Vector2 scrollPosition = Vector2.zero; private string search = string.Empty; [MenuItem( "Tools/GUI样式查看器")] public static void Init() { EditorWindow.GetWindow( typeof(EditorStyleViewer)); } void OnGUI() { GUILayout.BeginHorizontal( "HelpBox"); GUILayout.Label( "单击示例将复制其名到剪贴板", "label"); GUILayout.FlexibleSpace(); GUILayout.Label( "查找:"); search = EditorGUILayout.TextField(search); GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView(scrollPosition); foreach (GUIStyle style in GUI.skin) { if (style.name.ToLower().Contains(search.ToLower())) { GUILayout.BeginHorizontal( "PopupCurveSwatchBackground"); GUILayout.Space( 7); if (GUILayout.Button(style.name, style)) { EditorGUIUtility.systemCopyBuffer = "\"" + style.name + "\""; } GUILayout.FlexibleSpace(); EditorGUILayout.SelectableLabel( "\"" + style.name + "\""); GUILayout.EndHorizontal(); GUILayout.Space( 11); } } GUILayout.EndScrollView(); } } |
效果图如下:
右上角可以进行搜索,单击每个样式的左侧效果时,可以复制其样式名到剪贴板。