用于提取 MenuItem 的上下文。
MenuCommand objects are passed to custom menu item functions
defined using the MenuItem attribute.
注意:菜单会添加到对象中,并且可通过在检视面板中右键单击来访问。
脚本代码需要 CONTEXT 选项。
// Add context menu named "Do Something" to context menu
using UnityEngine;
using UnityEditor;
public class Something : EditorWindow
{
// Add menu item
[MenuItem("CONTEXT/Rigidbody/Do Something")]
static void DoSomething(MenuCommand command)
{
Rigidbody body = (Rigidbody)command.context;
body.mass = 5;
Debug.Log("Changed Rigidbody's Mass to " + body.mass + " from Context Menu...");
}
}
另请参阅:MenuItem。
MenuCommand | 创建一个新的 MenuCommand 对象。 |