update samples
parent
5415d95f36
commit
2696da092d
|
@ -2,6 +2,18 @@
|
||||||
|
|
||||||
public class PatchEventDefine
|
public class PatchEventDefine
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 补丁包初始化失败
|
||||||
|
/// </summary>
|
||||||
|
public class InitializeFailed : IEventMessage
|
||||||
|
{
|
||||||
|
public static void SendEventMessage()
|
||||||
|
{
|
||||||
|
var msg = new InitializeFailed();
|
||||||
|
UniEvent.SendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 补丁流程步骤改变
|
/// 补丁流程步骤改变
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -2,6 +2,18 @@
|
||||||
|
|
||||||
public class UserEventDefine
|
public class UserEventDefine
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户尝试再次初始化资源包
|
||||||
|
/// </summary>
|
||||||
|
public class UserTryInitialize : IEventMessage
|
||||||
|
{
|
||||||
|
public static void SendEventMessage()
|
||||||
|
{
|
||||||
|
var msg = new UserTryInitialize();
|
||||||
|
UniEvent.SendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户开始下载网络文件
|
/// 用户开始下载网络文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -8,9 +8,9 @@ using UniFramework.Module;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化工作
|
/// 初始化资源包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class FsmPatchInit : IStateNode
|
internal class FsmInitialize : IStateNode
|
||||||
{
|
{
|
||||||
private StateMachine _machine;
|
private StateMachine _machine;
|
||||||
|
|
||||||
|
@ -20,12 +20,8 @@ internal class FsmPatchInit : IStateNode
|
||||||
}
|
}
|
||||||
void IStateNode.OnEnter()
|
void IStateNode.OnEnter()
|
||||||
{
|
{
|
||||||
// 加载更新面板
|
PatchEventDefine.PatchStatesChange.SendEventMessage("初始化资源包!");
|
||||||
var go = Resources.Load<GameObject>("PatchWindow");
|
UniModule.StartCoroutine(InitPackage());
|
||||||
GameObject.Instantiate(go);
|
|
||||||
|
|
||||||
// 初始化资源系统
|
|
||||||
UniModule.StartCoroutine(InitYooAsset());
|
|
||||||
}
|
}
|
||||||
void IStateNode.OnUpdate()
|
void IStateNode.OnUpdate()
|
||||||
{
|
{
|
||||||
|
@ -34,19 +30,24 @@ internal class FsmPatchInit : IStateNode
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator InitYooAsset()
|
private IEnumerator InitPackage()
|
||||||
{
|
{
|
||||||
var playMode = PatchManager.Instance.PlayMode;
|
var playMode = PatchManager.Instance.PlayMode;
|
||||||
|
|
||||||
// 创建默认的资源包
|
// 创建默认的资源包
|
||||||
var package = YooAssets.CreateAssetsPackage("DefaultPackage");
|
string packageName = "DefaultPackage";
|
||||||
YooAssets.SetDefaultAssetsPackage(package);
|
var package = YooAssets.TryGetAssetsPackage(packageName);
|
||||||
|
if (package == null)
|
||||||
|
{
|
||||||
|
package = YooAssets.CreateAssetsPackage(packageName);
|
||||||
|
YooAssets.SetDefaultAssetsPackage(package);
|
||||||
|
}
|
||||||
|
|
||||||
// 编辑器下的模拟模式
|
// 编辑器下的模拟模式
|
||||||
if (playMode == EPlayMode.EditorSimulateMode)
|
if (playMode == EPlayMode.EditorSimulateMode)
|
||||||
{
|
{
|
||||||
var createParameters = new EditorSimulateModeParameters();
|
var createParameters = new EditorSimulateModeParameters();
|
||||||
createParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild("DefaultPackage");
|
createParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild(packageName);
|
||||||
yield return package.InitializeAsync(createParameters);
|
yield return package.InitializeAsync(createParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +70,10 @@ internal class FsmPatchInit : IStateNode
|
||||||
yield return package.InitializeAsync(createParameters);
|
yield return package.InitializeAsync(createParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
_machine.ChangeState<FsmUpdateVersion>();
|
if (package.InitializeStatus == EOperationStatus.Succeed)
|
||||||
|
_machine.ChangeState<FsmUpdateVersion>();
|
||||||
|
else
|
||||||
|
PatchEventDefine.InitializeFailed.SendEventMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9c67e6e479b68e345afcdf325775c079
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -5,7 +5,7 @@ using UniFramework.Machine;
|
||||||
using UniFramework.Module;
|
using UniFramework.Module;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新完毕
|
/// 流程更新完毕
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class FsmPatchDone : IStateNode
|
internal class FsmPatchDone : IStateNode
|
||||||
{
|
{
|
||||||
|
|
|
@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,6 +53,7 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
|
||||||
PlayMode = playMode;
|
PlayMode = playMode;
|
||||||
|
|
||||||
// 注册监听事件
|
// 注册监听事件
|
||||||
|
_eventGroup.AddListener<UserEventDefine.UserTryInitialize>(OnHandleEventMessage);
|
||||||
_eventGroup.AddListener<UserEventDefine.UserBeginDownloadWebFiles>(OnHandleEventMessage);
|
_eventGroup.AddListener<UserEventDefine.UserBeginDownloadWebFiles>(OnHandleEventMessage);
|
||||||
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePackageVersion>(OnHandleEventMessage);
|
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePackageVersion>(OnHandleEventMessage);
|
||||||
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePatchManifest>(OnHandleEventMessage);
|
_eventGroup.AddListener<UserEventDefine.UserTryUpdatePatchManifest>(OnHandleEventMessage);
|
||||||
|
@ -60,7 +61,8 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
|
||||||
|
|
||||||
Debug.Log("开启补丁更新流程...");
|
Debug.Log("开启补丁更新流程...");
|
||||||
_machine = new StateMachine(this);
|
_machine = new StateMachine(this);
|
||||||
_machine.AddNode<FsmPatchInit>();
|
_machine.AddNode<FsmPatchPrepare>();
|
||||||
|
_machine.AddNode<FsmInitialize>();
|
||||||
_machine.AddNode<FsmUpdateVersion>();
|
_machine.AddNode<FsmUpdateVersion>();
|
||||||
_machine.AddNode<FsmUpdateManifest>();
|
_machine.AddNode<FsmUpdateManifest>();
|
||||||
_machine.AddNode<FsmCreateDownloader>();
|
_machine.AddNode<FsmCreateDownloader>();
|
||||||
|
@ -68,7 +70,7 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
|
||||||
_machine.AddNode<FsmDownloadOver>();
|
_machine.AddNode<FsmDownloadOver>();
|
||||||
_machine.AddNode<FsmClearCache>();
|
_machine.AddNode<FsmClearCache>();
|
||||||
_machine.AddNode<FsmPatchDone>();
|
_machine.AddNode<FsmPatchDone>();
|
||||||
_machine.Run<FsmPatchInit>();
|
_machine.Run<FsmPatchPrepare>();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -81,7 +83,11 @@ public class PatchManager : ModuleSingleton<PatchManager>, IModule
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnHandleEventMessage(IEventMessage message)
|
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>();
|
_machine.ChangeState<FsmDownloadFiles>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class PatchWindow : MonoBehaviour
|
||||||
_messageBoxObj = transform.Find("UIWindow/MessgeBox").gameObject;
|
_messageBoxObj = transform.Find("UIWindow/MessgeBox").gameObject;
|
||||||
_messageBoxObj.SetActive(false);
|
_messageBoxObj.SetActive(false);
|
||||||
|
|
||||||
|
_eventGroup.AddListener<PatchEventDefine.InitializeFailed>(OnHandleEventMessage);
|
||||||
_eventGroup.AddListener<PatchEventDefine.PatchStatesChange>(OnHandleEventMessage);
|
_eventGroup.AddListener<PatchEventDefine.PatchStatesChange>(OnHandleEventMessage);
|
||||||
_eventGroup.AddListener<PatchEventDefine.FoundUpdateFiles>(OnHandleEventMessage);
|
_eventGroup.AddListener<PatchEventDefine.FoundUpdateFiles>(OnHandleEventMessage);
|
||||||
_eventGroup.AddListener<PatchEventDefine.DownloadProgressUpdate>(OnHandleEventMessage);
|
_eventGroup.AddListener<PatchEventDefine.DownloadProgressUpdate>(OnHandleEventMessage);
|
||||||
|
@ -87,7 +88,15 @@ public class PatchWindow : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnHandleEventMessage(IEventMessage message)
|
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;
|
var msg = message as PatchEventDefine.PatchStatesChange;
|
||||||
_tips.text = msg.Tips;
|
_tips.text = msg.Tips;
|
||||||
|
|
Loading…
Reference in New Issue