在Unity编辑器不同位置添加菜单

在Unity编辑器不同位置添加菜单 有时候由于自定义工作流的需要,我们需要在编辑器中添加我们自己的菜单,用来执行不同的操作,这里介绍在编辑器的不同位置该如何添加菜单,比如在主菜单添加,Hierarchy, Project,Inspector等位置。主菜单通过下拉列表弹出,Hierarchy,Project和Inspector分别是鼠标右键弹出。 在主菜单中弹出 using UnityEngine; using UnityEditor; using System.Collections; public class ExampleClass : MonoBehaviour { // Add Example1 has priority of 100 [MenuItem("Example/Example1", priority = 1)] public static void Example1() { print("Example/Example1"); } // Example2 has a priority of 111 which is 11 more than Example1. // This will cause a divider to be created. [MenuItem("Example/Example2", priority = 11)] public static void Example2() { print("Example/Example2"); } } 效果如下图: 注意当两个菜单的 priority 差值大于10【小于等于10不会有】的时候,菜单之间会自动生成一条横线。并且 priority 越大,菜单就会在越下面 在Hierarchy中弹出 using UnityEngine; using UnityEditor; using System....

September 22, 2022 · 2 min · 280 words · Link

在Unity的Hierarchy面板上添加鼠标右键菜单

在Unity的Hierarchy面板上添加右键菜单 这里添加的是复制一个模型的节点信息的功能,从子节点自身开始复制,一直到模型的父节点终止。因为有时候模型的子节点比较多,一个一个的去点开查找比较麻烦,或者想查看子节点的路径对不对。记得priority要写。 代码如下: public static class EditorTool { [MenuItem("GameObject/EditorTool/CopyPath", priority = 0)] static string CopyPath() { if (Selection.gameObjects.Length == 1) { GameObject selectObj = Selection.gameObjects[0]; StringBuilder pathSB = new StringBuilder(selectObj.name); while (selectObj.transform.parent != null) { pathSB.Insert(0, selectObj.transform.parent.name + "/"); selectObj = selectObj.transform.parent.gameObject; } GUIUtility.systemCopyBuffer = pathSB.ToString(); return pathSB.ToString(); } return ""; } } {: .shadow width = “50%” }

May 25, 2021 · 1 min · 59 words · Link