diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs index af865d8..e7c586e 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs @@ -2,6 +2,18 @@ public class PatchEventDefine { + /// + /// 补丁包初始化失败 + /// + public class InitializeFailed : IEventMessage + { + public static void SendEventMessage() + { + var msg = new InitializeFailed(); + UniEvent.SendMessage(msg); + } + } + /// /// 补丁流程步骤改变 /// diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/UserEventDefine.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/UserEventDefine.cs index 4f41298..be335ac 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/UserEventDefine.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/UserEventDefine.cs @@ -2,6 +2,18 @@ public class UserEventDefine { + /// + /// 用户尝试再次初始化资源包 + /// + public class UserTryInitialize : IEventMessage + { + public static void SendEventMessage() + { + var msg = new UserTryInitialize(); + UniEvent.SendMessage(msg); + } + } + /// /// 用户开始下载网络文件 /// diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchInit.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs similarity index 83% rename from Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchInit.cs rename to Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs index e9b499b..601f807 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchInit.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs @@ -8,9 +8,9 @@ using UniFramework.Module; using YooAsset; /// -/// 初始化工作 +/// 初始化资源包 /// -internal class FsmPatchInit : IStateNode +internal class FsmInitialize : IStateNode { private StateMachine _machine; @@ -20,12 +20,8 @@ internal class FsmPatchInit : IStateNode } void IStateNode.OnEnter() { - // 加载更新面板 - var go = Resources.Load("PatchWindow"); - GameObject.Instantiate(go); - - // 初始化资源系统 - UniModule.StartCoroutine(InitYooAsset()); + PatchEventDefine.PatchStatesChange.SendEventMessage("初始化资源包!"); + UniModule.StartCoroutine(InitPackage()); } void IStateNode.OnUpdate() { @@ -34,19 +30,24 @@ internal class FsmPatchInit : IStateNode { } - private IEnumerator InitYooAsset() + private IEnumerator InitPackage() { var playMode = PatchManager.Instance.PlayMode; - // 创建默认的资源包 - var package = YooAssets.CreateAssetsPackage("DefaultPackage"); - YooAssets.SetDefaultAssetsPackage(package); + // 创建默认的资源包 + string packageName = "DefaultPackage"; + var package = YooAssets.TryGetAssetsPackage(packageName); + if (package == null) + { + package = YooAssets.CreateAssetsPackage(packageName); + YooAssets.SetDefaultAssetsPackage(package); + } // 编辑器下的模拟模式 if (playMode == EPlayMode.EditorSimulateMode) { var createParameters = new EditorSimulateModeParameters(); - createParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild("DefaultPackage"); + createParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild(packageName); yield return package.InitializeAsync(createParameters); } @@ -69,7 +70,10 @@ internal class FsmPatchInit : IStateNode yield return package.InitializeAsync(createParameters); } - _machine.ChangeState(); + if (package.InitializeStatus == EOperationStatus.Succeed) + _machine.ChangeState(); + else + PatchEventDefine.InitializeFailed.SendEventMessage(); } /// diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs.meta new file mode 100644 index 0000000..cb45b7a --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmInitialize.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9c67e6e479b68e345afcdf325775c079 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchDone.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchDone.cs index d2c35d5..99e0633 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchDone.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchDone.cs @@ -5,7 +5,7 @@ using UniFramework.Machine; using UniFramework.Module; /// -/// 更新完毕 +/// 流程更新完毕 /// internal class FsmPatchDone : IStateNode { diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchPrepare.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchPrepare.cs new file mode 100644 index 0000000..4f23e72 --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchPrepare.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UniFramework.Machine; +using UniFramework.Module; + +/// +/// 流程准备工作 +/// +internal class FsmPatchPrepare : IStateNode +{ + private StateMachine _machine; + + void IStateNode.OnCreate(StateMachine machine) + { + _machine = machine; + } + void IStateNode.OnEnter() + { + // 加载更新面板 + var go = Resources.Load("PatchWindow"); + GameObject.Instantiate(go); + + _machine.ChangeState(); + } + void IStateNode.OnUpdate() + { + } + void IStateNode.OnExit() + { + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchInit.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchPrepare.cs.meta similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchInit.cs.meta rename to Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmPatchPrepare.cs.meta diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs index e57566f..33ccdd6 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs @@ -53,6 +53,7 @@ public class PatchManager : ModuleSingleton, IModule PlayMode = playMode; // 注册监听事件 + _eventGroup.AddListener(OnHandleEventMessage); _eventGroup.AddListener(OnHandleEventMessage); _eventGroup.AddListener(OnHandleEventMessage); _eventGroup.AddListener(OnHandleEventMessage); @@ -60,7 +61,8 @@ public class PatchManager : ModuleSingleton, IModule Debug.Log("开启补丁更新流程..."); _machine = new StateMachine(this); - _machine.AddNode(); + _machine.AddNode(); + _machine.AddNode(); _machine.AddNode(); _machine.AddNode(); _machine.AddNode(); @@ -68,7 +70,7 @@ public class PatchManager : ModuleSingleton, IModule _machine.AddNode(); _machine.AddNode(); _machine.AddNode(); - _machine.Run(); + _machine.Run(); } else { @@ -81,7 +83,11 @@ public class PatchManager : ModuleSingleton, IModule /// private void OnHandleEventMessage(IEventMessage message) { - if (message is UserEventDefine.UserBeginDownloadWebFiles) + if (message is UserEventDefine.UserTryInitialize) + { + _machine.ChangeState(); + } + else if (message is UserEventDefine.UserBeginDownloadWebFiles) { _machine.ChangeState(); } diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchWindow.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchWindow.cs index e2778f2..198abb8 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchWindow.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchWindow.cs @@ -70,6 +70,7 @@ public class PatchWindow : MonoBehaviour _messageBoxObj = transform.Find("UIWindow/MessgeBox").gameObject; _messageBoxObj.SetActive(false); + _eventGroup.AddListener(OnHandleEventMessage); _eventGroup.AddListener(OnHandleEventMessage); _eventGroup.AddListener(OnHandleEventMessage); _eventGroup.AddListener(OnHandleEventMessage); @@ -87,7 +88,15 @@ public class PatchWindow : MonoBehaviour /// private void OnHandleEventMessage(IEventMessage message) { - if (message is PatchEventDefine.PatchStatesChange) + if (message is PatchEventDefine.InitializeFailed) + { + System.Action callback = () => + { + UserEventDefine.UserTryInitialize.SendEventMessage(); + }; + ShowMessageBox($"Failed to initialize package !", callback); + } + else if (message is PatchEventDefine.PatchStatesChange) { var msg = message as PatchEventDefine.PatchStatesChange; _tips.text = msg.Tips;