JisolGame/JNFrame2/Assets/HotMain/SHGame/Procedure/ProcedureInitPackage.cs
2024-10-15 02:12:55 +08:00

104 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
using Cysharp.Threading.Tasks;
using Plugins.SHFrame.SHGame.YooAsset;
using SHFrame;
using SHFrame.FSM;
using UnityEditor;
using UnityEngine;
using YooAsset;
namespace Plugins.SHFrame.SHGame.Procedure
{
/// <summary>
/// 初始化资源包
/// </summary>
public class ProcedureInitializePackage : ProcedureBase
{
public static EPlayMode PlayMode = EPlayMode.OfflinePlayMode;
public static string RawFilePackageName = "RawFilePackage";
public static string DefaultPackageName = "DefaultPackage";
//热更新的dll名称
public static readonly string[] HotDllName =
{
};
public static readonly string[] AotMetaAssemblyFiles =
{
"mscorlib.dll",
"System.dll",
"System.Core.dll",
};
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
InitPackage(procedureOwner).Forget();
}
private async UniTask InitPackage(IFsm<IProcedureManager> procedureOwner)
{
Log.Debug($"YooAssets 开始初始化");
// 1.初始化资源系统
YooAssets.Initialize();
var rawFilePackage = await InitYooPackage(RawFilePackageName, true);
var defaultPackage = await InitYooPackage(DefaultPackageName, false);
Log.Debug($"YooAssets 初始化完成");
// 设置该资源包为默认的资源包可以使用YooAssets相关加载接口加载该资源包内容。
YooAssets.SetDefaultPackage(defaultPackage);
// 切换到更新资源清单
ChangeState<ProcedureUpdatePackageManifest>(procedureOwner);
}
private async UniTask<ResourcePackage> InitYooPackage(string packageName, bool isRaw)
{
// 创建资源包
var package = YooAssets.TryGetPackage(packageName) ?? YooAssets.CreatePackage(packageName);
InitializationOperation initOperation = null;
switch (PlayMode)
{
case EPlayMode.EditorSimulateMode:
// 编辑器模拟模式
EDefaultBuildPipeline buildPipeline = isRaw ? EDefaultBuildPipeline.RawFileBuildPipeline : EDefaultBuildPipeline.ScriptableBuildPipeline;
var initParametersEditorSimulateMode = new EditorSimulateModeParameters
{
SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(buildPipeline, packageName)
};
initOperation = package.InitializeAsync(initParametersEditorSimulateMode);
break;
case EPlayMode.OfflinePlayMode:
// 单机模式
var initParametersOfflinePlayMode = new OfflinePlayModeParameters
{
DecryptionServices = new FileStreamDecryption()
};
initOperation = package.InitializeAsync(initParametersOfflinePlayMode);
break;
case EPlayMode.HostPlayMode:
// //联机运行模式
// var initParametersHostPlayMode = new HostPlayModeParameters
// {
// BuildinQueryServices = new GameQueryServices(),
// RemoteServices = new RemoteServices(GetHostServerURL(packageName), GetHostServerURL(packageName))
// };
// initOperation = package.InitializeAsync(initParametersHostPlayMode);
break;
}
await initOperation.ToUniTask();
return package;
}
}
}