(client) feat:添加键值对式加载资源函数
This commit is contained in:
@ -258,5 +258,31 @@ namespace Configs
|
||||
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 用于加载指定路径下的所有资源,并返回资源名称和加载好的资源的键值对。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">资源类型</typeparam>
|
||||
/// <param name="path">资源路径(相对于 Resources 文件夹)</param>
|
||||
/// <returns>字典,键为资源名称,值为加载好的资源</returns>
|
||||
public static Dictionary<string, T> LoadResources<T>(string path) where T : UnityEngine.Object
|
||||
{
|
||||
// 创建一个字典来存储资源名称和加载好的资源
|
||||
Dictionary<string, T> resourceDict = new Dictionary<string, T>();
|
||||
|
||||
// 加载指定路径下的所有资源
|
||||
T[] resources = Resources.LoadAll<T>(path);
|
||||
|
||||
foreach (T resource in resources)
|
||||
{
|
||||
if (resource != null)
|
||||
{
|
||||
// 获取资源名称并存入字典
|
||||
string resourceName = resource.name;
|
||||
resourceDict[resourceName] = resource;
|
||||
}
|
||||
}
|
||||
|
||||
return resourceDict;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user