Unity编辑器里查找某一类型的资源
MenuItem 和 ContextMenu
https://blog.csdn.net/wpapa/article/details/51066397
反射与特性,自定义特性
https://www.cnblogs.com/whuanle/p/12182962.html
编辑器里查找某一类型的资源
public static void GetModels(string AssetsPath) { try { ModelConfig modelConfig = AssetDatabase.LoadAssetAtPath<ModelConfig>(Paths.MODELCONFIG_PATH); modelConfig.m_AllModelName.Clear(); DirectoryInfo directoryInfo = new DirectoryInfo(AssetsPath); FileInfo[] fileInfos = directoryInfo.GetFiles("*", SearchOption.AllDirectories); for (int i = 0; i < fileInfos.Length; i++) { if (fileInfos[i].Name.EndsWith(".fbx")) { modelConfig.m_AllModelName.Add(fileInfos[i].Name.Replace(".fbx", "")); } } } catch (System.Exception e) { Debug.LogError($"获取模型失败!{e}"); } } 上面的是正儿八经的判断后缀去获取模型,下面的是通过.FindAssets这个api去查找,返回的是GUID,有通过GUID来得到路径的api,其中传入的参数t:是有含义的,代表根据类型来查找,model代表模型,其他字母的含义请查阅相关api。 try { List<string> modelPath = new List<string>(); string[] allStr = AssetDatabase.FindAssets("t:model", new string[] { pathList }); for (int i = 0; i < allStr.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(allStr[i]); if (allStr.Length > 100) { EditorUtility.DisplayProgressBar("查找模型", "ModelPath:" + path, i * 1.0f / allStr.Length); } modelPath.Add(path); } EditorUtility.ClearProgressBar(); return modelPath; } catch (System.Exception e) { EditorUtility.ClearProgressBar(); Debug.LogError($"查找模型失败{e}!"); return null; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)