当前位置:网站首页>Unity 从Inspector界面打开资源管理器选择并记录文件路径
Unity 从Inspector界面打开资源管理器选择并记录文件路径
2022-07-04 07:13:00 【unity工具人】
在AvProVideo插件中有个功能,点击视频组件中的按钮可以打开资源管理器窗口,找到目标视频资源并记录下资源路径。
查了一下实现起来并不难,主要有两点
一个是unity 自带的用于打开资源管理器的方法
EditorUtility.OpenFilePanel();
第二个就是自定义编辑器的操作
实现过程
脚本1:定义窗口、打开资源管理器
using UnityEngine;
using UnityEditor;
public class Example : EditorWindow
{
static GameObject _objectBuilderScript;
//[MenuItem("SKFramework/Example")]
public static void Open(GameObject objectBuilderScript)
{
GetWindow<Example>().Show();
_objectBuilderScript = objectBuilderScript;
}
private string path;
private void OnGUI()
{
//水平布局
GUILayout.BeginHorizontal();
{
GUILayout.Label("路径", GUILayout.Width(50f));
path = GUILayout.TextField(path);
if (GUILayout.Button("浏览", GUILayout.Width(50f)))
{
//不用上边这个弹窗也可以
path = EditorUtility.OpenFilePanel("成功啦 ୧*□*୨", Application.dataPath, "png");
_objectBuilderScript.GetComponent<ObjectBuilderScript>().path = path;
}
}
GUILayout.EndHorizontal();
}
}
脚本2:操作类
using UnityEditor;
using UnityEngine;
public class ObjectBuilderScript : MonoBehaviour
{
public string path;
public void BuildObject()
{
Example.Open(gameObject);
}
}
脚本3:重写操作类
这个脚本要放在 Assets/Editor 文件夹下
using UnityEngine;
using UnityEditor;
using System;
[CustomEditor(typeof(ObjectBuilderScript))]
public class ObjectBuilderEditor : Editor
{
public override void OnInspectorGUI()
{
string path;
string FilePath = Environment.CurrentDirectory;
DrawDefaultInspector();
ObjectBuilderScript myScript = (ObjectBuilderScript)target;
if (GUILayout.Button("选择图片资源"))
{
myScript.BuildObject();
}
}
}
可以看到我们定义了一个按钮
弹窗
打开资源管理器
选择文件后可以看到路径被保存下来了

参考文章:https://blog.csdn.net/qq_42139931/article/details/123206376
参考文章:https://wenku.baidu.com/view/1b41bac9561810a6f524ccbff121dd36a32dc422.html
边栏推荐
- 响应式移动Web测试题
- Selenium driver ie common problem solving message: currently focused window has been closed
- Uniapp applet subcontracting
- Tar source code analysis 9
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
- 期末周,我裂开
- Campus network problems
- Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
- [Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
- 【网络数据传输】基于FPGA的百兆网/兆网千UDP数据包收发系统开发,PC到FPGA
猜你喜欢

Centos8 install mysql 7 unable to start up

MySQL 45 lecture learning notes (VII) line lock

the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘

Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction

Transition technology from IPv4 to IPv6

Selenium ide plug-in download, installation and use tutorial

【GF(q)+LDPC】基于二值图GF(q)域的规则LDPC编译码设计与matlab仿真

Responsive mobile web test questions

There is no Chinese prompt below when inputting text in win10 Microsoft Pinyin input method

centos8安装mysql.7 无法开机启动
随机推荐
MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
用于压缩视频感知增强的多目标网络自适应时空融合
[untitled] notice on holding "2022 traditional fermented food and modern brewing technology"
Deep profile data leakage prevention scheme
A new understanding of how to encrypt industrial computers: host reinforcement application
[kubernetes series] kubesphere is installed on kubernetes
Selection (023) - what are the three stages of event propagation?
Tar source code analysis 9
notepad++如何统计单词数量
Finishing (III) - Exercise 2
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph
Zabbix agent主动模式的实现
移动适配:vw/vh
How does the inner roll break?
"Sword finger offer" 2nd Edition - force button brush question
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
Pangu open source: multi support and promotion, the wave of chip industry
Four sets of APIs for queues
ABCD four sequential execution methods, extended application