当前位置:网站首页>Unity editor extension -- Hierarchy extension
Unity editor extension -- Hierarchy extension
2022-08-07 22:05:00 【IT apprentice.】
Unity编辑器拓展--Hierarchy拓展
前言
HierarchyView opens the options we found andGameObjectThe open view is the same,So we expandHierachyView is also rightGameObjectThe menu bar option is expanded,前文已经介绍过了,具体可以参考Project拓展
Hierarchy拓展
Here we create a new script to controlHierarchy拓展:
This is what we did beforeProjectExtend similar,It's just when it's passed,We need to pass an instanceIdGo in insteadguid.
具体代码如下所示:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestHierarchy : MonoBehaviour
{
[MenuItem("GameObject/Hierarchy1", false, 0)]
static void Test1()
{
Debug.Log("Hierarchy1");
}
[InitializeOnLoadMethod]
static void InitializeOnload()
{
EditorApplication.hierarchyWindowItemOnGUI += (instanceID, rect) =>
{
if (Selection.activeObject != null && instanceID==Selection.activeObject.GetInstanceID())
{
rect.x = rect.width - 50;
rect.width = 100;
if (GUI.Button(rect, "delete"))
{
//Delete game objects from the scene
GameObject.DestroyImmediate(Selection.activeObject);
}
}
};
}
}
重写Hierarchy菜单
If we want to completely deprecate the previous oneHierarchyThe menu thus completely uses its own customHierarchy应该怎么实现呢?
这里我们首先创建一个脚本来控制Hierarchy的重写
我们跳出HierarchyThe menu appears when you right-click,So here we need to rewrite by listening to the right click event.类似于这样:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestHierarchyMenu : MonoBehaviour
{
[InitializeOnLoadMethod]
static void InitOnLoad()
{
EditorApplication.hierarchyWindowItemOnGUI += (instanceID, rect) =>
{
//Listen to the right-click event of our mouse
if (Event.current != null&&Event.current.button==1&&Event.current.type==EventType.MouseUp)
{
Debug.Log("Hierarchy鼠标右键抬起");
}
};
}
}

We can achieve rewriting by blocking this event:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestHierarchyMenu : MonoBehaviour
{
[InitializeOnLoadMethod]
static void InitOnLoad()
{
EditorApplication.hierarchyWindowItemOnGUI += (instanceID, rect) =>
{
//Listen to the right-click event of our mouse
if (Event.current != null&&Event.current.button==1&&Event.current.type==EventType.MouseUp)
{
Debug.Log("Hierarchy鼠标右键抬起");
//Block native menus
Event.current.Use();
//弹出自定义的菜单
///参数1.The position and size of the popup,2.A custom menu that pops up 3.菜单命令
EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x,Event.current.mousePosition.y,100,100),"Assets",null);
}
};
}
}
我们来看一下效果:
发现弹出了Assets菜单:
边栏推荐
- 怎么看64位还是32位 怎么看电脑是32还是64
- 即将开幕!阿里云飞天技术峰会邀您一同探秘云原生最佳实践
- 2022年危险化学品生产单位安全生产管理人员考试试题及模拟考试
- Unity编辑器拓展--Inspector拓展
- 无法访问打印机怎么办 共享打印机无法访问权限怎么解决
- Is it safe to open an account with Big Wisdom?
- 2022G1工业锅炉司炉特种作业证考试题库模拟考试平台操作
- 小米3手机怎样连接电脑 小米3连接电脑传文件的教程
- Towards a Unified View of Parameter-Efficient Transfer Learning
- UE4 Sequence添加基础动画效果 (02-切换动作)
猜你喜欢

Shell: Loop Statements and Functions

Thymeleaf

如何使用 ABAP 创建包含不同字体大小的 Word 文档

What to do if Win7 opens word and prompts "Cannot open file Normal because there is an error in the content"

知乎高赞:拼多多和国家电网,选哪个?

如何找到系统支持的最大并发数

笔记本怎样手写 笔记本电脑如何使用手写功能

【kali-权限提升】(4.2.2)社会工程学工具包:web站点克隆钓鱼

How to change the default opening method How to change the opening method of a file

【瑞吉外卖】day03:完善登录功能与新增员工
随机推荐
The difference between Icon and Ico pictures
ECCV 2022 | 清华&腾讯AI Lab提出REALY: 重新思考3D人脸重建的评估方法
How to read ten thousand lines of code
如果Controller里有私有的方法,能成功访问吗?
golang切片slice详解:介绍、内存分析、定义、遍历、切片可以继续切片、切片可以动态增长、切片的拷贝及底层原理
冰冰学习笔记:类与对象(下)
[笔记]攻防工具分享之 CobaltStrike框架 《一》环境配置
【636. 函数的独占时间】
【kali-权限提升】(4.2.2)社会工程学工具包:web站点克隆钓鱼
UE4 Sequence添加基础动画效果 (03-主序列的使用)
leetcode 232. Implement Queue using Stacks
那就浅浅回顾一下生成器吧
JDBC简介
数据仓库调度工具Azkaban的使用(二)
MySQL先分组再取组内最大最小记录
黑盒子问题
安装IK分词器
如何打开本地组策略编辑器 打开组策略编辑器方法
温州银河证券手机开户收费吗?开户安全吗?
阿德的感悟