当前位置:网站首页>[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 .
边栏推荐
- Given two points and a point with a middle scale, find the coordinates of the point
- Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
- Function and principle of remoteviews
- .NET混合开发解决方案24 WebView2对比CefSharp的超强优势
- 【编解码】从零开始写H264解码器(1) 总纲
- Build your own website (18)
- SEO优化的许多好处是与流量有直接关系
- 【Unity编辑器扩展基础】、EditorGUILayout (三)
- Mr. Zhang responded to the first live broadcast with goods
- Remoteviews layout and type restriction source code analysis
猜你喜欢
随机推荐
【C语言】NextDay问题
Remoteviews layout and type restriction source code analysis
2018 joint examination of nine provinces & Merging of line segment trees
华泰证券开户安全吗? 开户有风险吗
MapReduce project case 1
Leetcode 705. 设计哈希集合
Android应用安全之JNI混淆
多维度监控:智能监控的数据基础
【附源码+代码注释】误差状态卡尔曼滤波(error-state Kalman Filter),扩展卡尔曼滤波,实现GPS+IMU融合,EKF ESKF GPS+IMU
4. maximum continuity factor
Levels – 虚幻引擎场景制作「建议收藏」
Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
ByteV搭建动态数字孪生网络安全平台----助力网络安全发展
It really doesn't matter if a woman fails to pass the college entrance examination and buys thousands of villas in a counter attack
多维度监控:智能监控的数据基础
30套JSP网站源代码合集「建议收藏」
请问通达信股票软件可靠吗?在上面交易股票安全吗?
Cohere, a large model company, completed the round B financing of US $125million
【经验分享】Django开发中常用到的数据库操作总结
Custom title bar view









