当前位置:网站首页>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
边栏推荐
- Summary of June 2022
- CMS source code of multi wechat management system developed based on thinkphp6, with one click curd and other functions
- [FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
- A real penetration test
- How to buy financial products in 2022?
- [kubernetes series] kubesphere is installed on kubernetes
- [network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
- How notepad++ counts words
- Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
- Rhcsa day 3
猜你喜欢
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
[Mori city] random talk on GIS data (I)
Introduction to rce in attack and defense world
Routing decorator of tornado project
Unity 从Inspector界面打开资源管理器选择并记录文件路径
Selenium driver ie common problem solving message: currently focused window has been closed
Transition technology from IPv4 to IPv6
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
Introduction to spark core components
【Kubernetes系列】Kubernetes 上安装 KubeSphere
随机推荐
com. alibaba. nacos. api. exception. NacosException
Industrial computer anti-virus
Implementation of ZABBIX agent active mode
Routing decorator of tornado project
The most effective futures trend strategy: futures reverse merchandising
Technical experts from large factories: common thinking models in architecture design
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
[Valentine's day] - you can change your love and write down your lover's name
Lottery system test report
Finishing (III) - Exercise 2
【FPGA教程案例8】基于verilog的分频器设计与实现
Summary of June 2022
Introduction to spark core components
由于dms升级为了新版,我之前的sql在老版本的dms中,这种情况下,如何找回我之前的sql呢?
2022 - 021arts: début du deuxième semestre
tornado之目录
在已经知道表格列勾选一个显示一列
tornado项目之路由装饰器
js 常用时间处理函数
《剑指Offer》第2版——力扣刷题