一,unity 内置图标展示
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();
}
}
二 自定义图标
?
private void LoadGuiStyles()
{
string path = GetMonoScriptFilePath(this);
path = path.Split(new string[] { "Assets" }, StringSplitOptions.None)[1]
.Split(new string[] { "Tayx" }, StringSplitOptions.None)[0];
m_logoTexture = AssetDatabase.LoadAssetAtPath<Texture2D>
(
"Assets" +
path +
"Tayx/Graphy - Ultimate Stats Monitor/Textures/Debugger_Logo_" +
(EditorGUIUtility.isProSkin ? "White.png" : "Dark.png")
);
m_skin = AssetDatabase.LoadAssetAtPath<GUISkin>
(
"Assets" +
path +
"Tayx/Graphy - Ultimate Stats Monitor/GUI/Graphy.guiskin"
);
if (m_skin != null)
{
m_headerStyle1 = m_skin.GetStyle("Header1");
m_headerStyle2 = m_skin.GetStyle("Header2");
SetGuiStyleFontColor
(
guiStyle: m_headerStyle2,
color: EditorGUIUtility.isProSkin ? Color.white : Color.black
);
}
else
{
m_headerStyle1 = EditorStyles.boldLabel;
m_headerStyle2 = EditorStyles.boldLabel;
}
}
--------------------------------------------------------
GUISkin skin = AssetDatabase.LoadAssetAtPath<GUISkin>
(
"Assets/_Game/myTest.guiskin"
);
if (GUILayout.Button("保存", skin.GetStyle("test"), GUILayout.Width(60)))
{
}
结果如下
|