Update samples
This commit is contained in:
@@ -28,9 +28,16 @@ public class BattleRoom : MonoBehaviour
|
||||
"asteroid01", "asteroid02", "asteroid03", "enemy_ship"
|
||||
};
|
||||
|
||||
private AssetOperationHandle _panelHandle;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
var canvas = GameObject.Find("Canvas");
|
||||
_panelHandle = YooAssets.LoadAssetSync<GameObject>("UIBattle");
|
||||
var go = _panelHandle.InstantiateSync(canvas.transform);
|
||||
go.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
@@ -44,6 +51,12 @@ public class BattleRoom : MonoBehaviour
|
||||
void OnDestroy()
|
||||
{
|
||||
Instance = null;
|
||||
|
||||
if(_panelHandle != null)
|
||||
{
|
||||
_panelHandle.Release();
|
||||
_panelHandle = null;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator SpawnWaves()
|
||||
|
||||
+17
-24
@@ -5,23 +5,20 @@ using YooAsset;
|
||||
using Better.StreamingAssets;
|
||||
using System.IO;
|
||||
|
||||
public class BootScene : MonoBehaviour
|
||||
public class GameBoot : MonoBehaviour
|
||||
{
|
||||
public static BootScene Instance { private set; get; }
|
||||
public static EPlayMode GamePlayMode;
|
||||
public static GameBoot Instance;
|
||||
|
||||
public EPlayMode PlayMode = EPlayMode.EditorSimulateMode;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Debug.Log($"资源系统运行模式:{PlayMode}");
|
||||
Instance = this;
|
||||
|
||||
Application.targetFrameRate = 60;
|
||||
Application.runInBackground = true;
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
Instance = null;
|
||||
|
||||
DontDestroyOnLoad(this.gameObject);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
@@ -31,9 +28,6 @@ public class BootScene : MonoBehaviour
|
||||
|
||||
IEnumerator Start()
|
||||
{
|
||||
GamePlayMode = PlayMode;
|
||||
Debug.Log($"资源系统运行模式:{PlayMode}");
|
||||
|
||||
// 初始化BetterStreaming
|
||||
BetterStreamingAssets.Initialize();
|
||||
|
||||
@@ -41,39 +35,37 @@ public class BootScene : MonoBehaviour
|
||||
YooAssets.Initialize();
|
||||
|
||||
// 创建默认的资源包
|
||||
var defaultPackage = YooAssets.CreateAssetsPackage("DefaultPackage");
|
||||
|
||||
// 设置该资源包为默认的资源包
|
||||
YooAssets.SetDefaultAssetsPackage(defaultPackage);
|
||||
var package = YooAssets.CreateAssetsPackage("DefaultPackage");
|
||||
YooAssets.SetDefaultAssetsPackage(package);
|
||||
|
||||
// 编辑器下的模拟模式
|
||||
if (PlayMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
var createParameters = new EditorSimulateModeParameters();
|
||||
createParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild("DefaultPackage");
|
||||
yield return defaultPackage.InitializeAsync(createParameters);
|
||||
yield return package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
// 单机运行模式
|
||||
if (PlayMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var createParameters = new OfflinePlayModeParameters();
|
||||
createParameters.DecryptionServices = new BundleDecryptionServices();
|
||||
yield return defaultPackage.InitializeAsync(createParameters);
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
yield return package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
// 联机运行模式
|
||||
if (PlayMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
var createParameters = new HostPlayModeParameters();
|
||||
createParameters.DecryptionServices = new BundleDecryptionServices();
|
||||
createParameters.QueryServices = new QueryStreamingAssetsFileServices();
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.QueryServices = new GameQueryServices();
|
||||
createParameters.DefaultHostServer = GetHostServerURL();
|
||||
createParameters.FallbackHostServer = GetHostServerURL();
|
||||
yield return defaultPackage.InitializeAsync(createParameters);
|
||||
yield return package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
// 运行补丁流程
|
||||
// 运行资源更新流程
|
||||
PatchManager.Run();
|
||||
}
|
||||
|
||||
@@ -103,7 +95,8 @@ public class BootScene : MonoBehaviour
|
||||
return $"{hostServerIP}/CDN/PC/{gameVersion}";
|
||||
#endif
|
||||
}
|
||||
private class QueryStreamingAssetsFileServices : IQueryServices
|
||||
|
||||
private class GameQueryServices : IQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string fileName)
|
||||
{
|
||||
@@ -112,7 +105,7 @@ public class BootScene : MonoBehaviour
|
||||
return BetterStreamingAssets.FileExists($"{buildinFolderName}/{fileName}");
|
||||
}
|
||||
}
|
||||
private class BundleDecryptionServices : IDecryptionServices
|
||||
private class GameDecryptionServices : IDecryptionServices
|
||||
{
|
||||
public ulong LoadFromFileOffset(DecryptFileInfo fileInfo)
|
||||
{
|
||||
+4
-1
@@ -2,13 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 清理未使用的缓存文件
|
||||
/// </summary>
|
||||
internal class FsmClearCache : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmClearCache);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
Debug.Log("清理未使用的缓存文件!");
|
||||
Debug.Log("开始清理未使用的缓存文件!");
|
||||
var package = YooAsset.YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var operation = package.ClearPackageUnusedCacheFilesAsync();
|
||||
operation.Completed += Operation_Completed;
|
||||
|
||||
+5
-2
@@ -3,14 +3,18 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件下载器
|
||||
/// </summary>
|
||||
public class FsmCreateDownloader : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmCreateDownloader);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
Debug.Log("创建补丁下载器!");
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.CreateDownloader);
|
||||
BootScene.Instance.StartCoroutine(CreateDownloader());
|
||||
GameBoot.Instance.StartCoroutine(CreateDownloader());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
@@ -23,7 +27,6 @@ public class FsmCreateDownloader : IFsmNode
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
Debug.Log("创建补丁下载器.");
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
PatchManager.Downloader = YooAssets.CreatePatchDownloader(downloadingMaxNum, failedTryAgain);
|
||||
|
||||
+6
-1
@@ -1,14 +1,19 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 下载更新文件
|
||||
/// </summary>
|
||||
public class FsmDownloadFiles : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmDownloadFiles);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
Debug.Log("开始下载补丁文件!");
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.DownloadWebFiles);
|
||||
BootScene.Instance.StartCoroutine(BeginDownload());
|
||||
GameBoot.Instance.StartCoroutine(BeginDownload());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
|
||||
+4
-2
@@ -2,15 +2,17 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 更新完毕
|
||||
/// </summary>
|
||||
internal class FsmPatchDone : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmPatchDone);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.PatchDone);
|
||||
Debug.Log("补丁流程更新完毕!");
|
||||
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.PatchDone);
|
||||
FsmManager.Transition(nameof(FsmClearCache));
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
|
||||
+4
-8
@@ -2,6 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化工作
|
||||
/// </summary>
|
||||
internal class FsmPatchInit : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmPatchInit);
|
||||
@@ -12,7 +15,7 @@ internal class FsmPatchInit : IFsmNode
|
||||
var go = Resources.Load<GameObject>("PatchWindow");
|
||||
GameObject.Instantiate(go);
|
||||
|
||||
BootScene.Instance.StartCoroutine(Begin());
|
||||
FsmManager.Transition(nameof(FsmUpdateVersion));
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
@@ -20,11 +23,4 @@ internal class FsmPatchInit : IFsmNode
|
||||
void IFsmNode.OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
private IEnumerator Begin()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
FsmManager.Transition(nameof(FsmUpdateVersion));
|
||||
}
|
||||
}
|
||||
+3
@@ -2,6 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 开始游戏
|
||||
/// </summary>
|
||||
internal class FsmStartGame : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmStartGame);
|
||||
|
||||
+5
-2
@@ -3,14 +3,18 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 更新补丁清单
|
||||
/// </summary>
|
||||
public class FsmUpdateManifest : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmUpdateManifest);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
Debug.Log("开始更新资源版本清单!");
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.UpdateManifest);
|
||||
BootScene.Instance.StartCoroutine(UpdateManifest());
|
||||
GameBoot.Instance.StartCoroutine(UpdateManifest());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
@@ -23,7 +27,6 @@ public class FsmUpdateManifest : IFsmNode
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
// 更新补丁清单
|
||||
var package = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var operation = package.UpdatePackageManifestAsync(PatchManager.PackageVersion, 30);
|
||||
yield return operation;
|
||||
|
||||
+5
-2
@@ -3,14 +3,18 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 更新资源版本号
|
||||
/// </summary>
|
||||
internal class FsmUpdateVersion : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmUpdateVersion);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
Debug.Log("开始获取资源版本号!");
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.UpdateStaticVersion);
|
||||
BootScene.Instance.StartCoroutine(GetStaticVersion());
|
||||
GameBoot.Instance.StartCoroutine(GetStaticVersion());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
@@ -23,7 +27,6 @@ internal class FsmUpdateVersion : IFsmNode
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
// 更新资源版本号
|
||||
var package = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var operation = package.UpdatePackageVersionAsync(30);
|
||||
yield return operation;
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public static class PatchManager
|
||||
{
|
||||
_isRun = true;
|
||||
|
||||
Debug.Log("开始补丁更新...");
|
||||
Debug.Log("开启补丁更新流程...");
|
||||
|
||||
// 注意:按照先后顺序添加流程节点
|
||||
FsmManager.AddNode(new FsmPatchInit());
|
||||
|
||||
Reference in New Issue
Block a user