阅读demo源码

pull/98/head
Compa 2023-01-06 18:19:39 +08:00
parent 223a28ce82
commit 5b44eca4aa
10 changed files with 78 additions and 29 deletions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 7454dfe0b5b68e047b4c43fef1a651c9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -196,7 +196,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 41fef9a778e4e254b939e9dc3e553bf0, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayMode: 2
PlayMode: 1
--- !u!4 &1281760861
Transform:
m_ObjectHideFlags: 0
@ -285,6 +285,7 @@ GameObject:
- component: {fileID: 6920458660802423026}
- component: {fileID: 6920458660802423025}
- component: {fileID: 6920458660802423024}
- component: {fileID: 6920458660802423027}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -358,3 +359,36 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!114 &6920458660802423027
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6920458660802423023}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2

View File

@ -10,6 +10,6 @@ public class BhvApplicationQuit : MonoBehaviour
}
private void OnApplicationQuit()
{
YooAssets.Destroy();
YooAssets.Destroy(); //TODO wht real 是不是要调一下
}
}

View File

@ -3,6 +3,7 @@ using UniFramework.Event;
using UniFramework.Module;
using YooAsset;
//TODO wht real 框架加入该类
public class Boot : MonoBehaviour
{
/// <summary>
@ -13,28 +14,32 @@ public class Boot : MonoBehaviour
void Awake()
{
Debug.Log($"资源系统运行模式:{PlayMode}");
Application.targetFrameRate = 60;
Application.runInBackground = true;
// Application.targetFrameRate = 60;
// Application.runInBackground = true; //TODO wht real 加入框架
}
void Start()
{
// 初始化BetterStreaming
BetterStreamingAssets.Initialize();
BetterStreamingAssets.Initialize(); //TODO wht ref 不是必要的
// 初始化事件系统
UniEvent.Initalize();
UniEvent.Initalize(); //TODO wht ref 不是必要的
// 初始化管理系统
UniModule.Initialize();
UniModule.Initialize(); //TODO wht ref 不是必要的
// 初始化资源系统
YooAssets.Initialize();
YooAssets.SetOperationSystemMaxTimeSlice(30);
YooAssets.Initialize(); //TODO wht real 拿
YooAssets.SetOperationSystemMaxTimeSlice(30); //TODO wht real 拿
// TODO wht ref 上面 都要有
// 创建补丁管理器
UniModule.CreateModule<PatchManager>();
UniModule.CreateModule<PatchManager>(); //TODO wht ref 不是必要的
// 开始补丁更新流程
PatchManager.Instance.Run(PlayMode);
PatchManager.Instance.Run(PlayMode); //TODo wht ref 不是必要的
//TODO wht real 把UniFramework和BetterStreamingAssets去掉
}
}

View File

@ -17,6 +17,7 @@ internal class FsmClearCache : IStateNode
void IStateNode.OnEnter()
{
PatchEventDefine.PatchStatesChange.SendEventMessage("清理未使用的缓存文件!");
//TODO wht real 拿,但是不开
var package = YooAsset.YooAssets.GetAssetsPackage("DefaultPackage");
var operation = package.ClearUnusedCacheFilesAsync();
operation.Completed += Operation_Completed;

View File

@ -32,12 +32,13 @@ public class FsmCreateDownloader : IStateNode
{
yield return new WaitForSecondsRealtime(0.5f);
//TODO wht real 以下代码全拿
int downloadingMaxNum = 10;
int failedTryAgain = 3;
var downloader = YooAssets.CreatePatchDownloader(downloadingMaxNum, failedTryAgain);
PatchManager.Instance.Downloader = downloader;
if (downloader.TotalDownloadCount == 0)
if (downloader.TotalDownloadCount == 0) //没有需要下载的资源
{
Debug.Log("Not found any download files !");
_machine.ChangeState<FsmDownloadOver>();
@ -51,7 +52,7 @@ public class FsmCreateDownloader : IStateNode
// 注意:开发者需要在下载前检测磁盘空间不足
int totalDownloadCount = downloader.TotalDownloadCount;
long totalDownloadBytes = downloader.TotalDownloadBytes;
PatchEventDefine.FoundUpdateFiles.SendEventMessage(totalDownloadCount, totalDownloadBytes);
PatchEventDefine.FoundUpdateFiles.SendEventMessage(totalDownloadCount, totalDownloadBytes); //TODO wht real 不要
}
}
}

