真UnityEditor编辑器扩展之dropdown和风琴式左右布局窗口
Posted avi9111
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了真UnityEditor编辑器扩展之dropdown和风琴式左右布局窗口相关的知识,希望对你有一定的参考价值。
目录
实现DropDown
传统的gui in Editor并没有editor
或者有我不知道
但确实明显没有
但是有menu
左右布局实现
实现不了docker,就将就用用
void OnGUI()
{
if (EditorGUILayout.DropdownButton(new GUIContent("11"), FocusType.Passive))
{
Debug.LogError("fff");
GenericMenu menu = new GenericMenu();
// forward slashes nest menu items under submenus
AddMenuItemForColor(menu, "RGB/Red", Color.red);
AddMenuItemForColor(menu, "RGB/Green", Color.green);
AddMenuItemForColor(menu, "RGB/Blue", Color.blue);
menu.AddSeparator("");
AddMenuItemForColor(menu, "White", Color.white);
// display the menu
menu.ShowAsContext();
}
}
void AddMenuItemForColor(GenericMenu menu, string menuPath, Color color)
{
// the menu item is marked as selected if it matches the current value of m_Color
menu.AddItem(new GUIContent(menuPath), m_Color.Equals(color), OnColorSelected, color);
}
// the GenericMenu.MenuFunction2 event handler for when a menu item is selected
void OnColorSelected(object color)
{
m_Color = (Color)color;
}
gui rect定位的秘密
关键还是Style,某个小弟的分析给了我启发
原来搞这么多年,都没搞懂
label的style简单,是GUI.sytle.label
public class GUILayout
{
/// <summary>
/// <para>Make an auto-layout label.</para>
/// </summary>
/// <param name="text">Text to display on the label.</param>
/// <param name="image">Texture to display on the label.</param>
/// <param name="content">Text, image and tooltip for this label.</param>
/// <param name="style">The style to use. If left out, the label style from the current GUISkin is used.</param>
/// <param name="options">An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.<br>
/// See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight,
/// GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.</param>
public static void Label(Texture image, params GUILayoutOption[] options)
{
GUILayout.DoLabel(GUIContent.Temp(image), GUI.skin.label, options);
}
objectField的style是.layerMaskField
/// <summary>
/// <para>Get a rect for an Editor control.</para>
/// </summary>
/// <param name="hasLabel">Optional boolean to specify if the control has a label. Default is true.</param>
/// <param name="height">The height in pixels of the control. Default is EditorGUIUtility.singleLineHeight.</param>
/// <param name="style">Optional GUIStyle to use for the control.</param>
/// <param name="options">An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the style.
/// See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight,
/// GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.</param>
public static Rect GetControlRect(
bool hasLabel,
float height,
params GUILayoutOption[] options)
{
return EditorGUILayout.GetControlRect(hasLabel, height, EditorStyles.layerMaskField, options);
}
参考:
UnityEditor.GenericMenu - Unity 脚本 API (unity3d.com)
以上是关于真UnityEditor编辑器扩展之dropdown和风琴式左右布局窗口的主要内容,如果未能解决你的问题,请参考以下文章
UnityEditor编辑器扩展开发之类似于Inspector面板_Script的GameObject写法