一月末黑的博客

不会程序的美术不是好策划~一个美术学代码用来做笔记的地方

导航

Unity扩展编辑器学习笔记--从路径下找到拥有某个组件类型的预设

5 public static List<T> GetAssetsWithScript<T>(string path) where T:MonoBehaviour
 6         {
 7             T tmp;
 8             string assetPath;
 9             GameObject asset;
10             List<T> assetList = new List<T> ();
11             string[] guids = AssetDatabase.FindAssets ("t:Prefab", new string[] {path});
12             for (int i = 0; i < guids.Length; i++) 
13             {
14                 assetPath = AssetDatabase.GUIDToAssetPath (guids[i]);
15                 asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject;
16                 tmp = asset.GetComponent<T> ();
17                 if (tmp != null) 
18                 {
19                     assetList.Add (tmp);
20                 }
21             }
22             return assetList;
23         }

 

posted on 2016-09-11 16:37  一月末黑  阅读(767)  评论(0编辑  收藏  举报