当前位置:网站首页>The Unity editor development, Project development
The Unity editor development, Project development
2022-08-07 22:08:00 【IT apprentice.】
Unity编辑器拓展--Project拓展
前言
我们都知道在Unity的工程中,ProjectIt contains all the resources of our project.When we click the right mouse button, a menu will pop up:
If we want to expand these content, how should we expand??
Here I make some summaries.
Project视图
We create a new script to controlProject的拓展:

In fact, we carefully found thisProject's view is actually the same as our topAssetsThe pop-up content of the menu bar is consistent,所以我们对ProjectExpansion of content isAssetsExpand the menu bar.结合前面第一节We know that we only need to change the root directory..
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestProject : MonoBehaviour
{
[MenuItem("Assets/Test1")]
static void Test1()
{
}
}

Here we will not introduce more details.,可以看第一节
If we need to click on the custombuttonWhen can be achieved:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestProject : MonoBehaviour
{
[MenuItem("Assets/Test1")]
static void Test1()
{
//EditorApplication.projectWindowItemOnGUIWhen is open the option is invoked
EditorApplication.projectWindowItemOnGUI += (guid, rect) =>
{
///Capture parameter list
///1.Unique identifier for the file 2.
///用GUI绘制一个按钮
GUI.Button(new Rect(100, 100, 100, 100),"Test1");
};
}
//The following is the time to load is called,Both are based on demand
[InitializeOnLoadMethod]
static void InitializeOnload()
{
EditorApplication.projectWindowItemOnGUI += (guid, rect) =>
{
///Capture parameter list
///1.Unique identifier for the file 2.
///用GUI绘制一个按钮
GUI.Button(new Rect(100, 100, 100, 100), "Test1");
};
}
}
效果如下:
If we want a delete button to appear after the script is clicked,Then delete the corresponding prefab:
So what should such a function do??具体如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestProject : MonoBehaviour
{
[MenuItem("Assets/Test1")]
static void Test1()
{
}
//The following is the time to load is called,Both are based on demand
[InitializeOnLoadMethod]
static void InitializeOnload()
{
EditorApplication.projectWindowItemOnGUI += (guid, rect) =>
{
if(Selection.activeObject != null)
{
//Get the currently selected objectguid
string m_guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(Selection.activeObject));
if (m_guid == guid)
{
rect.x = rect.width - 100;
rect.width = 100;
if (GUI.Button(rect, "Test1"))
{
//删除
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(Selection.activeObject));
Debug.Log("删除当前对象" + AssetDatabase.GetAssetPath(Selection.activeObject));
}
}
}
/Capture parameter list
/1.Unique identifier for the file 2.
/用GUI绘制一个按钮
//GUI.Button(new Rect(100, 100, 100, 100), "Test1");
};
}
}


Project事件监听
新建一个脚本TestProjectEventto control event listeners
Here we no longer inheritUnity中的MonoBehaviour类,instead inheritUnityEditor.AssetModificationProcessora class like this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestProjectEvent : UnityEditor.AssetModificationProcessor
{
}
- 监听文件创建
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestProjectEvent : UnityEditor.AssetModificationProcessor
{
//Called before the resource is created
public static void OnWillCreateAsset(string path)
{
//pathIs a path we are going to create the resources
Debug.LogFormat("创建资源{0}",path);
}
}
Let's drag a picture to try the effect:
2. Monitoring file save
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestProjectEvent : UnityEditor.AssetModificationProcessor
{
[InitializeOnLoadMethod]
static void InitOnLoad()
{
//resource change call
EditorApplication.projectChanged += () =>
{
Debug.Log("资源发生了改变");
};
}
}
边栏推荐
- golang struct结构体之间的转换方式:传统方式和type取别名方式
- How to check your broadband account and password How to check your broadband account and password
- 如果Controller里有私有的方法,能成功访问吗?
- kali的安装与配置
- Leecode-SQL 1393. Capital Gains and Losses on Stocks
- 2022win7旗舰版永久激活密钥 win7旗舰版最新免费激活码分享
- golang映射map详解:map的三种创建方式、map的增删改查
- Leecode-SQL 1407. 排名靠前的旅行者
- LeetCode_Double Pointer_Medium_633. Sum of Squares
- Unity编辑器拓展--Project拓展
猜你喜欢
随机推荐
LeetCode_Double Pointer_Medium_633. Sum of Squares
谷歌联合高校发布端到端的全景分割方法MaX-DeepLab,图像分割的伪影大幅减少且不含手动模块
UE4 Sequence添加基础动画效果 (01-物体移动)
win7定时关机怎么设置 win7定时关机设置方法
现在网上开户安全么?想知道证券公司开户如何得到优惠?
双重队列问题
数据仓库调度工具Azkaban的使用(一)
win7截图快捷键ctrl加什么 电脑任意截图的按键组合有哪些
现在网上开户安全?手机开户哪个证券公司佣金最低?
同花顺开户靠谱吗?开户安全吗
How to install dual system on Apple computer
Flutter开发实战之Google Play 最佳应用程序开发者分享Flutter经验与技巧
图数据建模图数据建模指南
第一次小实习记录
Hands-on deep learning_target detection
软考 --- 软件工程(5)软件质量
阿德的感悟
golang函数和方法的区别
Redis - install Redis service and start the Linux system
新电脑如何分区硬盘 新电脑分区怎么分区
![[笔记]机器学习之机器学习理论及案例分析《二》 聚类](/img/92/cbb133e7f016346774b5d08c0c219f.png)





![[笔记]攻防工具分享之 CobaltStrike框架 《二》生成后门](/img/08/f70cbb47414dde5fa6c56f986bc7a1.png)


