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; }

浙公网安备 33010602011771号