当前位置:网站首页>[unity Editor Extension practice], find all prefabrications through code
[unity Editor Extension practice], find all prefabrications through code
2022-06-28 12:21:00 【Unique_ eight hundred and forty-nine million nine hundred and n】
stay Unity Editor extensions in , Usually, I will add, delete, modify and check files , Here are two Unity Find prefabricated methods in , The same goes for other documents .
1、 utilize AssetDatabase Find prefabrication :
adopt AssetDatabase Of FindAssets Method can find all the files guid, Parameters filter Is a filter character . Namely Unity in Project The two buttons on the right side of the search bar under the window pop up ,t The sign is Type,l The sign is lable.( Such as "Prefab t:Prefab" Is the name with Prefab Prefabrication of , This parameter is the same as here )

Parameters searchInFolders Is the relative path of the folder ( No path is in the project Assets The lookup ).
then use GUIDToAssetPath Find the prefabricated path , Reuse LoadAssetAtPath Load as GameObject.
public static List<GameObject> GetAllPrefabByAssetDatabase(params string[] path)
{
List<GameObject> _prefabList = new List<GameObject>();
string[] _guids = AssetDatabase.FindAssets("t:Prefab", path);
string _prefabPath = "";
GameObject _prefab;
foreach (var _guid in _guids)
{
_prefabPath = AssetDatabase.GUIDToAssetPath(_guid);
_prefab = AssetDatabase.LoadAssetAtPath(_prefabPath, typeof(GameObject)) as GameObject;
_prefabList.Add(_prefab);
}
return _prefabList;
}2、 utilize Directory Find files :
Directory and AssetDatabase Empathy , It is only used here Directory Of GetFiles Method to find the prefabrication path ,
path: Relative paths ,
searchPattern:? matching 0 Or a character ,* matching 0 Live multiple characters .
public static List<GameObject> GetAllPrefabByDirectory(string path)
{
string[] files = Directory.GetFiles(path, "*.prefab", SearchOption.AllDirectories);
List<GameObject> _prefabList = new List<GameObject>();
GameObject _prefab;
foreach (var _path in files)
{
_prefab = AssetDatabase.LoadAssetAtPath(_path, typeof(GameObject)) as GameObject;
_prefabList.Add(_prefab);
}
return _prefabList;
}Expand small knowledge :
Generally, the prefabrication obtained by these two methods is the same , But there is one case where there is a difference . stay Unity Of Assets Next create a folder , When naming, enter two points in front of the file name , Such as :..Prefab. You'll find out Unity Of Project Next , You will not see this folder and the files in it . In this case, if Directory.GetFiles Will get the path of the file , But use AssetDatabase.LoadAssetAtPath It cannot be loaded when loading .
All the prefabrications are found here , The same goes for other resources .
边栏推荐
- [C language] use of file read / write function
- websocket 1 分钟自动断开连接
- 多维度监控:智能监控的数据基础
- Batch will png . bmp . JPEG format pictures are converted to Jpg format picture
- 【Unity编辑器扩展基础】、EditorGUILayout(二)
- Many benefits of SEO optimization are directly related to traffic
- AGCO AI frontier promotion (2.16)
- Zero basic C language (I)
- UGUI使用小技巧(五) Scroll Rect组件的使用
- NFT数字藏品系统开发(3D建模经济模型开发案例)
猜你喜欢

Data analysis learning notes

Software test interview classic + 1000 high-frequency real questions, and the hit rate of big companies is 80%

Django -- MySQL database reflects the mapping data model to models

.NET混合开发解决方案24 WebView2对比CefSharp的超强优势

What is the difference between internal oscillator, passive crystal oscillator and active crystal oscillator?

不到一小时,苹果摧毁了15家初创公司

【Unity编辑器扩展基础】、EditorGUILayout (三)

Still using simpledateformat for time formatting? Be careful that the project collapses!

JNI confusion of Android Application Security

开源项目维权成功案例: spug 开源运维平台成功维权
随机推荐
Daily practice of C language - day 3: calculate the number of occurrences of sub strings of strings
Convert black mask picture to color annotation file
【Unity编辑器扩展实践】、查找所有引用该图片的预制体
零基础C语言(一)
【C语言】结构体嵌套二级指针的使用
Bisection (integer bisection and floating point bisection)
Source code analysis of ArrayList
Research on personalized product search
Custom title bar view
UGUI使用小技巧(六)Unity实现字符串竖行显示
AGCO AI frontier promotion (2.16)
Remoteviews layout and type restriction source code analysis
MapReduce项目案例3——温度统计
How to deploy the software testing environment?
Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting
NFT数字藏品系统开发(3D建模经济模型开发案例)
关于字符串转换的一些小技巧
案例驱动 :从入门到掌握Shell编程详细指南
Django -- MySQL database reflects the mapping data model to models
【附源码+代码注释】误差状态卡尔曼滤波(error-state Kalman Filter),扩展卡尔曼滤波,实现GPS+IMU融合,EKF ESKF GPS+IMU