mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-16 12:50:17 +00:00
Update samples
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class FsmCreateDownloader : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmCreateDownloader);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.CreateDownloader);
|
||||
BootScene.Instance.StartCoroutine(CreateDownloader());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
}
|
||||
void IFsmNode.OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator CreateDownloader()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
Debug.Log("创建补丁下载器.");
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
PatchUpdater.Downloader = YooAssets.CreatePatchDownloader(downloadingMaxNum, failedTryAgain);
|
||||
if (PatchUpdater.Downloader.TotalDownloadCount == 0)
|
||||
{
|
||||
Debug.Log("没有发现需要下载的资源");
|
||||
FsmManager.Transition(nameof(FsmPatchDone));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"一共发现了{PatchUpdater.Downloader.TotalDownloadCount}个资源需要更新下载。");
|
||||
|
||||
// 发现新更新文件后,挂起流程系统
|
||||
// 注意:开发者需要在下载前检测磁盘空间不足
|
||||
int totalDownloadCount = PatchUpdater.Downloader.TotalDownloadCount;
|
||||
long totalDownloadBytes = PatchUpdater.Downloader.TotalDownloadBytes;
|
||||
PatchEventDispatcher.SendFoundUpdateFilesMsg(totalDownloadCount, totalDownloadBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b104741ebcb72946abe282c1da73360
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using YooAsset;
|
||||
|
||||
public class FsmDownloadWebFiles : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmDownloadWebFiles);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.DownloadWebFiles);
|
||||
BootScene.Instance.StartCoroutine(BeginDownload());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
}
|
||||
void IFsmNode.OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
private IEnumerator BeginDownload()
|
||||
{
|
||||
var downloader = PatchUpdater.Downloader;
|
||||
|
||||
// 注册下载回调
|
||||
downloader.OnDownloadErrorCallback = PatchEventDispatcher.SendWebFileDownloadFailedMsg;
|
||||
downloader.OnDownloadProgressCallback = PatchEventDispatcher.SendDownloadProgressUpdateMsg;
|
||||
downloader.BeginDownload();
|
||||
yield return downloader;
|
||||
|
||||
// 检测下载结果
|
||||
if (downloader.Status != EOperationStatus.Succeed)
|
||||
yield break;
|
||||
|
||||
FsmManager.Transition(nameof(FsmPatchDone));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3fae22040fe2d541ab4582c7c1c71fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
internal class FsmPatchDone : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmPatchDone);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.PatchDone);
|
||||
Debug.Log("补丁流程更新完毕!");
|
||||
|
||||
YooAsset.YooAssets.LoadSceneAsync("Scene/Game1");
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
}
|
||||
void IFsmNode.OnExit()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cf80cfbed474c34b892eaeda7fcb054
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
internal class FsmPatchInit : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmPatchInit);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
// 加载更新面板
|
||||
var go = Resources.Load<GameObject>("PatchWindow");
|
||||
GameObject.Instantiate(go);
|
||||
|
||||
BootScene.Instance.StartCoroutine(Begin());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
}
|
||||
void IFsmNode.OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
private IEnumerator Begin()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
FsmManager.Transition(nameof(FsmUpdateStaticVersion));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8998f67b4187d404eb26190f5cd5ac86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class FsmUpdateManifest : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmUpdateManifest);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.UpdateManifest);
|
||||
BootScene.Instance.StartCoroutine(UpdateManifest());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
}
|
||||
void IFsmNode.OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
private IEnumerator UpdateManifest()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
// 更新补丁清单
|
||||
var operation = YooAssets.UpdateManifestAsync(PatchUpdater.ResourceVersion, 30);
|
||||
yield return operation;
|
||||
|
||||
if(operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
FsmManager.Transition(nameof(FsmCreateDownloader));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(operation.Error);
|
||||
PatchEventDispatcher.SendPatchManifestUpdateFailedMsg();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4b6ef49759dcf14d80c5aa2d360f597
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
internal class FsmUpdateStaticVersion : IFsmNode
|
||||
{
|
||||
public string Name { private set; get; } = nameof(FsmUpdateStaticVersion);
|
||||
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.UpdateStaticVersion);
|
||||
BootScene.Instance.StartCoroutine(GetStaticVersion());
|
||||
}
|
||||
void IFsmNode.OnUpdate()
|
||||
{
|
||||
}
|
||||
void IFsmNode.OnExit()
|
||||
{
|
||||
}
|
||||
|
||||
private IEnumerator GetStaticVersion()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
// 更新资源版本号
|
||||
var operation = YooAssets.UpdateStaticVersionAsync(30);
|
||||
yield return operation;
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
Debug.Log($"Found static version : {operation.ResourceVersion}");
|
||||
PatchUpdater.ResourceVersion = operation.ResourceVersion;
|
||||
FsmManager.Transition(nameof(FsmUpdateManifest));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(operation.Error);
|
||||
PatchEventDispatcher.SendStaticVersionUpdateFailedMsg();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5ea76dfe0fc52b47a00a3bf68a54d09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user