当前位置:网站首页>[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 .
边栏推荐
- 设置Canvas的 overrideSorting不生效
- 智联招聘基于 Nebula Graph 的推荐实践分享
- Remoteviews layout and type restriction source code analysis
- 【Unity编辑器扩展实践】、利用txt模板动态生成UI代码
- Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
- 【Unity编辑器扩展基础】、GUILayout
- 什么是泛型,怎么使用泛型分析
- 多维度监控:智能监控的数据基础
- AGCO AI frontier promotion (2.16)
- [C language] use of nested secondary pointer of structure
猜你喜欢

EMC RS485 interface EMC circuit design scheme

SEO优化的许多好处是与流量有直接关系
![[vi/vim] basic usage and command summary](/img/bc/0be3ae3f122c3c21b480e0678095a1.png)
[vi/vim] basic usage and command summary

【C语言】关于scanf()与scanf_s()的一些问题

Graphics view framework for QT learning (to realize startup animation)

【Unity编辑器扩展基础】、EditorGUILayout (一)
Three ways to implement LRU cache (recommended Collection)

websocket 1 分钟自动断开连接

Share the easy-to-use fastadmin open source system - practical part

What is data compliance? How to achieve data compliance?
随机推荐
什么是数据合规?怎样做到数据合规?
cdc同步 如果数据库表的主键发生了变化,会同步成两个数据 还是会同步更新主键呢?
Pyqt5 visual development
URL append parameter method, considering #$ Situation of
.NET混合开发解决方案24 WebView2对比CefSharp的超强优势
自定义标题栏View
MapReduce项目案例1
UGUI使用小技巧(五) Scroll Rect组件的使用
Django -- MySQL database reflects the mapping data model to models
【Unity编辑器扩展基础】、EditorGUILayout(二)
女子高考落榜读专科逆袭买千万别墅,考得不好真的没关系
Asynctask experience summary
JNI confusion of Android Application Security
AcWing 605. Simple product (implemented in C language)
Batch will png . bmp . JPEG format pictures are converted to Jpg format picture
【C语言】结构体嵌套二级指针的使用
【Unity编辑器扩展基础】、EditorGUILayout (一)
Int~long long indicates the maximum and minimum number
Cohere, a large model company, completed the round B financing of US $125million
IDEA全局搜索快捷设置