假设我们希望为材质右键弹出按钮增加新的功能,应该怎么做呢
我们可以通过注册EditorApplication.contextualPropertyMenu全局回调方法,增加自定义的MenuItem
using UnityEditor;
using UnityEngine;
namespace Yaojz
{
[InitializeOnLoad]
public static class MaterialContextMenuCopy
{
static MaterialContextMenuCopy()
{
EditorApplication.contextualPropertyMenu += OnPropertyContextMenu;
}
private static void OnPropertyContextMenu(GenericMenu menu, SerializedProperty property)
{
if (property.objectReferenceValue == null)
{
return;
}
var objValue = property.objectReferenceValue;
var type = objValue.GetType();
//这里判断是否是特定类型
if (type == typeof(Mesh))
{
menu.AddItem(new GUIContent("复制并引用"),false, () =>
{
});
}
else if (type == typeof(Material))
{
menu.AddItem(new GUIContent("复制并引用"),false, () =>
{
});
}
}
}
}
标签:菜单,自定义,EditorApplication,contextualPropertyMenu,static,右键
From: https://www.cnblogs.com/terrynoya/p/18030368