Unity通过Resources.LoadAll读取指定的资源类型并返回资源列表

 

 1 /// <summary>
 2 /// 读取资源
 3 /// </summary>
 4 /// <typeparam name="T">限制为UnityEngine.Object</typeparam>
 5 /// <param name="_path">资源路径</param>
 6 /// <returns>读取到的资源列表</returns>
 7 public static List<T> LoadSources<T>(string _path) where T : UnityEngine.Object
 8 {
 9   List<T> _sourcesList = new List<T>();
10    var _getSources = Resources.LoadAll(_path);
11    foreach (var sources in _getSources)
12    {
13       _sourcesList.Add(sources as T);
14    }
15    return _sourcesList;
16 }

 

posted @ 2022-01-12 11:32  法小鱿  阅读(837)  评论(0编辑  收藏  举报