傻逼Yooasset 新版本各种问题还是用老版本吧!

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-10-15 02:12:55 +08:00
parent f6c362d356
commit d7e6b45f5f
184 changed files with 10075 additions and 13465 deletions

View File

@@ -1,53 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
public class ConsoleToScreen : MonoBehaviour
{
const int maxLines = 50;
const int maxLineLength = 120;
private string _logStr = "";
private readonly List<string> _lines = new();
public int fontSize = 15;
void OnEnable() { Application.logMessageReceived += Log; }
void OnDisable() { Application.logMessageReceived -= Log; }
public void Log(string logString, string stackTrace, LogType type)
{
foreach (var line in logString.Split('\n'))
{
if (line.Length <= maxLineLength)
{
_lines.Add(line);
continue;
}
var lineCount = line.Length / maxLineLength + 1;
for (int i = 0; i < lineCount; i++)
{
if ((i + 1) * maxLineLength <= line.Length)
{
_lines.Add(line.Substring(i * maxLineLength, maxLineLength));
}
else
{
_lines.Add(line.Substring(i * maxLineLength, line.Length - i * maxLineLength));
}
}
}
if (_lines.Count > maxLines)
{
_lines.RemoveRange(0, _lines.Count - maxLines);
}
// _lines.Add(stackTrace);
_logStr = string.Join("\n", _lines);
}
void OnGUI()
{
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,
new Vector3(Screen.width / 1200.0f, Screen.height / 800.0f, 1.0f));
GUI.Label(new Rect(10, 10, 800, 370), _logStr, new GUIStyle { fontSize = 10 });
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f75d46640fcd41f49a2bc14a946c16cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -147,6 +147,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 67180524}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
@@ -154,7 +155,6 @@ Transform:
m_Children:
- {fileID: 1371077986}
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &67180526
MonoBehaviour:
@@ -254,13 +254,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 790008994}
serializedVersion: 2
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &1371077985
GameObject:
@@ -286,13 +286,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1371077985}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 67180525}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1371077987
MonoBehaviour:
@@ -307,6 +307,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_AvailableProcedureTypeNames:
- HotMain.SHGame.Procedure.ProcedureLoadLauncher
- Plugins.SHFrame.SHGame.Procedure.ProcedureInitializePackage
- Plugins.SHFrame.SHGame.Procedure.ProcedureUpdatePackageManifest
- Plugins.SHFrame.SHGame.Procedure.ProcedureUpdatePackageVersion
@@ -395,11 +396,18 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1371947665}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 1371947668}
- {fileID: 790008996}
- {fileID: 67180525}

View File

