当前位置:网站首页>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
- Electronic Association C language level 1 35, bank interest
- [FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
- Responsive - media query
- 响应式——媒体查询
- Design of test cases
- Mobile adaptation: vw/vh
- Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
- How to input single quotation marks and double quotation marks in latex?
- Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
猜你喜欢
电脑通过Putty远程连接树莓派
Transition technology from IPv4 to IPv6
Responsive mobile web test questions
Valentine's Day is coming! Without 50W bride price, my girlfriend was forcibly dragged away...
Selenium driver ie common problem solving message: currently focused window has been closed
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
Responsive - media query
Implementation of ZABBIX agent active mode
Mobile adaptation: vw/vh
用于压缩视频感知增强的多目标网络自适应时空融合
随机推荐
Introduction to spark core components
Selenium ide plug-in download, installation and use tutorial
在所有SwiftUI版本(1.0-4.0)中原生实现Charts图表视图之思路
Splicing plain text into JSON strings - easy language method
Selection (023) - what are the three stages of event propagation?
《剑指Offer》第2版——力扣刷题
Status of the thread
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
[thread pool]
The difference between synchronized and lock
How can the old version of commonly used SQL be migrated to the new version?
由于dms升级为了新版,我之前的sql在老版本的dms中,这种情况下,如何找回我之前的sql呢?
关于IDEA如何设置快捷键集
Directory of tornado
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
"Sword finger offer" 2nd Edition - force button brush question
云Redis 有什么用? 云redis怎么用?
Rhcsa the next day
Selection (022) - what is the output of the following code?
2022-021ARTS:下半年开始