JisolGame/JNFrame2/Assets/HotMain/SHGame/Procedure/ProcedureInitPackage.cs
PC-20230316NUNE\Administrator b0a2e4a900 提交完美
2024-10-17 20:36:24 +08:00

109 lines
4.2 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 Cysharp.Threading.Tasks;
using HotMain.SHGame.YooAsset;
using HotMain.SHGame.YooAsset.StreamingAssetsHelper;
using SHFrame;
using SHFrame.FSM;
using YooAsset;
namespace HotMain.SHGame.Procedure
{
/// <summary>
/// 初始化资源包
/// </summary>
public class ProcedureInitializePackage : ProcedureBase
{
#if UNITY_EDITOR
public static EPlayMode PlayMode = EPlayMode.EditorSimulateMode;
#else
public static EPlayMode PlayMode = EPlayMode.HostPlayMode;
#endif
public static string RawFilePackageName = "RawFilePackage";
public static string DefaultPackageName = "DefaultPackage";
//热更新的dll名称
public static readonly string[] HotDllName =
{
"JNGame.Runtime.dll",
"HotSamples.dll",
"GameScripts.dll",
};
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:
//联机运行模式
// 注意GameQueryServices.cs 太空战机的脚本类详细见StreamingAssetsHelper.cs
string HostServer = $"http://ngame.jisol.cn/JNGame2/{packageName}";
var createParameters = new HostPlayModeParameters();
createParameters.DecryptionServices = new FileStreamDecryption();
createParameters.BuildinQueryServices = new GameQueryServices();
createParameters.RemoteServices = new RemoteServices(HostServer, HostServer);
initOperation = package.InitializeAsync(createParameters);
break;
}
await initOperation.ToUniTask();
return package;
}
}
}