首页 > 解决方案 > 如何创建可折叠的汉堡菜单图标自定义检查器/编辑器 Unity

问题描述

我最近在一个视频中看到了这个自定义检查器图标,我认为它对于我目前正在创建的自定义编辑器可能非常有用。不过,我无法找到有关如何创建它的任何信息,所以我想知道是否有人知道如何创建它,或者它是否可能是视频创建者自己添加的。

替代文字

红色框内的项目是我想要创建的。如果有人有任何关于它是如何创建的或如何从头开始创建它的信息,我将不胜感激。

标签: unity3d

解决方案


您可以使用 GUIStyle 创建此图像。

using UnityEditor;

[CustomPropertyDrawer(typeof(MyProperty))]
public class MyPropertyDrawer : PropertyDrawer
{
    //which index of the popupOptions you want selected
    private int selectedIndex = 0;

    //the different options you want to display when the Popup is selected
    private readonly string[] popupOptions =
        { "Option One", "Option Two" };  

    private GUIStyle popupStyle;

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //stuff above here

        if (popupStyle == null)
        {
            popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"));
            popupStyle.imagePosition = ImagePosition.ImageOnly;
        }
        EditorGUI.Popup(position /*or whatever position you want*/, selectedIndex, popupOptions, popupStyle);

        //stuff below here
    }
}

在这里找到。


推荐阅读