[toc]

# 概要

对于 Unity 中的热更新而言,Assetbundle 是必不可少的。从而对于 Assetbundle 的控制也是必不可少的. GameFramework 独立实现了一套 ResourceManager, 这套控制器可以实现 AB 打包的彻底配置化。本文将分几个阶段进行 * 介绍如何实现 GF 框架内 ResourceManager 的配置信息自定义 * 介绍其实现逻辑

# 配置 ResourceManager

官方文档: https://gameframework.cn/uncategorized/%e4%bd%bf%e7%94%a8-assetbundle-%e7%bc%96%e8%be%91%e5%99%a8/ 参考官方文档,可以发现对于 ResourceManager 最重要的是一个配置文件
* AssetBundleEditor.xml 但是新的 GF 框架里这部分是需要自己配置的,具体需要结合 StarForce 这个项目一起看.
这里介绍新版里如何自定义配置 AssetBundleEditor.xml

# 找到配置路径

如上图所示,EditorXml 的配置路径在 ResourceBuilderController.cs/43行

1
m_ConfigurationPath = Type.GetConfigurationPath<ResourceBuilderConfigPathAttribute>() ?? Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameFramework/Configs/ResourceBuilder.xml"));

即,它会先从一个 特性 中尝试获取路径,如果为空,则会使用默认的路径. GameFramework/Configs/ResourceBuilder.xml .

# 实现自定义配置

由上知,我们如果想要实现自定义配置的话。需要声明一个变量,并用 ResourceBuilderConfigPathAttribute 特性进行装饰.

下面这个代码可以直接实现自定义配置 **(需要放到 Editor 目录下)**

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using System.IO;
using GameFramework;
using UnityEngine;
using UnityGameFramework.Editor;
using UnityGameFramework.Editor.ResourceTools;

public enum BuildSchema
{
Demo,
Furry
}

namespace FurryGF.Editor
{
public static class FurryGFConfig
{
[BuildSettingsConfigPath]
public static string BuildSettingsConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, GetResourceEditorXmlPath("BuildSettings")));

[ResourceCollectionConfigPath]
public static string ResourceCollectionConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, GetResourceEditorXmlPath("Collection")));

[ResourceEditorConfigPath]
public static string ResourceEditorConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, GetResourceEditorXmlPath("Editor")));

[ResourceBuilderConfigPath]
public static string ResourceBuilderConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, GetResourceEditorXmlPath("Builder")));
/// <summary>
/// 获取默认的AssetBundle配置地址,根据不同打包方案确定
/// </summary>
/// <param name="schema"></param>
/// <returns></returns>
public static string GetResourceEditorXmlPath(string name,BuildSchema schema=BuildSchema.Furry){
switch (schema)
{
case BuildSchema.Demo:
return "AssetsData/Config/Resource"+name+"_Demo.xml";
break;
case BuildSchema.Furry:
return "AssetsData/Config/Resource"+name+"_Furry.xml";
break;
default:
return "AssetsData/Config/Resource"+name+"_Furry.xml";
}
}
}
}

然后编辑对应的配置文件即可,目前总共四个,其中 ResourceEditor_Furry.xml 主要决定 ResoureTools 会预览的资源文件存放的路径