当前位置:网站首页>[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 .
边栏推荐
- CDC synchronization if the primary key of a database table changes, will it be synchronized into two data or will it be synchronized to update the primary key?
- 【编解码】从零开始写H264解码器(1) 总纲
- RemoteViews的作用及原理
- What is the difference between internal oscillator, passive crystal oscillator and active crystal oscillator?
- Data analysis learning notes
- Still using simpledateformat for time formatting? Be careful that the project collapses!
- AcWing 608. Poor (implemented in C language)
- [vi/vim] basic usage and command summary
- 什么是泛型,怎么使用泛型分析
- KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
猜你喜欢

自定义标题栏View

EMC RS485接口EMC电路设计方案

Redis 原理 - List

RemoteViews布局和类型限制源码分析

Custom title bar view

Leetcode 48. 旋转图像(可以,已解决)

Database Series: is there any way to seamlessly upgrade the business tables of the database
![[Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination](/img/06/df5a64441814c9ecfa2f039318496e.jpg)
[Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination

【Unity编辑器扩展实践】、利用txt模板动态生成UI代码

【Unity编辑器扩展基础】、EditorGUILayout (一)
随机推荐
6. calculation index
3. seat number
Django -- MySQL database reflects the mapping data model to models
[Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques
AcWing 610. Salary and bonus (implemented in C language)
[C language] use of file read / write function
AcWing 607. Average 2 (implemented in C language)
Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
Redis principle - List
來吧元宇宙,果然這熱度一時半會兒過不去了
Map排序工具类
如何获取泛型的类型
Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration
AcWing 604. Area of circle (implemented in C language)
AsyncTask经验小结
Cohere, a large model company, completed the round B financing of US $125million
真正的学懂三极管入门篇(经典)「建议收藏」
4. maximum continuity factor
多维度监控:智能监控的数据基础