diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Boot.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Boot.cs index 953255b3..cb8f3f6c 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Boot.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Boot.cs @@ -19,7 +19,7 @@ public class Boot : MonoBehaviour Application.runInBackground = true; DontDestroyOnLoad(this.gameObject); } - IEnumerator Start() + void Start() { // 游戏管理器 GameManager.Instance.Behaviour = this; @@ -34,16 +34,12 @@ public class Boot : MonoBehaviour var go = Resources.Load("PatchWindow"); GameObject.Instantiate(go); - // 开始补丁更新流程 - var operation = new PatchOperation("DefaultPackage", PlayMode); - YooAssets.StartOperation(operation); - yield return operation; - - // 设置默认的资源包 - var gamePackage = YooAssets.GetPackage("DefaultPackage"); - YooAssets.SetDefaultPackage(gamePackage); - - // 切换到主页面场景 - SceneEventDefine.ChangeToHomeScene.SendEventMessage(); + // 补丁更新流程 + PatchManager.Create("DefaultPackage", PlayMode); + PatchManager.Start(); + } + private void Update() + { + PatchManager.Update(); } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmStartGame.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmStartGame.cs index ce156ebe..06cfc092 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmStartGame.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmStartGame.cs @@ -2,19 +2,23 @@ using System.Collections.Generic; using UnityEngine; using UniFramework.Machine; +using YooAsset; internal class FsmStartGame : IStateNode { - private PatchOperation _owner; - void IStateNode.OnCreate(StateMachine machine) { - _owner = machine.Owner as PatchOperation; } void IStateNode.OnEnter() { PatchEventDefine.PatchStepsChange.SendEventMessage("开始游戏!"); - _owner.SetFinish(); + + // 设置默认的资源包 + var gamePackage = YooAssets.GetPackage("DefaultPackage"); + YooAssets.SetDefaultPackage(gamePackage); + + // 切换到主页面场景 + SceneEventDefine.ChangeToHomeScene.SendEventMessage(); } void IStateNode.OnUpdate() { diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchOperation.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs similarity index 67% rename from Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchOperation.cs rename to Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs index f03fa8ff..a3ace715 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchOperation.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs @@ -3,24 +3,13 @@ using UniFramework.Machine; using UniFramework.Event; using YooAsset; -public class PatchOperation : GameAsyncOperation +public static class PatchManager { - private enum ESteps + private static readonly EventGroup _eventGroup = new EventGroup(); + private static StateMachine _machine; + + public static void Create(string packageName, EPlayMode playMode) { - None, - Update, - Done, - } - - private readonly EventGroup _eventGroup = new EventGroup(); - private readonly StateMachine _machine; - private readonly string _packageName; - private ESteps _steps = ESteps.None; - - public PatchOperation(string packageName, EPlayMode playMode) - { - _packageName = packageName; - // 注册监听事件 _eventGroup.AddListener(OnHandleEventMessage); _eventGroup.AddListener(OnHandleEventMessage); @@ -29,7 +18,7 @@ public class PatchOperation : GameAsyncOperation _eventGroup.AddListener(OnHandleEventMessage); // 创建状态机 - _machine = new StateMachine(this); + _machine = new StateMachine(null); _machine.AddNode(); _machine.AddNode(); _machine.AddNode(); @@ -42,37 +31,19 @@ public class PatchOperation : GameAsyncOperation _machine.SetBlackboardValue("PackageName", packageName); _machine.SetBlackboardValue("PlayMode", playMode); } - protected override void OnStart() + public static void Start() { - _steps = ESteps.Update; _machine.Run(); } - protected override void OnUpdate() + public static void Update() { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.Update) - { - _machine.Update(); - } - } - protected override void OnAbort() - { - } - - public void SetFinish() - { - _steps = ESteps.Done; - _eventGroup.RemoveAllListener(); - Status = EOperationStatus.Succeed; - Debug.Log($"Package {_packageName} patch done !"); + _machine.Update(); } /// /// 接收事件 /// - private void OnHandleEventMessage(IEventMessage message) + private static void OnHandleEventMessage(IEventMessage message) { if (message is UserEventDefine.UserTryInitialize) { diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchOperation.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs.meta similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchOperation.cs.meta rename to Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/PatchManager.cs.meta