简易资源加载框架

目录

[TOC]

一、写在前面

从零开始搭建一个简易资源加载框架,之后再慢慢扩展和完善。

目前版本不太适合多人协作开发使用,适合独立制作使用。

欢迎大家访问我的 GitHub 来下载小工具,或者 百度网盘(提取码:w9nv)

包含有以下功能

picture1

二、积累常用 API

1.编辑器模式下的资源加载 API

(1)GetAssetPathsFromAssetBundleAndAssetName()

通过 AB 包名和 Asset 名获取资源路径(string[])

UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(string abName,string assetName)

(2)LoadAssetAtPath<UnityEngine.Object>()

根据资源路径加载资源

UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(string assetPath)

2.真机运行下的资源加载 API

(1)AssetBundle.LoadFromFile()

通过 AB 包路径加载 AB 包

AssetBundle.LoadFromFile(string abPath)

(2)AssetBundle.LoadAsset()

通过 Asset 名从 AB 包中加载资源

AssetBundle.LoadAsset(string assetName)

3.AssetBundle 相关 API

(1)BuildPipeline.BuildAssetBundles()

Build AB 包

BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget)

BuildAssetBundleOptions.ChunkBasedCompression:使用LZ4压缩,中等压缩比,可按需分块解压

(2)AssetBundleManifest.GetDirectDependencies()

获取 AB 包的直接依赖(string[])

AssetBundleManifest.GetDirectDependencies(string abName)

4.其他 API

(1)Menu.SetChecked()

设置菜单是否checked

Menu.SetChecked(string menuPath,bool isChecked)

(2)Directory.Exits()

文件夹是否存在

Directory.Exits(string directoryPath)

(3)Directory.CreateDirectory()

创建文件夹

Directory.CreateDirectory(string directoryPath)

(4)UnityEditor.AssetDatabase.Refresh()

刷新

UnityEditor.AssetDatabase.Refresh()

三、框架设计

四、实现

五、待完善

六、写在最后

还在更新中…