官方也有一个文章,举了MenuItem类的一些使用方法,传送门:http://unity3d.com/cn/learn/tutorials/modules/intermediate/editor/menu-items 首先是unity顶部菜单栏的一些用法,如图: 注意:MenuItem是编辑器类,所以技能导入using UnityEditor;命名空间,且一般我们的类也不是集成自MonoBehaviour的,而是集成ScriptableObject的。
class in UnityEngine / 继承自:PropertyAttribute 描述 使用该属性可将上下文菜单添加到调用命名方法的字段。 using UnityEngine; using System.Collections; public class ExampleClass :MonoBehaviour{ [ContextMenuItem("Reset", "ResetBiography")] [Multiline(8)] public string playerBiography = ""; void Reset...
复制 using UnityEditor;using UnityEngine;using UnityEngine.UI;namespaceSK.Framework{publicclassImageTool:Editor{/// <summary>/// Image转RawImage/// </summary>[MenuItem("CONTEXT/Image/Convert 2 RawImage")]publicstaticvoidImage2RawImage(){Image image=Selection.activeGameObject.GetComponent<Image>();/...
用于给成员变量增加右键菜单 加在成员变量上,在成员变量上右键弹出右键菜单,对应的菜单函数只能是成员函数,不能是static函数 publicclassTestContextMenu : MonoBehaviour { [ContextMenuItem("Reset Count","CtxtMenuItem_ResetCount")]publicintm_Count;#ifUNITY_EDITORprivatevoidCtxtMenuItem_ResetCount() { m_Cou...
官方也有一个文章,举了 MenuItem 类的一些使用方法,传送门:http://unity3d.com/cn/learn/tutorials/modules/intermediate/editor/menu-items 首先是unity顶部菜单栏的一些用法,如图: 这里写图片描述 注意:MenuItem 是编辑器类,所以技能导入 using UnityEditor; ...
image.png 还有2个如下: image.png 分别在Runtime和UnityEditor下调用。前者是组件右键菜单, 附注: 如何在Unity的Inspector窗口中单独显示某个对象?? 答:以此为例,使用UnityEditor.Selection.SetActiveObjectWithContext(texture,texture);后,可以直接在Inspector窗口中观察到该对象的内容并预览 ...
public class ContextTesting : MonoBehaviour { /// Add a context menu named "Do Something" in the inspector /// of the attached script.[ContextMenu ("Do Something")]void DoSomething () { Debug.Log ("Perform operation");} } 这是unity的菜单拓展项 拓展编辑起用的。。也就是在...
扩展内置组件的环境菜单 EditorRigidbodyMenu.cs #ifUNITY_EDITORusingUnityEditor;usingUnityEngine;publicclassEditorRigidbodyMenu:Editor{[MenuItem("CONTEXT/Rigidbody/在Rigidbody上右键")]// 注意此处使用的不是 ContextMenustaticvoidDoIt(){EditorUtility.DisplayDialog("MyTool","Do It in C# !","OK","")...
UnityEditor Unity OtherContextMenuclass in UnityEngineDescripción The ContextMenu attribute allows you to add commands to the context menu. In the inspector of the attached script. When the user selects the context menu, the function will be executed.This is most useful for automatically setting ...
ContextMenuclass in UnityEngine描述 ContextMenu 属性用于向上下文菜单添加命令。在该附加脚本的 Inspector 中,当用户选择该上下文菜单时,将执行此函数。这对于从该脚本自动设置场景数据非常有用。此函数必须是非静态的。using UnityEngine;public class ContextTesting : MonoBehaviour { /// Add a context menu named...