一:前言
创建控件的时候可以通过EditorStyles设置控件样式
二:效果演示
三:代码实现
using UnityEngine;using UnityEditor;using System.Collections.Generic;using System;using System.Reflection;/// <summary>/// 编辑器样式预览窗口/// </summary>public class EditorStylePreviewEditor : EditorWindow{static List<GUIStyle> styles = new List<GUIStyle>();[MenuItem("Tools/编辑器样式预览窗口")]static void OpenWindow(){EditorWindow window = GetWindow(typeof(EditorStylePreviewEditor), true, "编辑器样式预览窗口");window.minSize = new Vector2(500, 500);window.Show();window.ShowUtility();window.Focus();Type type = typeof(EditorStyles);PropertyInfo[] pis = type.GetProperties(BindingFlags.Static | BindingFlags.Public);foreach (var temp in pis){object o = temp.GetValue(new EditorStyles());if (o.GetType() == typeof(GUIStyle)){styles.Add(o as GUIStyle);}}}Vector2 scrollPosition = Vector2.zero;private void OnGUI(){scrollPosition = GUILayout.BeginScrollView(scrollPosition);foreach (var temp in styles){GUILayout.Label(temp.name, temp);}GUILayout.EndScrollView();}}