当前位置:网站首页>[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 .
边栏推荐
- 【编解码】从零开始写H264解码器(1) 总纲
- [C language] about scanf() and scanf_ Some problems of s()
- Levels – virtual engine scene production "suggestions collection"
- Pyqt5 visual development
- PrecomputedTextCompat用法及原理
- Two writing methods of JNI function
- AcWing 607. Average 2 (implemented in C language)
- 真正的学懂三极管入门篇(经典)「建议收藏」
- Difference (one dimension)
- 4. maximum continuity factor
猜你喜欢

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

多维度监控:智能监控的数据基础

If you want to change to software testing, how can you package your resume as a test engineer with 1 year of work experience

深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...

建立自己的网站(18)

KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
Using MySQL database in the express framework of node

【C语言】二叉树的实现及三种遍历

Source code analysis of ArrayList

Convert black mask picture to color annotation file
随机推荐
【经验分享】Django开发中常用到的数据库操作总结
websocket 1 分钟自动断开连接
Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting
2018 joint examination of nine provinces & Merging of line segment trees
【C语言】判断三角形
Redis principle - List
.NET混合开发解决方案24 WebView2对比CefSharp的超强优势
UGUI强制刷新Layout(布局)组件
Share the easy-to-use fastadmin open source system - practical part
Map排序工具类
[source code + code comments] error state Kalman filter, extended Kalman filter, gps+imu fusion, EKF eskf gps+imu
Prefix and (one dimension)
Research on personalized product search
IO stream of file and Base64
【C语言】文件读写函数使用
AcWing 605. Simple product (implemented in C language)
Convert black mask picture to color annotation file
Url追加参数方法,考虑#、?、$的情况
URL append parameter method, considering #$ Situation of
How to get a generic type