2022-03-03 18:08:32 +08:00
|
|
|
|
# 初始化
|
|
|
|
|
|
|
|
|
|
资源系统的运行模式支持三种:编辑器模拟模式,单机运行模式,联机运行模式。
|
|
|
|
|
|
|
|
|
|
````C#
|
|
|
|
|
// 资源系统初始化方法,根据不同的模式,我们传递不同的创建参数类
|
|
|
|
|
YooAssets.InitializeAsync(CreateParameters parameters);
|
|
|
|
|
````
|
|
|
|
|
|
|
|
|
|
**编辑器模拟模式**
|
|
|
|
|
|
|
|
|
|
在编辑器下,不需要构建资源包,来模拟运行游戏。
|
|
|
|
|
|
|
|
|
|
注意:该模式只在编辑器下起效
|
|
|
|
|
|
|
|
|
|
````c#
|
|
|
|
|
private IEnumerator InitializeYooAsset()
|
|
|
|
|
{
|
2022-05-06 10:00:09 +08:00
|
|
|
|
var createParameters = new YooAssets.EditorSimulateModeParameters();
|
2022-04-14 12:38:20 +08:00
|
|
|
|
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
2022-03-03 19:13:07 +08:00
|
|
|
|
yield return YooAssets.InitializeAsync(createParameters);
|
2022-03-03 18:08:32 +08:00
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|
|
|
|
|
**单机运行模式**
|
|
|
|
|
|
|
|
|
|
对于不需要热更新资源的游戏,可以使用单机运行模式。
|
|
|
|
|
|
|
|
|
|
注意:该模式需要构建资源包
|
|
|
|
|
|
|
|
|
|
````c#
|
|
|
|
|
private IEnumerator InitializeYooAsset()
|
|
|
|
|
{
|
|
|
|
|
var createParameters = new YooAssets.OfflinePlayModeParameters();
|
2022-04-14 12:38:20 +08:00
|
|
|
|
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
2022-03-03 19:13:07 +08:00
|
|
|
|
yield return YooAssets.InitializeAsync(createParameters);
|
2022-03-03 18:08:32 +08:00
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|
|
|
|
|
**联机运行模式**
|
|
|
|
|
|
|
|
|
|
对于需要热更新资源的游戏,可以使用联机运行模式,该模式下初始化参数会很多。
|
|
|
|
|
|
|
|
|
|
注意:该模式需要构建资源包
|
|
|
|
|
|
2022-04-14 12:38:20 +08:00
|
|
|
|
- LocationServices : 资源定位的实例类。
|
2022-04-28 19:25:14 +08:00
|
|
|
|
|
|
|
|
|
(1) 默认的资源定位服务类(DefaultLocationServices)
|
|
|
|
|
|
|
|
|
|
(2) 可寻址的资源定位服务类(AddressLocationServices)
|
|
|
|
|
|
|
|
|
|
(3) 开发者自定义的资源定位服务类,需要提供实现ILocationServices接口的实例类。
|
|
|
|
|
|
2022-03-10 10:18:48 +08:00
|
|
|
|
- DecryptionServices : 如果资源包在构建的时候有加密,需要提供实现IDecryptionServices接口的实例类。
|
2022-04-28 19:25:14 +08:00
|
|
|
|
|
2022-03-03 18:08:32 +08:00
|
|
|
|
- ClearCacheWhenDirty : 安装包在覆盖安装的时候,是否清空沙盒缓存文件夹。
|
2022-04-28 19:25:14 +08:00
|
|
|
|
|
2022-03-03 18:08:32 +08:00
|
|
|
|
- DefaultHostServer : 默认的资源服务器IP地址。
|
2022-04-28 19:25:14 +08:00
|
|
|
|
|
2022-03-03 18:08:32 +08:00
|
|
|
|
- FallbackHostServer : 备用的资源服务器IP地址。
|
|
|
|
|
|
|
|
|
|
````c#
|
|
|
|
|
private IEnumerator InitializeYooAsset()
|
|
|
|
|
{
|
|
|
|
|
var createParameters = new YooAssets.HostPlayModeParameters();
|
2022-04-14 12:38:20 +08:00
|
|
|
|
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
2022-03-10 10:18:48 +08:00
|
|
|
|
createParameters.DecryptionServices = null;
|
2022-03-03 18:08:32 +08:00
|
|
|
|
createParameters.ClearCacheWhenDirty = false;
|
|
|
|
|
createParameters.DefaultHostServer = "http://127.0.0.1/CDN1/Android";
|
|
|
|
|
createParameters.FallbackHostServer = "http://127.0.0.1/CDN2/Android";
|
|
|
|
|
yield return YooAssets.InitializeAsync(createParameters);
|
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|
2022-03-21 23:49:50 +08:00
|
|
|
|
**资源文件解密**
|
|
|
|
|
|
|
|
|
|
````c#
|
|
|
|
|
public class BundleDecryption : IDecryptionServices
|
|
|
|
|
{
|
2022-05-12 12:37:48 +08:00
|
|
|
|
public ulong GetFileOffset()
|
2022-03-21 23:49:50 +08:00
|
|
|
|
{
|
|
|
|
|
return 32;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|