View File

@ -31,16 +31,25 @@ public class FsmDownloadFiles : IStateNode
{
var downloader = PatchManager.Instance.Downloader;
//TODO wht real 以下代码全拿
// 注册下载回调
downloader.OnDownloadErrorCallback = PatchEventDefine.WebFileDownloadFailed.SendEventMessage;
downloader.OnDownloadProgressCallback = PatchEventDefine.DownloadProgressUpdate.SendEventMessage;
// downloader.OnDownloadOverCallback = OnDownloadOverFunction;
// downloader.OnStartDownloadFileCallback = OnStartDownloadFileFunction;
downloader.BeginDownload();
yield return downloader;
// 检测下载结果
if (downloader.Status != EOperationStatus.Succeed)
yield break;
if (downloader.Status == EOperationStatus.Succeed)
{
_machine.ChangeState<FsmPatchDone>();
//TODO wht real 可以开始游戏
}
else
{
yield break;
}
}
}

View File

@ -36,6 +36,8 @@ internal class FsmInitialize : IStateNode
var playMode = PatchManager.Instance.PlayMode;
// TODO wht real 以下代码全拿
// 创建默认的资源包
string packageName = "DefaultPackage";
var package = YooAssets.TryGetAssetsPackage(packageName);
@ -76,12 +78,13 @@ internal class FsmInitialize : IStateNode
yield return initializationOperation;
if (package.InitializeStatus == EOperationStatus.Succeed)
{
_machine.ChangeState<FsmUpdateVersion>();
_machine.ChangeState<FsmUpdateVersion>(); //TODO wht ref 搜ChangeState去跟流程
}
else
{
Debug.LogWarning($"{initializationOperation.Error}");
PatchEventDefine.InitializeFailed.SendEventMessage();
//TODO wht 重试
PatchEventDefine.InitializeFailed.SendEventMessage(); //TODO wht real 不要
}
}
@ -124,7 +127,7 @@ internal class FsmInitialize : IStateNode
{
// 注意使用了BetterStreamingAssets插件使用前需要初始化该插件
string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
return BetterStreamingAssets.FileExists($"{buildinFolderName}/{fileName}");
return BetterStreamingAssets.FileExists($"{buildinFolderName}/{fileName}"); //TODO wht real 有没有其它接口可以替代不想用BetterStreamingAssets这种第三方
}
}

View File

@ -32,6 +32,7 @@ public class FsmUpdateManifest : IStateNode
{
yield return new WaitForSecondsRealtime(0.5f);
//TODO wht real 以下代码全拿
var package = YooAssets.GetAssetsPackage("DefaultPackage");
var operation = package.UpdatePackageManifestAsync(PatchManager.Instance.PackageVersion);
yield return operation;
@ -43,7 +44,8 @@ public class FsmUpdateManifest : IStateNode
else
{
Debug.LogWarning(operation.Error);
PatchEventDefine.PatchManifestUpdateFailed.SendEventMessage();
//TODO wht real 重试
PatchEventDefine.PatchManifestUpdateFailed.SendEventMessage(); //TODO wht real 不要
}
}
}

View File

@ -32,6 +32,7 @@ internal class FsmUpdateVersion : IStateNode
{
yield return new WaitForSecondsRealtime(0.5f);
//TODO wht real 以下代码全拿
var package = YooAssets.GetAssetsPackage("DefaultPackage");
var operation = package.UpdatePackageVersionAsync();
yield return operation;
@ -44,7 +45,8 @@ internal class FsmUpdateVersion : IStateNode
else
{
Debug.LogWarning(operation.Error);
PatchEventDefine.PackageVersionUpdateFailed.SendEventMessage();
//TODO wht real 重试
PatchEventDefine.PackageVersionUpdateFailed.SendEventMessage(); //TODO wht real 不要
}
}
}