mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
升级YooAsset->2.1.1、UniTask->2.5.4
升级YooAsset->2.1.1、UniTask->2.5.4
This commit is contained in:
@@ -111,7 +111,7 @@ namespace YooAsset
|
||||
// 再验证文件CRC
|
||||
if (verifyLevel == EVerifyLevel.High)
|
||||
{
|
||||
string crc = HashUtility.FileCRC32(filePath);
|
||||
string crc = HashUtility.FileCRC32Safely(filePath);
|
||||
if (crc == fileCRC)
|
||||
return EVerifyResult.Succeed;
|
||||
else
|
||||
|
@@ -23,6 +23,8 @@ namespace YooAsset
|
||||
return new System.Uri(path).ToString();
|
||||
#elif UNITY_STANDALONE
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_OPENHARMONY
|
||||
return path;
|
||||
#else
|
||||
return path;
|
||||
#endif
|
||||
|
@@ -58,7 +58,12 @@ namespace YooAsset
|
||||
}
|
||||
private static string CreateDefaultBuildinRoot()
|
||||
{
|
||||
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
string path = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#if UNITY_OPENHARMONY
|
||||
return $"file://{path}";
|
||||
#else
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
private static string CreateDefaultSandboxRoot()
|
||||
{
|
||||
@@ -176,6 +181,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void SaveSandboxPackageVersionFile(string version)
|
||||
{
|
||||
YooLogger.Log($"Save package version : {version}");
|
||||
string filePath = GetSandboxPackageVersionFilePath();
|
||||
FileUtility.WriteAllText(filePath, version);
|
||||
}
|
||||
|
@@ -150,5 +150,10 @@ namespace YooAsset
|
||||
/// 内置资源查询服务接口
|
||||
/// </summary>
|
||||
public IBuildinQueryServices BuildinQueryServices = null;
|
||||
|
||||
/// <summary>
|
||||
/// 微信缓存查询服务接口
|
||||
/// </summary>
|
||||
public IWechatQueryServices WechatQueryServices = null;
|
||||
}
|
||||
}
|
@@ -100,28 +100,21 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (SceneObject.IsValid())
|
||||
if (Provider is DatabaseSceneProvider)
|
||||
{
|
||||
if (Provider is DatabaseSceneProvider)
|
||||
{
|
||||
var temp = Provider as DatabaseSceneProvider;
|
||||
return temp.UnSuspendLoad();
|
||||
}
|
||||
else if (Provider is BundledSceneProvider)
|
||||
{
|
||||
var temp = Provider as BundledSceneProvider;
|
||||
return temp.UnSuspendLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
var provider = Provider as DatabaseSceneProvider;
|
||||
provider.UnSuspendLoad();
|
||||
}
|
||||
else if (Provider is BundledSceneProvider)
|
||||
{
|
||||
var provider = Provider as BundledSceneProvider;
|
||||
provider.UnSuspendLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Scene is invalid : {SceneObject.name}");
|
||||
return false;
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -31,6 +31,22 @@ namespace YooAsset
|
||||
{
|
||||
_error = null;
|
||||
_provider = provider;
|
||||
|
||||
// 注意:卸载场景前必须先解除挂起操作
|
||||
if (provider is DatabaseSceneProvider)
|
||||
{
|
||||
var temp = provider as DatabaseSceneProvider;
|
||||
temp.UnSuspendLoad();
|
||||
}
|
||||
else if (provider is BundledSceneProvider)
|
||||
{
|
||||
var temp = provider as BundledSceneProvider;
|
||||
temp.UnSuspendLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
|
@@ -9,14 +9,14 @@ namespace YooAsset
|
||||
internal sealed class BundledSceneProvider : ProviderBase
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private readonly bool _suspendLoad;
|
||||
private AsyncOperation _asyncOperation;
|
||||
private bool _suspendLoadMode;
|
||||
|
||||
public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoad = suspendLoad;
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
@@ -80,7 +80,7 @@ namespace YooAsset
|
||||
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
_asyncOperation.priority = 100;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.Checking;
|
||||
@@ -106,6 +106,13 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoadMode == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
@@ -128,13 +135,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作
|
||||
/// </summary>
|
||||
public bool UnSuspendLoad()
|
||||
public void UnSuspendLoad()
|
||||
{
|
||||
if (_asyncOperation == null)
|
||||
return false;
|
||||
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
return true;
|
||||
if (IsDone == false)
|
||||
{
|
||||
_suspendLoadMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,14 +9,14 @@ namespace YooAsset
|
||||
internal sealed class DatabaseSceneProvider : ProviderBase
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private readonly bool _suspendLoad;
|
||||
private bool _suspendLoadMode;
|
||||
private AsyncOperation _asyncOperation;
|
||||
|
||||
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoad = suspendLoad;
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
@@ -69,7 +69,7 @@ namespace YooAsset
|
||||
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
_asyncOperation.priority = 100;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.Checking;
|
||||
@@ -95,6 +95,13 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoadMode == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
@@ -118,13 +125,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作
|
||||
/// </summary>
|
||||
public bool UnSuspendLoad()
|
||||
public void UnSuspendLoad()
|
||||
{
|
||||
if (_asyncOperation == null)
|
||||
return false;
|
||||
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
return true;
|
||||
if (IsDone == false)
|
||||
{
|
||||
_suspendLoadMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -332,6 +332,7 @@ namespace YooAsset
|
||||
{
|
||||
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||
_impl.FlushManifestVersionFile(); //注意:解压内置清单并加载成功后保存该清单版本。
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
|
@@ -77,7 +77,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
string fileHash = HashUtility.FileMD5(_manifestFilePath);
|
||||
string fileHash = HashUtility.FileMD5Safely(_manifestFilePath);
|
||||
if (fileHash != _queryCachePackageHashOp.PackageHash)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
@@ -63,7 +63,6 @@ namespace YooAsset
|
||||
TryLoadCacheManifest,
|
||||
DownloadManifest,
|
||||
LoadCacheManifest,
|
||||
CheckDeserializeManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,7 @@ namespace YooAsset
|
||||
private ResourceAssist _assist;
|
||||
private IBuildinQueryServices _buildinQueryServices;
|
||||
private IRemoteServices _remoteServices;
|
||||
private IWechatQueryServices _wechatQueryServices;
|
||||
|
||||
public readonly string PackageName;
|
||||
public DownloadManager Download
|
||||
@@ -34,11 +35,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices)
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices, IWechatQueryServices wechatQueryServices)
|
||||
{
|
||||
_assist = assist;
|
||||
_buildinQueryServices = buildinQueryServices;
|
||||
_remoteServices = remoteServices;
|
||||
_wechatQueryServices = wechatQueryServices;
|
||||
|
||||
var operation = new WebPlayModeInitializationOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
@@ -65,23 +67,13 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
#if UNITY_WECHAT_GAME
|
||||
private WeChatWASM.WXFileSystemManager _wxFileSystemMgr;
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
if (_wxFileSystemMgr == null)
|
||||
_wxFileSystemMgr = WeChatWASM.WX.GetFileSystemManager();
|
||||
string filePath = WeChatWASM.WX.env.USER_DATA_PATH + packageBundle.FileName;
|
||||
string result = _wxFileSystemMgr.AccessSync(filePath);
|
||||
return result.Equals("access:ok");
|
||||
if (_wechatQueryServices != null)
|
||||
return _wechatQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
|
@@ -184,7 +184,8 @@ namespace YooAsset
|
||||
var initializeParameters = parameters as WebPlayModeParameters;
|
||||
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
|
||||
initializeParameters.BuildinQueryServices,
|
||||
initializeParameters.RemoteServices);
|
||||
initializeParameters.RemoteServices,
|
||||
initializeParameters.WechatQueryServices);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public interface IWechatQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询是否为微信缓存的资源文件
|
||||
/// </summary>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
|
||||
/// <param name="fileCRC">文件哈希值</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
bool Query(string packageName, string fileName, string fileCRC);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6b28ce9425f5eb4f972dcda9fd864f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -214,13 +214,21 @@ namespace YooAsset
|
||||
/// 获取文件的Hash值
|
||||
/// </summary>
|
||||
public static string FileSHA1(string filePath)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamSHA1(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的Hash值
|
||||
/// </summary>
|
||||
public static string FileSHA1Safely(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamSHA1(fs);
|
||||
}
|
||||
return FileSHA1(filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -266,13 +274,21 @@ namespace YooAsset
|
||||
/// 获取文件的MD5
|
||||
/// </summary>
|
||||
public static string FileMD5(string filePath)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamMD5(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的MD5
|
||||
/// </summary>
|
||||
public static string FileMD5Safely(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamMD5(fs);
|
||||
}
|
||||
return FileMD5(filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -316,13 +332,21 @@ namespace YooAsset
|
||||
/// 获取文件的CRC32
|
||||
/// </summary>
|
||||
public static string FileCRC32(string filePath)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamCRC32(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的CRC32
|
||||
/// </summary>
|
||||
public static string FileCRC32Safely(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamCRC32(fs);
|
||||
}
|
||||
return FileCRC32(filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user