【封装】Unity编辑器模式GUID加载资源

介绍

在编辑器模式下通过GUID 获取工程目录下的指定资源的接口工具封装

工具原理
  • 借助AssetDatabaseAPI
    • FindAssets : 获取 GUID
    • GUIDToAssetPath : 通过GUID获取路径
    • LoadAssetAtPath<T>: 通过路径加载资源
代码:
csharp 复制代码
public static class GetAssetUtil
{
    public static void GetAsset<T>(String[] folderPaths,Action<T> action) where T : UnityEngine.Object
    {
        var guids = AssetDatabase.FindAssets($"t:{typeof(T).Name}",folderPaths);
        foreach (var guid in guids)
        {
            var path = AssetDatabase.GUIDToAssetPath(guid);
            var asset = AssetDatabase.LoadAssetAtPath<T>(path);
            if (asset!= null)
            {
                action(asset);
            }
        }
    }
}
相关推荐
LONGZETECH8 小时前
无人机实训高成本痛点解法:虚拟仿真实现 70% 耗材损耗下降
大数据·算法·unity·架构·无人机
五仁烧饼21 小时前
Unity Addressables 静默资源策略
游戏·unity·addressables
fanfan_hongyun1 天前
unity 与cad 坐标系映射
unity·游戏引擎
神码编程1 天前
【Unity】 HTFramework框架(七十)MultiChoiceDropdown可多选的下拉菜单
unity·游戏引擎·ugui·dropdown·下拉菜单
淡海水1 天前
15-07-YooAsset面试篇-Unity性能优化与内存管理
java·unity·面试·性能优化·c#·游戏引擎
zhchyun20082 天前
# 【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(03)
unity
淡海水3 天前
15-02-YooAsset面试篇-Unity架构设计与源码
java·unity·面试·c#·游戏引擎·yooasset
郝学胜-神的一滴3 天前
中级OpenGL教程 030:gl_FragCoord解锁区域渲染与深度可视化新姿势
c++·unity·游戏引擎·图形渲染·unreal engine·opengl
ellis19703 天前
u3d插件xLua[四]Lua访问C#源码分析,反射,生成代码
unity