@@ -1,297 +0,0 @@
using HybridCLR;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Plugins.SHFrame.SHGame.YooAsset;
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;
/// <summary>
/// 脚本工作流程:
/// 1.下载资源用YooAsset资源框架进行下载
/// 1资源文件ab包等
/// 2热更新dll
/// 3) AOT泛型补充元数据dll
/// 2.给AOT dll补充元数据通过RuntimeApi.LoadMetadataForAOTAssembly()
/// 3.通过实例化一个prefab运行热更新代码
/// </summary>
public class LoadDll : MonoBehaviour
{
/// <summary>
/// 资源系统运行模式
/// </summary>
public EPlayMode PlayMode = EPlayMode.OfflinePlayMode;
//补充元数据dll的列表
//通过RuntimeApi.LoadMetadataForAOTAssembly()函数来补充AOT泛型的原始元数据
public static List<string> AOTMetaAssemblyNames { get; } = new List<string>()
{
"mscorlib.dll",
"System.dll",
"System.Core.dll",
};
void Start()
{
//StartCoroutine(DownLoadAssets(this.StartGame));
StartCoroutine(DownLoadAssetsByYooAssets(this.StartGame));
}
private static Dictionary<string, byte[]> s_assetDatas = new Dictionary<string, byte[]>();
public static byte[] GetAssetData(string dllName)
{
return s_assetDatas[dllName];
}
private string GetWebRequestPath(string asset)
{
var path = $"{Application.streamingAssetsPath}/{asset}";
if (!path.Contains("://"))
{
path = "file://" + path;
}
if (path.EndsWith(".dll"))
{
path += ".bytes";
}
return path;
}
IEnumerator DownLoadAssetsByYooAssets(Action onDownloadComplete)
{
// 1.初始化资源系统
YooAssets.Initialize();
string packageName = "DefaultPackage";
// 创建默认的资源包
var package = YooAssets.TryGetPackage(packageName) ?? YooAssets.CreatePackage(packageName);
// 设置该资源包为默认的资源包可以使用YooAssets相关加载接口加载该资源包内容。
YooAssets.SetDefaultPackage(package);
if (PlayMode == EPlayMode.EditorSimulateMode)
{
Debug.Log("编辑器模式");
//编辑器模拟模式
var initParameters = new EditorSimulateModeParameters();
initParameters.EditorFileSystemParameters =
FileSystemParameters.CreateDefaultEditorFileSystemParameters(
EditorSimulateModeHelper.SimulateBuild(EDefaultBuildPipeline.ScriptableBuildPipeline, "DefaultPackage")
);
yield return package.InitializeAsync(initParameters);
}
else if (PlayMode == EPlayMode.HostPlayMode)
{
Debug.Log("在线模式");
// 注意GameQueryServices.cs 太空战机的脚本类详细见StreamingAssetsHelper.cs
string defaultHostServer = "http://127.0.0.1/CDN/Android/v1.0";
string fallbackHostServer = "http://127.0.0.1/CDN/Android/v1.0";
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
var cacheFileSystem = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
var buildinFileSystem = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
var initParameters = new HostPlayModeParameters();
initParameters.BuildinFileSystemParameters = buildinFileSystem;
initParameters.CacheFileSystemParameters = cacheFileSystem;
yield return package.InitializeAsync(initParameters);
}
else if (PlayMode == EPlayMode.OfflinePlayMode)
{
Debug.Log("离线模式");
// var buildinFileSystem = FileSystemParameters.CreateDefaultBuildinRawFileSystemParameters();
// var initParameters = new OfflinePlayModeParameters();
// initParameters.BuildinFileSystemParameters = buildinFileSystem;
// yield return package.InitializeAsync(initParameters);
// var initParametersOfflinePlayMode = new OfflinePlayModeParameters();
// yield return package.InitializeAsync(initParametersOfflinePlayMode);
var createParameters = new OfflinePlayModeParameters();
createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(new FileStreamDecryption());
yield return package.InitializeAsync(createParameters);
}
//2.获取资源版本
var operation = package.RequestPackageVersionAsync();
yield return operation;
if (operation.Status != EOperationStatus.Succeed)
{
//更新失败
Debug.LogError(operation.Error);
//TODO
yield break;
}
string PackageVersion = operation.PackageVersion;
//3.更新补丁清单
var operation2 = package.UpdatePackageManifestAsync(PackageVersion);
yield return operation2;
if (operation2.Status != EOperationStatus.Succeed)
{
//更新失败
Debug.LogError(operation2.Error);
//TODO:
yield break;
}
//4.下载补丁包
yield return Download();
//TODO:判断是否下载成功...
var assets = new List<string>
{
"HotSamples.dll",
}.Concat(AOTMetaAssemblyNames);
foreach (var asset in assets)
{
var handle = package.LoadRawFileAsync(asset);
yield return handle;
byte[] fileData = handle.GetRawFileData();
s_assetDatas[asset] = fileData;
Debug.Log($"dll:{asset} size:{fileData.Length}");
}
onDownloadComplete();
}
IEnumerator Download()
{
int downloadingMaxNum = 10;
int failedTryAgain = 3;
int timeout = 60;
var package = YooAssets.GetPackage("DefaultPackage");
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain, timeout);
//没有需要下载的资源
if (downloader.TotalDownloadCount == 0)
{
yield break;
}
//需要下载的文件总数和总大小
int totalDownloadCount = downloader.TotalDownloadCount;
long totalDownloadBytes = downloader.TotalDownloadBytes;
//注册回调方法
downloader.OnDownloadErrorCallback = OnDownloadErrorFunction;
downloader.OnDownloadProgressCallback = OnDownloadProgressUpdateFunction;
downloader.OnDownloadOverCallback = OnDownloadOverFunction;
downloader.OnStartDownloadFileCallback = OnStartDownloadFileFunction;
//开启下载
downloader.BeginDownload();
yield return downloader;
//检测下载结果
if (downloader.Status == EOperationStatus.Succeed)
{
//下载成功
Debug.Log("更新完成!");
//TODO:
}
else
{
//下载失败
Debug.LogError("更新失败!");
//TODO:
}
}
/// <summary>
/// 开始下载
/// </summary>
/// <param name="fileName"></param>
/// <param name="sizeBytes"></param>
/// <exception cref="NotImplementedException"></exception>
private void OnStartDownloadFileFunction(string fileName, long sizeBytes)
{
Debug.Log(string.Format("开始下载:文件名:{0}, 文件大小:{1}", fileName, sizeBytes));
}
/// <summary>
/// 下载完成
/// </summary>
/// <param name="isSucceed"></param>
/// <exception cref="NotImplementedException"></exception>
private void OnDownloadOverFunction(bool isSucceed)
{
Debug.Log("下载" + (isSucceed ? "成功" : "失败"));
}
/// <summary>
/// 更新中
/// </summary>
/// <param name="totalDownloadCount"></param>
/// <param name="currentDownloadCount"></param>
/// <param name="totalDownloadBytes"></param>
/// <param name="currentDownloadBytes"></param>
/// <exception cref="NotImplementedException"></exception>
private void OnDownloadProgressUpdateFunction(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes)
{
Debug.Log(string.Format("文件总数:{0}, 已下载文件数:{1}, 下载总大小:{2}, 已下载大小:{3}", totalDownloadCount, currentDownloadCount, totalDownloadBytes, currentDownloadBytes));
}
/// <summary>
/// 下载出错
/// </summary>
/// <param name="fileName"></param>
/// <param name="error"></param>
/// <exception cref="NotImplementedException"></exception>
private void OnDownloadErrorFunction(string fileName, string error)
{
Debug.LogError(string.Format("下载出错:文件名:{0}, 错误信息:{1}", fileName, error));
}
void StartGame()
{
LoadMetadataForAOTAssemblies();
#if !UNITY_EDITOR
System.Reflection.Assembly.Load(GetAssetData("HotSamples.dll"));
#endif
//委托加载方式加载prefab
var package = YooAssets.GetPackage("DefaultPackage");
AssetHandle handle = package.LoadAssetAsync<GameObject>("HotPrefab");
handle.Completed += Handle_Completed;
//AssetBundle prefabAb = AssetBundle.LoadFromMemory(GetAssetData("prefabs"));
//GameObject testPrefab = Instantiate(prefabAb.LoadAsset<GameObject>("HotUpdatePrefab.prefab"));
}
private void Handle_Completed(AssetHandle obj)
{
GameObject go = obj.InstantiateSync();
Debug.Log($"Prefab name is {go.name}");
}
/// <summary>
/// 为aot assembly加载原始metadata 这个代码放aot或者热更新都行。
/// 一旦加载后如果AOT泛型函数对应native实现不存在则自动替换为解释模式执行
/// </summary>
private static void LoadMetadataForAOTAssemblies()
{
/// 注意补充元数据是给AOT dll补充元数据而不是给热更新dll补充元数据。
/// 热更新dll不缺元数据不需要补充如果调用LoadMetadataForAOTAssembly会返回错误
///
HomologousImageMode mode = HomologousImageMode.SuperSet;
foreach (var aotDllName in AOTMetaAssemblyNames)
{
byte[] dllBytes = GetAssetData(aotDllName);
// 加载assembly对应的dll会自动为它hook。一旦aot泛型函数的native函数不存在用解释器版本代码
LoadImageErrorCode err = RuntimeApi.LoadMetadataForAOTAssembly(dllBytes, mode);
Debug.Log($"LoadMetadataForAOTAssembly:{aotDllName}. mode:{mode} ret:{err}");
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 21612b697232f004dbebce22c0000dd8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9e005776846e48c4a5e41f261eea14df
timeCreated: 1728875736

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5644558033ff4e3cb5af03aa0afdb5e0
timeCreated: 1728875898

View File

@@ -0,0 +1,104 @@
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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 426ff69263b7461194f0e87ff5b32100
timeCreated: 1728876063

View File

@@ -0,0 +1,53 @@
using System;
using System.Linq;
using System.Reflection;
using Cysharp.Threading.Tasks;
using HybridCLR;
using Plugins.SHFrame.SHGame.Procedure;
using SHFrame;
using SHFrame.FSM;
using YooAsset;
namespace HotMain.SHGame.Procedure
{
public class ProcedureLoadLauncher : ProcedureBase
{
private static Assembly _launcherAss;
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
CreatePackageDownloader(procedureOwner).Forget();
}
private async UniTask CreatePackageDownloader(IFsm<IProcedureManager> procedureOwner)
{
// 打包时内置在包体内的资源 直接先使用包体资源,实例化 登录加载界面后,再去检查是否需要下载更新
//加载AOT
await LoadMetadataForAOTAssemblies();
}
/// <summary>
/// 为aot assembly加载原始metadata 这个代码放aot或者热更新都行。
/// 一旦加载后如果AOT泛型函数对应native实现不存在则自动替换为解释模式执行
/// </summary>
private async UniTask LoadMetadataForAOTAssemblies()
{
var package = YooAssets.GetPackage(ProcedureInitializePackage.RawFilePackageName);
Log.Debug("加载AOT泛型dll数据");
// 注意补充元数据是给AOT dll补充元数据而不是给热更新dll补充元数据。
// 热更新dll不缺元数据不需要补充如果调用LoadMetadataForAOTAssembly会返回错误
var mode = HomologousImageMode.SuperSet;
foreach (var aotDllName in ProcedureInitializePackage.AotMetaAssemblyFiles)
{
var handle = package.LoadRawFileSync(aotDllName);
await handle.ToUniTask();
// 加载assembly对应的dll会自动为它hook。一旦aot泛型函数的native函数不存在用解释器版本代码
var err = RuntimeApi.LoadMetadataForAOTAssembly(handle.GetRawFileData(), mode);
Log.Debug($"LoadMetadataForAOTAssembly:{aotDllName}. mode:{mode} ret:{err}");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b77504dd9e24ad49ebed9a8def0fe26
timeCreated: 1728926184

View File

@@ -0,0 +1,70 @@
using Cysharp.Threading.Tasks;
using SHFrame;
using SHFrame.FSM;
using YooAsset;
namespace Plugins.SHFrame.SHGame.Procedure
{
/// <summary>
/// 更新资源清单
/// </summary>
public class ProcedureUpdatePackageManifest : ProcedureBase
{
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
UpdateManifest(procedureOwner).Forget();
}
private async UniTask UpdateManifest(IFsm<IProcedureManager> procedureOwner)
{
bool result = await UpdatePackageManifest(ProcedureInitializePackage.RawFilePackageName);
if (!result) return;
result = await UpdatePackageManifest(ProcedureInitializePackage.DefaultPackageName);
if (!result) return;
//切换到更新资源版本
ChangeState<ProcedureUpdatePackageVersion>(procedureOwner);
}
/// <summary>
/// 更新资源清单
/// </summary>
/// <returns></returns>
private async UniTask<bool> UpdatePackageManifest(string packageName)
{
ResourcePackage package = YooAssets.GetPackage(packageName);
//2.获取资源版本
UpdatePackageVersionOperation updateVerOperation = package.UpdatePackageVersionAsync(false);
await updateVerOperation.ToUniTask();
// TODO 如果初始化失败弹出提示界面
if (updateVerOperation.Status != EOperationStatus.Succeed)
{
//初始化失败了 弹出提示
Log.Error($"{package.PackageName} 获取远程资源版本信息失败: {updateVerOperation.Error}");
return false;
}
string packageVersion = updateVerOperation.PackageVersion;
Log.Debug($"Init {package.PackageName} version : {packageVersion}");
//3.更新补丁清单
UpdatePackageManifestOperation updateManifestOperation = package.UpdatePackageManifestAsync(packageVersion);
await updateManifestOperation.ToUniTask();
if (updateManifestOperation.Status != EOperationStatus.Succeed)
{
//更新失败了 弹出提示
Log.Error($"{package.PackageName} 更新资源版本清单失败: {updateManifestOperation.Error}");
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fa136220570f473bb1154a1aaf29a140
timeCreated: 1728877120

View File

@@ -0,0 +1,49 @@
using Cysharp.Threading.Tasks;
using HotMain.SHGame.Procedure;
using SHFrame;
using SHFrame.FSM;
using YooAsset;
namespace Plugins.SHFrame.SHGame.Procedure
{
/// <summary>
/// 更新资源版本号
/// </summary>
public class ProcedureUpdatePackageVersion : ProcedureBase
{
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
UpdatePackages(procedureOwner).Forget();
}
private async UniTask UpdatePackages(IFsm<IProcedureManager> procedureOwner)
{
bool result = await UpdatePackageVersion(ProcedureInitializePackage.RawFilePackageName);
if (!result) return;
result = await UpdatePackageVersion(ProcedureInitializePackage.DefaultPackageName);
if (!result) return;
//切换到更新资源版本
ChangeState<ProcedureLoadLauncher>(procedureOwner);
}
private async UniTask<bool> UpdatePackageVersion(string packageName)
{
ResourcePackage package = YooAssets.GetPackage(packageName);
//2.获取资源版本
UpdatePackageVersionOperation updateVerOperation = package.UpdatePackageVersionAsync(false);
await updateVerOperation.ToUniTask();
// TODO 如果初始化失败弹出提示界面
if (updateVerOperation.Status != EOperationStatus.Succeed)
{
Log.Error($"{package.PackageName} 获取远程资源版本信息失败: {updateVerOperation.Error}");
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a53059ce506d495ab8adb95ae52979d0
timeCreated: 1728877770

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bc65a4d37b5c4c51953baaaee48d2c76
timeCreated: 1728876983

View File

@@ -0,0 +1,89 @@
using System.IO;
using UnityEngine;
using YooAsset;
namespace Plugins.SHFrame.SHGame.YooAsset
{
public class RemoteServices : IRemoteServices
{
private string defaultHostServer;
private string fallbackHostServer;
public RemoteServices(string defaultHostServer, string fallbackHostServer)
{
this.defaultHostServer = defaultHostServer;
this.fallbackHostServer = fallbackHostServer;
}
public string GetRemoteMainURL(string fileName)
{
return defaultHostServer;
}
public string GetRemoteFallbackURL(string fileName)
{
return fallbackHostServer;
}
}
/// <summary>
/// 资源文件解密流
/// </summary>
public class BundleStream : FileStream
{
public const byte KEY = 64;
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
{
}
public BundleStream(string path, FileMode mode) : base(path, mode)
{
}
public override int Read(byte[] array, int offset, int count)
{
var index = base.Read(array, offset, count);
for (int i = 0; i < array.Length; i++)
{
array[i] ^= KEY;
}
return index;
}
}
/// <summary>
/// 资源文件流加载解密类
/// </summary>
public class FileStreamDecryption : IDecryptionServices
{
/// <summary>
/// 同步方式获取解密的资源包对象
/// 注意:加载流对象在资源包对象释放的时候会自动释放
/// </summary>
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
{
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
managedStream = bundleStream;
return AssetBundle.LoadFromStream(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
}
/// <summary>
/// 异步方式获取解密的资源包对象
/// 注意:加载流对象在资源包对象释放的时候会自动释放
/// </summary>
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
{
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
managedStream = bundleStream;
return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
}
private static uint GetManagedReadBufferSize()
{
return 1024;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2c2a4207de1f4b1995db5f2f3a8d6e62
timeCreated: 1728649446