[cb]扩展Hierarchy 添加二级菜单
目地
这篇博客教大家如何扩展Hierarchy
默认的Hierarchy
在Unity的Edior编辑器中,默认的Hierarchy如下
扩展的Hierarchy
扩展示例
MyInitOnLoad脚本
创建MyInitOnLoad.cs,放在Editor目录下
using UnityEngine; using UnityEditor; using System.Collections; //InitializeOnLoad:http://docs.unity3d.com/Manual/RunningEditorCodeOnLaunch.html [InitializeOnLoad] public static class MyInitOnLoad { //MenuItem属性把任意静态函数变成为一个菜单命令。仅静态函数能使用这个MenuItem属性 //static function MenuItem (itemName : string, isValidateFunction : bool, priority : int) [MenuItem("GameObject/Create Other/cb/New-1", false, 55000)] public static void CreateNew1() { } [MenuItem("GameObject/Create Other/cb/New-2", false, 55000)] public static void CreateNew2() { } [MenuItem("GameObject/Create Other/cb/New-3", false, 55000)] public static void CreateNew3() { } [MenuItem("GameObject/Create Other/cb/New-4", false, 55000)] public static void CreateNew4() { } }
自定义菜单
扩展Hierarchy后,出现自定义的菜单项,如下图所示: