当前位置:网站首页>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
边栏推荐
- Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
- kubernetes集群之Label管理
- Chapter 1 programming problems
- 云Redis 有什么用? 云redis怎么用?
- "Sword finger offer" 2nd Edition - force button brush question
- uniapp小程序分包
- Introduction to spark core components
- Selection (021) - what is the output of the following code?
- Check and display one column in the known table column
- Paddleocr prompt error: can not import AVX core while this file exists: xxx\paddle\fluid\core_ avx
猜你喜欢
win10微软拼音输入法输入文字时候下方不出现中文提示
Xcode 14之大变化详细介绍
Zabbix agent主动模式的实现
[MySQL transaction]
【森城市】GIS数据漫谈(一)
[Mori city] random talk on GIS data (I)
tornado项目之路由装饰器
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
Experience installing VMware esxi 6.7 under VMware Workstation 16
[web security] nodejs prototype chain pollution analysis
随机推荐
When JDBC connects to es query, is there a God who meets the following situation?
【FPGA教程案例8】基于verilog的分频器设计与实现
Computer connects raspberry pie remotely through putty
Vulhub vulnerability recurrence 77_ zabbix
[FPGA tutorial case 7] design and implementation of counter based on Verilog
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
【Kubernetes系列】Kubernetes 上安装 KubeSphere
[FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
Xcode 14之大变化详细介绍
JS common time processing functions
Transition technology from IPv4 to IPv6
Rhcsa day 3
The most effective futures trend strategy: futures reverse merchandising
tornado项目之路由装饰器
Uniapp applet subcontracting
Boast about Devops
leetcode825. Age appropriate friends
2022 - 021arts: début du deuxième semestre
rapidjson读写json文件
Selection (021) - what is the output of the following code?