MenuCommand

class in UnityEditor

Switch to Manual

Description

用于提取 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

Variables

context上下文是作为菜单命令目标的对象。
userData用于将自定义信息传递给菜单项的整数。

Constructors

MenuCommand创建一个新的 MenuCommand 对象。