【发布时间】:2019-02-13 06:34:36
【问题描述】:
using UnityEditor;
using UnityEngine;
public class Test : EditorWindow
{
[MenuItem("GameObject/Test")]
static void Tests()
{
int width = 340;
int height = 300;
int x = (Screen.currentResolution.width - width) / 2;
int y = (Screen.currentResolution.height - height) / 2;
GetWindow<Test>().position = new Rect(x, y, width, height);
}
}
这将在 GameObject 下方顶部的编辑器菜单中创建测试选项。 但我想在层次结构中的单个或多个 GameObject/s 上添加选项/属性,而不是编辑器顶部菜单。
这是我尝试过的:
using UnityEditor;
using UnityEngine;
public class ExportObjects : EditorWindow
{
[MenuItem("GaemObject/Export", true, 1)]
static void Export()
{
int width = 340;
int height = 300;
int x = (Screen.currentResolution.width - width) / 2;
int y = (Screen.currentResolution.height - height) / 2;
GetWindow<ExportObjects>().position = new Rect(x, y, width, height);
}
}
但它什么也没做,它没有在层次结构中的对象上的右键单击鼠标上下文菜单中添加任何内容。
如果我换行:
[MenuItem("GaemObject/Export", true, 1)]
收件人:
[MenuItem("GaemObject/Export")]
它将在编辑器和导出的顶部添加一个新的 GameObject 菜单。 但是我想在层次结构中的对象上单击鼠标右键时添加它。单个对象或选定对象。
试过真,1 和真,-10 或真,10
【问题讨论】: