码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-09-11 17:02:03      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

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         }

 

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

标签:

原文地址:http://www.cnblogs.com/heizai/p/5862079.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!