当前位置:网站首页>Unity opens the explorer from the inspector interface, selects and records the file path
Unity opens the explorer from the inspector interface, selects and records the file path
2022-07-04 07:18:00 【Unity tool man】
stay AvProVideo There are functions in the plug-in , Click the button in the video component to open the Explorer window , Find the target video resource and record the resource path .
After checking, it's not difficult to realize , There are two main points
One is unity The built-in method for opening the Explorer
EditorUtility.OpenFilePanel();
The second is to customize the operation of the editor
Implementation process
Script 1: define window 、 Open Explorer
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()
{
// Horizontal layout
GUILayout.BeginHorizontal();
{
GUILayout.Label(" route ", GUILayout.Width(50f));
path = GUILayout.TextField(path);
if (GUILayout.Button(" Browse ", GUILayout.Width(50f)))
{
// You don't need the pop-up window above
path = EditorUtility.OpenFilePanel(" It's a success ୧*□*୨", Application.dataPath, "png");
_objectBuilderScript.GetComponent<ObjectBuilderScript>().path = path;
}
}
GUILayout.EndHorizontal();
}
}
Script 2: Operation class
using UnityEditor;
using UnityEngine;
public class ObjectBuilderScript : MonoBehaviour
{
public string path;
public void BuildObject()
{
Example.Open(gameObject);
}
}
Script 3: Override operation class
This script should be placed in Assets/Editor Under the folder
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(" Select picture resources "))
{
myScript.BuildObject();
}
}
}
You can see that we have defined a button
Popup
Open Explorer
After selecting the file, you can see that the path has been saved
Reference article :https://blog.csdn.net/qq_42139931/article/details/123206376
Reference article :https://wenku.baidu.com/view/1b41bac9561810a6f524ccbff121dd36a32dc422.html
边栏推荐
- Highly paid programmers & interview questions: how does redis of series 119 realize distributed locks?
- [FPGA tutorial case 7] design and implementation of counter based on Verilog
- the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
- Redis interview question set
- win10微软拼音输入法输入文字时候下方不出现中文提示
- 【网络数据传输】基于FPGA的百兆网/兆网千UDP数据包收发系统开发,PC到FPGA
- Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
- How can the old version of commonly used SQL be migrated to the new version?
- 【森城市】GIS数据漫谈(一)
- Experience installing VMware esxi 6.7 under VMware Workstation 16
猜你喜欢
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph
Routing decorator of tornado project
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
【GF(q)+LDPC】基于二值图GF(q)域的规则LDPC编译码设计与matlab仿真
[MySQL transaction]
NLP-文献阅读总结
电脑通过Putty远程连接树莓派
大厂技术专家:架构设计中常用的思维模型
Bottom problem of figure
Master-slave replication principle of MySQL database
随机推荐
Computer connects raspberry pie remotely through putty
rapidjson读写json文件
[Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
请问旧版的的常用SQL怎么迁移到新版本里来?
[FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
Summary of MySQL common judgment functions!! Have you used it
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
由于dms升级为了新版,我之前的sql在老版本的dms中,这种情况下,如何找回我之前的sql呢?
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
jdbc连接es查询的时候,有遇到下面这种情况的大神嘛?
Selection (022) - what is the output of the following code?
【FPGA教程案例7】基于verilog的计数器设计与实现
Latex中的单引号,双引号如何输入?
电子协会 C语言 1级 34 、分段函数
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
Implementation of ZABBIX agent active mode
Rhcsa day 3