update samples

pull/51/head
hevinci 2022-11-29 11:07:38 +08:00
parent 5415d95f36
commit 2696da092d
9 changed files with 107 additions and 19 deletions

View File

@ -2,6 +2,18 @@
public class PatchEventDefine
{
/// <summary>
/// 补丁包初始化失败
/// </summary>
public class InitializeFailed : IEventMessage
{
public static void SendEventMessage()
{
var msg = new InitializeFailed();
UniEvent.SendMessage(msg);
}
}
/// <summary>
/// 补丁流程步骤改变
/// </summary>

View File

@ -2,6 +2,18 @@
public class UserEventDefine
{
/// <summary>
/// 用户尝试再次初始化资源包
/// </summary>
public class UserTryInitialize : IEventMessage
{
public static void SendEventMessage()
{
var msg = new UserTryInitialize();
UniEvent.SendMessage(msg);
}
}
/// <summary>
/// 用户开始下载网络文件
/// </summary>

View File

@ -8,9 +8,9 @@ using UniFramework.Module;
using YooAsset;
/// <summary>
/// 初始化工作
/// 初始化资源包
/// </summary>
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<GameObject>("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");
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);
}
if (package.InitializeStatus == EOperationStatus.Succeed)
_machine.ChangeState<FsmUpdateVersion>();
else
PatchEventDefine.InitializeFailed.SendEventMessage();
}
/// <summary>

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9c67e6e479b68e345afcdf325775c079
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,7 +5,7 @@ using UniFramework.Machine;
using UniFramework.Module;
/// <summary>
/// 更新完毕
/// 流程更新完毕
/// </summary>
internal class FsmPatchDone : IStateNode
{

View File

@ -0,0 +1,34 @@
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Machine;
using UniFramework.Module;
/// <summary>
/// 流程准备工作
/// </summary>
internal class FsmPatchPrepare : IStateNode
{
private StateMachine _machine;
void IStateNode.OnCreate(StateMachine machine)
{
_machine = machine;
}
void IStateNode.OnEnter()
{
// 加载更新面板
var go = Resources.Load<GameObject>("PatchWindow");
GameObject.Instantiate(go);
_machine.ChangeState<FsmInitialize>();
}
void IStateNode.OnUpdate()
{
}
void IStateNode.OnExit()
{
}
}

View File

@ -53,6 +53,7 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
PlayMode = playMode;
// 注册监听事件
_eventGroup.AddListener<UserEventDefine.UserTryInitialize>(OnHandleEventMessage);
_eventGroup.AddListener<UserEventDefine.UserBeginDownloadWebFiles>(OnHandleEventMessage);
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePackageVersion>(OnHandleEventMessage);
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePatchManifest>(OnHandleEventMessage);
@ -60,7 +61,8 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
Debug.Log("开启补丁更新流程...");
_machine = new StateMachine(this);
_machine.AddNode<FsmPatchInit>();
_machine.AddNode<FsmPatchPrepare>();
_machine.AddNode<FsmInitialize>();
_machine.AddNode<FsmUpdateVersion>();
_machine.AddNode<FsmUpdateManifest>();
_machine.AddNode<FsmCreateDownloader>();
@ -68,7 +70,7 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
_machine.AddNode<FsmDownloadOver>();
_machine.AddNode<FsmClearCache>();
_machine.AddNode<FsmPatchDone>();
_machine.Run<FsmPatchInit>();
_machine.Run<FsmPatchPrepare>();
}
else
{
@ -81,7 +83,11 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
/// </summary>
private void OnHandleEventMessage(IEventMessage message)
{
if (message is UserEventDefine.UserBeginDownloadWebFiles)
if (message is UserEventDefine.UserTryInitialize)
{
_machine.ChangeState<FsmInitialize>();
}
else if (message is UserEventDefine.UserBeginDownloadWebFiles)
{
_machine.ChangeState<FsmDownloadFiles>();
}

View File

@ -70,6 +70,7 @@ public class PatchWindow : MonoBehaviour
_messageBoxObj = transform.Find("UIWindow/MessgeBox").gameObject;
_messageBoxObj.SetActive(false);
_eventGroup.AddListener<PatchEventDefine.InitializeFailed>(OnHandleEventMessage);
_eventGroup.AddListener<PatchEventDefine.PatchStatesChange>(OnHandleEventMessage);
_eventGroup.AddListener<PatchEventDefine.FoundUpdateFiles>(OnHandleEventMessage);
_eventGroup.AddListener<PatchEventDefine.DownloadProgressUpdate>(OnHandleEventMessage);
@ -87,7 +88,15 @@ public class PatchWindow : MonoBehaviour
/// </summary>
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;