JisolGame/JNFrame2/Assets/HotMain/SHGame/Procedure/ProcedureInitPackage.cs

104 lines
3.8 KiB
C#
Raw Normal View History

2024-10-14 20:31:57 +08:00
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)
2024-10-14 20:31:57 +08:00
{
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)
};
2024-10-14 20:31:57 +08:00
initOperation = package.InitializeAsync(initParametersEditorSimulateMode);
break;
case EPlayMode.OfflinePlayMode:
// 单机模式
var initParametersOfflinePlayMode = new OfflinePlayModeParameters
2024-10-14 20:31:57 +08:00
{
DecryptionServices = new FileStreamDecryption()
2024-10-14 20:31:57 +08:00
};
initOperation = package.InitializeAsync(initParametersOfflinePlayMode);
2024-10-14 20:31:57 +08:00
break;
case EPlayMode.HostPlayMode:
// //联机运行模式
// var initParametersHostPlayMode = new HostPlayModeParameters
// {
// BuildinQueryServices = new GameQueryServices(),
// RemoteServices = new RemoteServices(GetHostServerURL(packageName), GetHostServerURL(packageName))
// };
// initOperation = package.InitializeAsync(initParametersHostPlayMode);
2024-10-14 20:31:57 +08:00
break;
}
await initOperation.ToUniTask();
2024-10-14 20:31:57 +08:00
return package;
}
}
}