当前位置:网站首页>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
边栏推荐
- Lottery system test report
- Novel website program source code that can be automatically collected
- Set JTAG fuc invalid to normal IO port
- Selection (023) - what are the three stages of event propagation?
- Introduction to rce in attack and defense world
- [freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
- [network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
- Xcode 14之大变化详细介绍
- Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
- Uniapp applet subcontracting
猜你喜欢

Experience installing VMware esxi 6.7 under VMware Workstation 16
![[Valentine's day] - you can change your love and write down your lover's name](/img/ab/402872ad39f9dc58fd27dd6fc823ef.jpg)
[Valentine's day] - you can change your love and write down your lover's name

How notepad++ counts words

The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native

Master-slave replication principle of MySQL database

响应式移动Web测试题

Chain ide -- the infrastructure of the metauniverse

Rhcsa the next day

用于压缩视频感知增强的多目标网络自适应时空融合

BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
随机推荐
The final week, I split
Why does the producer / consumer mode wait () use while instead of if (clear and understandable)
How to buy financial products in 2022?
[freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
uniapp小程序分包
About how idea sets up shortcut key sets
输入年份、月份,确定天数
2022年6月小结
Novel website program source code that can be automatically collected
[thread pool]
2022 - 021arts: début du deuxième semestre
电子协会 C语言 1级 34 、分段函数
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
大厂技术专家:架构设计中常用的思维模型
Xcode 14之大变化详细介绍
Summary of MySQL common judgment functions!! Have you used it
Routing decorator of tornado project
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
Lottery system test report