当前位置:网站首页>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
边栏推荐
- Directory of tornado
- Design of test cases
- 响应式——媒体查询
- The important role of host reinforcement concept in medical industry
- Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
- How to buy financial products in 2022?
- Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
- Literature collation and thesis reading methods
- 【森城市】GIS数据漫谈(一)
- 请问旧版的的常用SQL怎么迁移到新版本里来?
猜你喜欢
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
关于IDEA如何设置快捷键集
Node connection MySQL access denied for user 'root' @ 'localhost' (using password: yes
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
用于压缩视频感知增强的多目标网络自适应时空融合
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
移动适配:vw/vh
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
Zephyr 学习笔记1,threads
Status of the thread
随机推荐
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
Since DMS is upgraded to a new version, my previous SQL is in the old version of DMS. In this case, how can I retrieve my previous SQL?
【FreeRTOS】FreeRTOS學習筆記(7)— 手寫FreeRTOS雙向鏈錶/源碼分析
A new understanding of how to encrypt industrial computers: host reinforcement application
The important role of host reinforcement concept in medical industry
Routing decorator of tornado project
Directory of tornado
What is industrial computer encryption and how to do it
Set JTAG fuc invalid to normal IO port
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
The number of patent applications in China has again surpassed that of the United States and Japan, ranking first in the world for 11 consecutive years
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
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
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
Computer connects raspberry pie remotely through putty
tornado之目录
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
Four sets of APIs for queues
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture