mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
104 lines
3.8 KiB
C#
104 lines
3.8 KiB
C#
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;
|
||
}
|
||
|
||
}
|
||
} |