当前位置:网站首页>[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 .
边栏推荐
- Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed
- 【JS】斐波那契数列实现(递归与循环)
- 吐血推荐17个提升开发效率的“轮子”
- Levels – virtual engine scene production "suggestions collection"
- AcWing 608. Poor (implemented in C language)
- [C language] use of file read / write function
- Is it feasible to be a programmer at the age of 26?
- 案例驱动 :从入门到掌握Shell编程详细指南
- In less than an hour, apple destroyed 15 startups
- Prepare for Jin San Yin Si I. testers without experience in automated testing projects should look at it quickly
猜你喜欢

Prefix and (2D)

2018 joint examination of nine provinces & Merging of line segment trees

【vi/vim】基本使用及命令汇总
![[C language] about scanf() and scanf_ Some problems of s()](/img/d1/e3d0b845e699c8c1fe3eb9f3b250e1.png)
[C language] about scanf() and scanf_ Some problems of s()

【C语言】如何产生正态分布或高斯分布随机数

KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"

【C语言】随机数文件对其进行三种排序方法

【C语言】NextDay问题

智联招聘基于 Nebula Graph 的推荐实践分享

【Unity编辑器扩展实践】、利用txt模板动态生成UI代码
随机推荐
【C语言】如何很好的实现复数类型
Data analysis learning notes
AcWing 606. Average 1 (implemented in C language)
Remoteviews layout and type restriction source code analysis
【JS】斐波那契数列实现(递归与循环)
1. print hourglass
Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques
Share the easy-to-use fastadmin open source system - practical part
【经验分享】Django开发中常用到的数据库操作总结
UGUI使用小技巧(六)Unity实现字符串竖行显示
MapReduce project case 3 - temperature statistics
什么是泛型,怎么使用泛型分析
多维度监控:智能监控的数据基础
Is it feasible to be a programmer at the age of 26?
【Unity编辑器扩展实践】、通过代码查找所有预制
IO stream of file and Base64
【C语言】结构体嵌套二级指针的使用
Levels – 虚幻引擎场景制作「建议收藏」
【北京航空航天大学】考研初试复试资料分享
It really doesn't matter if a woman fails to pass the college entrance examination and buys thousands of villas in a counter attack