当前位置:网站首页>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
边栏推荐
- Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
- Summary of June 2022
- 【GF(q)+LDPC】基于二值图GF(q)域的规则LDPC编译码设计与matlab仿真
- Lottery system test report
- Bottom problem of figure
- 输入年份、月份,确定天数
- Chapter 1 programming problems
- Flink memory model, network buffer, memory tuning, troubleshooting
- The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
- Industrial computer anti-virus
猜你喜欢
com. alibaba. nacos. api. exception. NacosException
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
Uniapp applet subcontracting
The important role of host reinforcement concept in medical industry
[web security] nodejs prototype chain pollution analysis
Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
[Mori city] random talk on GIS data (I)
Data double write consistency between redis and MySQL
随机推荐
Industrial computer anti-virus
【FPGA教程案例8】基于verilog的分频器设计与实现
If there are two sources in the same job, it will be reported that one of the databases cannot be found. Is there a boss to answer
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
[untitled] notice on holding "2022 traditional fermented food and modern brewing technology"
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
【Kubernetes系列】Kubernetes 上安装 KubeSphere
Computer connects raspberry pie remotely through putty
MySQL relearn 2- Alibaba cloud server CentOS installation mysql8.0
在已经知道表格列勾选一个显示一列
Responsive - media query
SQL foundation 9 [grouping data]
Redis interview question set
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
The final week, I split
[Valentine's day] - you can change your love and write down your lover's name
Latex中的单引号,双引号如何输入?
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
Selenium ide plug-in download, installation and use tutorial