mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
yoo2.2,9
yoo2.2,9
This commit is contained in:
@@ -49,8 +49,8 @@ namespace GameMain
|
||||
var downloader = GameModule.Resource.Downloader;
|
||||
|
||||
// 注册下载回调
|
||||
downloader.OnDownloadErrorCallback = OnDownloadErrorCallback;
|
||||
downloader.OnDownloadProgressCallback = OnDownloadProgressCallback;
|
||||
downloader.DownloadErrorCallback = OnDownloadErrorCallback;
|
||||
downloader.DownloadUpdateCallback = OnDownloadProgressCallback;
|
||||
downloader.BeginDownload();
|
||||
await downloader;
|
||||
|
||||
@@ -61,23 +61,23 @@ namespace GameMain
|
||||
ChangeState<ProcedureDownloadOver>(_procedureOwner);
|
||||
}
|
||||
|
||||
private void OnDownloadErrorCallback(string fileName, string error)
|
||||
private void OnDownloadErrorCallback(DownloadErrorData downloadErrorData)
|
||||
{
|
||||
UILoadTip.ShowMessageBox($"Failed to download file : {fileName}", MessageShowType.TwoButton,
|
||||
UILoadTip.ShowMessageBox($"Failed to download file : {downloadErrorData.FileName}", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Default,
|
||||
() => { ChangeState<ProcedureCreateDownloader>(_procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
|
||||
private void OnDownloadProgressCallback(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes)
|
||||
private void OnDownloadProgressCallback(DownloadUpdateData downloadUpdateData/*int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes*/)
|
||||
{
|
||||
string currentSizeMb = (currentDownloadBytes / 1048576f).ToString("f1");
|
||||
string totalSizeMb = (totalDownloadBytes / 1048576f).ToString("f1");
|
||||
string currentSizeMb = (downloadUpdateData.CurrentDownloadBytes / 1048576f).ToString("f1");
|
||||
string totalSizeMb = (downloadUpdateData.TotalDownloadBytes / 1048576f).ToString("f1");
|
||||
float progressPercentage = GameModule.Resource.Downloader.Progress * 100;
|
||||
string speed = Utility.File.GetLengthString((int)CurrentSpeed);
|
||||
|
||||
string line1 = Utility.Text.Format("正在更新,已更新 {0}/{1} ({2:F2}%)", currentDownloadCount, totalDownloadCount, progressPercentage);
|
||||
string line1 = Utility.Text.Format("正在更新,已更新 {0}/{1} ({2:F2}%)", downloadUpdateData.CurrentDownloadCount, downloadUpdateData.TotalDownloadCount, progressPercentage);
|
||||
string line2 = Utility.Text.Format("已更新大小 {0}MB/{1}MB", currentSizeMb, totalSizeMb);
|
||||
string line3 = Utility.Text.Format("当前网速 {0}/s,剩余时间 {1}", speed, GetRemainingTime(totalDownloadBytes, currentDownloadBytes, CurrentSpeed));
|
||||
string line3 = Utility.Text.Format("当前网速 {0}/s,剩余时间 {1}", speed, GetRemainingTime(downloadUpdateData.TotalDownloadBytes, downloadUpdateData.CurrentDownloadBytes, CurrentSpeed));
|
||||
|
||||
LoadUpdateLogic.Instance.DownProgressAction?.Invoke(GameModule.Resource.Downloader.Progress);
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"{line1}\n{line2}\n{line3}");
|
||||
|
@@ -73,7 +73,8 @@ namespace GameMain
|
||||
else if (playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
Log.Info("Package resource mode detected.");
|
||||
ChangeState<ProcedureInitResources>(procedureOwner);
|
||||
// ChangeState<ProcedureInitResources>(procedureOwner);
|
||||
ChangeState<ProcedureUpdateVersion>(procedureOwner);
|
||||
}
|
||||
// 可更新模式。
|
||||
else if (playMode == EPlayMode.HostPlayMode ||
|
||||
|
@@ -34,7 +34,7 @@ namespace GameMain
|
||||
{
|
||||
//更新成功
|
||||
//注意:保存资源版本号作为下次默认启动的版本!
|
||||
operation.SavePackageVersion();
|
||||
// operation.SavePackageVersion();
|
||||
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.WebPlayMode ||
|
||||
GameModule.Resource.UpdatableWhilePlaying)
|
||||
|
@@ -24,15 +24,20 @@ namespace GameMain
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"更新静态版本文件...");
|
||||
|
||||
//检查设备是否能够访问互联网
|
||||
if (Application.internetReachability == NetworkReachability.NotReachable)
|
||||
EPlayMode playMode = GameModule.Resource.PlayMode;
|
||||
|
||||
if (playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
Log.Warning("The device is not connected to the network");
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_Net_UnReachable);
|
||||
UILoadTip.ShowMessageBox(LoadText.Instance.Label_Net_UnReachable, MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
GetStaticVersion().Forget,
|
||||
() => { ChangeState<ProcedureInitResources>(procedureOwner); });
|
||||
//检查设备是否能够访问互联网
|
||||
if (Application.internetReachability == NetworkReachability.NotReachable)
|
||||
{
|
||||
Log.Warning("The device is not connected to the network");
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_Net_UnReachable);
|
||||
UILoadTip.ShowMessageBox(LoadText.Instance.Label_Net_UnReachable, MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
GetStaticVersion().Forget,
|
||||
() => { ChangeState<ProcedureInitResources>(procedureOwner); });
|
||||
}
|
||||
}
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_RequestVersionIng);
|
||||
@@ -46,7 +51,11 @@ namespace GameMain
|
||||
/// </summary>
|
||||
private async UniTaskVoid GetStaticVersion()
|
||||
{
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
|
||||
EPlayMode playMode = GameModule.Resource.PlayMode;
|
||||
if (playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
|
||||
}
|
||||
|
||||
var operation = GameModule.Resource.UpdatePackageVersionAsync();
|
||||
|
||||
@@ -59,7 +68,15 @@ namespace GameMain
|
||||
//线上最新版本operation.PackageVersion
|
||||
GameModule.Resource.PackageVersion = operation.PackageVersion;
|
||||
Log.Debug($"Updated package Version : from {GameModule.Resource.GetPackageVersion()} to {operation.PackageVersion}");
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
|
||||
if (playMode == EPlayMode.HostPlayMode || playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeState<ProcedureInitResources>(_procedureOwner);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -16,16 +16,8 @@ namespace TEngine.Editor.Inspector
|
||||
"WebPlayMode (WebGL运行模式)"
|
||||
};
|
||||
|
||||
private static readonly string[] _verifyLevelNames = new string[]
|
||||
{
|
||||
"Low (验证文件存在)",
|
||||
"Middle (验证文件大小)",
|
||||
"High (验证文件大小和CRC)"
|
||||
};
|
||||
|
||||
private SerializedProperty m_PlayMode = null;
|
||||
private SerializedProperty m_UpdatableWhilePlaying = null;
|
||||
private SerializedProperty m_VerifyLevel = null;
|
||||
private SerializedProperty m_Milliseconds = null;
|
||||
private SerializedProperty m_ReadWritePathType = null;
|
||||
private SerializedProperty m_MinUnloadUnusedAssetsInterval = null;
|
||||
@@ -39,7 +31,6 @@ namespace TEngine.Editor.Inspector
|
||||
private SerializedProperty m_FailedTryAgain = null;
|
||||
private SerializedProperty m_PackageName = null;
|
||||
private int m_ResourceModeIndex = 0;
|
||||
private int m_VerifyIndex = 0;
|
||||
|
||||
private int m_PackageNameIndex = 0;
|
||||
private string[] m_PackageNames;
|
||||
@@ -56,8 +47,6 @@ namespace TEngine.Editor.Inspector
|
||||
if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
|
||||
{
|
||||
EditorGUILayout.EnumPopup("Resource Mode", t.PlayMode);
|
||||
|
||||
EditorGUILayout.EnumPopup("VerifyLevel", t.VerifyLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -67,13 +56,6 @@ namespace TEngine.Editor.Inspector
|
||||
m_ResourceModeIndex = selectedIndex;
|
||||
m_PlayMode.enumValueIndex = selectedIndex;
|
||||
}
|
||||
|
||||
int selectedVerifyIndex = EditorGUILayout.Popup("VerifyLevel", m_VerifyIndex, _verifyLevelNames);
|
||||
if (selectedVerifyIndex != m_VerifyIndex)
|
||||
{
|
||||
m_VerifyIndex = selectedVerifyIndex;
|
||||
m_VerifyLevel.enumValueIndex = selectedVerifyIndex;
|
||||
}
|
||||
}
|
||||
|
||||
m_ReadWritePathType.enumValueIndex = (int)(ReadWritePathType)EditorGUILayout.EnumPopup("Read-Write Path Type", t.ReadWritePathType);
|
||||
@@ -244,7 +226,6 @@ namespace TEngine.Editor.Inspector
|
||||
{
|
||||
m_PlayMode = serializedObject.FindProperty("playMode");
|
||||
m_UpdatableWhilePlaying = serializedObject.FindProperty("m_UpdatableWhilePlaying");
|
||||
m_VerifyLevel = serializedObject.FindProperty("VerifyLevel");
|
||||
m_Milliseconds = serializedObject.FindProperty("Milliseconds");
|
||||
m_ReadWritePathType = serializedObject.FindProperty("m_ReadWritePathType");
|
||||
m_MinUnloadUnusedAssetsInterval = serializedObject.FindProperty("m_MinUnloadUnusedAssetsInterval");
|
||||
@@ -265,7 +246,6 @@ namespace TEngine.Editor.Inspector
|
||||
private void RefreshModes()
|
||||
{
|
||||
m_ResourceModeIndex = m_PlayMode.enumValueIndex > 0 ? m_PlayMode.enumValueIndex : 0;
|
||||
m_VerifyIndex = m_VerifyLevel.enumValueIndex > 0 ? m_VerifyLevel.enumValueIndex : 0;
|
||||
}
|
||||
|
||||
private void RefreshTypeNames()
|
||||
|
@@ -136,7 +136,6 @@ namespace TEngine.Editor
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = buildPipeline.ToString();
|
||||
buildParameters.BuildTarget = buildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.IncrementalBuild;
|
||||
buildParameters.PackageName = "DefaultPackage";
|
||||
buildParameters.PackageVersion = packageVersion;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
|
@@ -16,7 +16,7 @@ public class FileOffsetEncryption : IEncryptionServices
|
||||
}
|
||||
|
||||
int offset = 32;
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FilePath);
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
var encryptedData = new byte[fileData.Length + offset];
|
||||
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class FileStreamEncryption : IEncryptionServices
|
||||
|
||||
}
|
||||
|
||||
var fileData = File.ReadAllBytes(fileInfo.FilePath);
|
||||
var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
for (int i = 0; i < fileData.Length; i++)
|
||||
{
|
||||
fileData[i] ^= BundleStream.KEY;
|
||||
|
@@ -26,11 +26,6 @@ namespace TEngine
|
||||
/// </summary>
|
||||
EPlayMode PlayMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存系统启动时的验证级别。
|
||||
/// </summary>
|
||||
EVerifyLevel VerifyLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 同时下载的最大数目。
|
||||
/// </summary>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using GameFramework.Runtime;
|
||||
using UnityEngine;
|
||||
@@ -21,41 +22,63 @@ namespace TEngine
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
}
|
||||
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件流加载解密类
|
||||
/// </summary>
|
||||
private class FileStreamDecryption : IDecryptionServices
|
||||
public class FileStreamDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStream(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = bundleStream;
|
||||
decryptResult.Result = AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = bundleStream;
|
||||
decryptResult.CreateRequest = AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static uint GetManagedReadBufferSize()
|
||||
@@ -64,29 +87,68 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件偏移加密方式
|
||||
/// </summary>
|
||||
public class FileOffsetEncryption : IEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
{
|
||||
int offset = 32;
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
var encryptedData = new byte[fileData.Length + offset];
|
||||
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||||
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.Encrypted = true;
|
||||
result.EncryptedData = encryptedData;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件偏移加载解密类
|
||||
/// </summary>
|
||||
private class FileOffsetDecryption : IDecryptionServices
|
||||
public class FileOffsetDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||
{
|
||||
managedStream = null;
|
||||
return AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.ConentCRC, GetFileOffset());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = null;
|
||||
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||
{
|
||||
managedStream = null;
|
||||
return AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.ConentCRC, GetFileOffset());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = null;
|
||||
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static ulong GetFileOffset()
|
||||
@@ -122,176 +184,4 @@ namespace TEngine
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices : IBuildinQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询内置文件的时候,是否比对文件哈希值
|
||||
/// </summary>
|
||||
public static bool CompareFileCRC = false;
|
||||
|
||||
public bool Query(string packageName, string fileName, string fileCRC)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return StreamingAssetsHelper.FileExists(packageName, fileName, fileCRC);
|
||||
}
|
||||
}
|
||||
|
||||
public class StreamingAssetsDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// 根目录名称(保持和YooAssets资源系统一致)
|
||||
/// </summary>
|
||||
public const string RootFolderName = "package";
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public static bool FileExists(string packageName, string fileName, string fileCRC)
|
||||
{
|
||||
string filePath = Path.Combine(Application.streamingAssetsPath, StreamingAssetsDefine.RootFolderName, packageName, fileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
if (GameQueryServices.CompareFileCRC)
|
||||
{
|
||||
string crc32 = YooAsset.HashUtility.FileCRC32(filePath);
|
||||
return crc32 == fileCRC;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
private class PackageQuery
|
||||
{
|
||||
public readonly Dictionary<string, BuildinFileManifest.Element> Elements = new Dictionary<string, BuildinFileManifest.Element>(1000);
|
||||
}
|
||||
|
||||
private static bool _isInit = false;
|
||||
private static readonly Dictionary<string, PackageQuery> _packages = new Dictionary<string, PackageQuery>(10);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public static void Init()
|
||||
{
|
||||
if (_isInit == false)
|
||||
{
|
||||
_isInit = true;
|
||||
|
||||
var manifest = Resources.Load<BuildinFileManifest>("BuildinFileManifest");
|
||||
if (manifest != null)
|
||||
{
|
||||
foreach (var element in manifest.BuildinFiles)
|
||||
{
|
||||
if (_packages.TryGetValue(element.PackageName, out PackageQuery package) == false)
|
||||
{
|
||||
package = new PackageQuery();
|
||||
_packages.Add(element.PackageName, package);
|
||||
}
|
||||
package.Elements.Add(element.FileName, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询方法
|
||||
/// </summary>
|
||||
public static bool FileExists(string packageName, string fileName, string fileCRC32)
|
||||
{
|
||||
if (_isInit == false)
|
||||
Init();
|
||||
|
||||
if (_packages.TryGetValue(packageName, out PackageQuery package) == false)
|
||||
return false;
|
||||
|
||||
if (package.Elements.TryGetValue(fileName, out var element) == false)
|
||||
return false;
|
||||
|
||||
if (GameQueryServices.CompareFileCRC)
|
||||
{
|
||||
return element.FileCRC32 == fileCRC32;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在构建应用程序前处理
|
||||
/// 原理:在构建APP之前,搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入内置清单,内置清单存储在Resources文件夹下。
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
{
|
||||
string saveFilePath = "Assets/AATemp/Resources/BuildinFileManifest.asset";
|
||||
if (File.Exists(saveFilePath))
|
||||
{
|
||||
File.Delete(saveFilePath);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}";
|
||||
DirectoryInfo root = new DirectoryInfo(folderPath);
|
||||
if (root.Exists == false)
|
||||
{
|
||||
Debug.LogWarning($"没有发现YooAsset内置目录 : {folderPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
||||
FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories);
|
||||
foreach (var fileInfo in files)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta")
|
||||
continue;
|
||||
if (fileInfo.Name.StartsWith("PackageManifest_"))
|
||||
continue;
|
||||
|
||||
BuildinFileManifest.Element element = new BuildinFileManifest.Element();
|
||||
element.PackageName = fileInfo.Directory.Name;
|
||||
element.FileCRC32 = YooAsset.HashUtility.FileCRC32(fileInfo.FullName);
|
||||
element.FileName = fileInfo.Name;
|
||||
manifest.BuildinFiles.Add(element);
|
||||
}
|
||||
|
||||
if (Directory.Exists("Assets/AATemp/Resources") == false)
|
||||
Directory.CreateDirectory("Assets/AATemp/Resources");
|
||||
UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
Debug.Log($"一共{manifest.BuildinFiles.Count}个内置文件,内置资源清单保存成功 : {saveFilePath}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -29,11 +29,6 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public EPlayMode PlayMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件校验等级。
|
||||
/// </summary>
|
||||
public EVerifyLevel VerifyLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
||||
/// </summary>
|
||||
@@ -210,9 +205,11 @@ namespace TEngine
|
||||
InitializationOperation initializationOperation = null;
|
||||
if (playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
var buildResult = EditorSimulateModeHelper.SimulateBuild(packageName);
|
||||
var packageRoot = buildResult.PackageRootDirectory;
|
||||
var createParameters = new EditorSimulateModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(EDefaultBuildPipeline.BuiltinBuildPipeline, packageName);
|
||||
createParameters.EditorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(packageRoot);
|
||||
createParameters.EditorFileSystemParameters.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES,new FileOffsetEncryption());
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -220,8 +217,7 @@ namespace TEngine
|
||||
if (playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var createParameters = new OfflinePlayModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.DecryptionServices = new FileStreamDecryption();
|
||||
createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -230,31 +226,30 @@ namespace TEngine
|
||||
{
|
||||
string defaultHostServer = HostServerURL;
|
||||
string fallbackHostServer = FallbackHostServerURL;
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
var createParameters = new HostPlayModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.DecryptionServices = new FileStreamDecryption();
|
||||
createParameters.BuildinQueryServices = new GameQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
||||
createParameters.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
// WebGL运行模式
|
||||
if (playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
string defaultHostServer = HostServerURL;
|
||||
string fallbackHostServer = FallbackHostServerURL;
|
||||
var createParameters = new WebPlayModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.DecryptionServices = new FileStreamDecryption();
|
||||
createParameters.BuildinQueryServices = new GameQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME && !UNITY_EDITOR
|
||||
string defaultHostServer = GetHostServerURL();
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
createParameters.WebServerFileSystemParameters = WechatFileSystemCreater.CreateWechatFileSystemParameters(remoteServices);
|
||||
#else
|
||||
createParameters.WebServerFileSystemParameters = FileSystemParameters.CreateDefaultWebServerFileSystemParameters();
|
||||
#endif
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
await initializationOperation.ToUniTask();
|
||||
|
||||
Log.Info($"Init resource package version : {initializationOperation?.PackageVersion}");
|
||||
|
||||
return initializationOperation;
|
||||
}
|
||||
|
||||
@@ -268,9 +263,6 @@ namespace TEngine
|
||||
m_AssetPool = null;
|
||||
_assetLoadingList.Clear();
|
||||
_assetInfoMap.Clear();
|
||||
#if !UNITY_WEBGL
|
||||
YooAssets.Destroy();
|
||||
#endif
|
||||
}
|
||||
|
||||
#region Public Methods
|
||||
@@ -950,7 +942,7 @@ namespace TEngine
|
||||
{
|
||||
if (package is { InitializeStatus: EOperationStatus.Succeed })
|
||||
{
|
||||
package.UnloadUnusedAssets();
|
||||
package.UnloadUnusedAssetsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -966,7 +958,7 @@ namespace TEngine
|
||||
{
|
||||
if (package is { InitializeStatus: EOperationStatus.Succeed })
|
||||
{
|
||||
package.ForceUnloadAllAssets();
|
||||
package.UnloadAllAssetsAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -95,11 +95,6 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public bool UpdatableWhilePlaying => m_UpdatableWhilePlaying;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件校验等级。
|
||||
/// </summary>
|
||||
public EVerifyLevel VerifyLevel = EVerifyLevel.Middle;
|
||||
|
||||
[SerializeField] private ReadWritePathType m_ReadWritePathType = ReadWritePathType.Unspecified;
|
||||
|
||||
/// <summary>
|
||||
@@ -297,7 +292,6 @@ namespace TEngine
|
||||
|
||||
m_ResourceManager.DefaultPackageName = PackageName;
|
||||
m_ResourceManager.PlayMode = PlayMode;
|
||||
m_ResourceManager.VerifyLevel = VerifyLevel;
|
||||
m_ResourceManager.Milliseconds = Milliseconds;
|
||||
m_ResourceManager.InstanceRoot = transform;
|
||||
m_ResourceManager.HostServerURL = SettingsUtils.GetResDownLoadPath();
|
||||
@@ -350,29 +344,27 @@ namespace TEngine
|
||||
/// <param name="timeout">超时时间。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>请求远端包裹的最新版本操作句柄。</returns>
|
||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = false, int timeout = 60,
|
||||
public RequestPackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = false, int timeout = 60,
|
||||
string customPackageName = "")
|
||||
{
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.UpdatePackageVersionAsync(appendTimeTicks, timeout);
|
||||
return package.RequestPackageVersionAsync(appendTimeTicks, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">更新的包裹版本</param>
|
||||
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion,
|
||||
bool autoSaveVersion = true, int timeout = 60, string customPackageName = "")
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60, string customPackageName = "")
|
||||
{
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
|
||||
return package.UpdatePackageManifestAsync(packageVersion, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -404,12 +396,12 @@ namespace TEngine
|
||||
/// 清理包裹未使用的缓存文件。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync(string customPackageName = "")
|
||||
public ClearCacheFilesOperation ClearUnusedCacheFilesAsync(string customPackageName = "")
|
||||
{
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.ClearUnusedCacheFilesAsync();
|
||||
return package.ClearCacheFilesAsync(EFileClearMode.ClearUnusedBundleFiles);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -421,7 +413,7 @@ namespace TEngine
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
package.ClearPackageSandbox();
|
||||
package.ClearCacheFilesAsync(EFileClearMode.ClearAllBundleFiles);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@@ -43,13 +43,6 @@ namespace TEngine
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool UnSuspend(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
|
@@ -84,16 +84,6 @@ namespace TEngine
|
||||
return _sceneModule.UnSuspend(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location)
|
||||
{
|
||||
return _sceneModule.IsMainScene(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
|
@@ -63,7 +63,7 @@ namespace TEngine
|
||||
Log.Warning($"Could not load subScene while already loaded. Scene: {location}");
|
||||
return subScene;
|
||||
}
|
||||
subScene = YooAssets.LoadSceneAsync(location, sceneMode, suspendLoad, (uint)priority);
|
||||
subScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None,suspendLoad, (uint)priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
@@ -88,7 +88,7 @@ namespace TEngine
|
||||
|
||||
_currentMainSceneName = location;
|
||||
|
||||
_currentMainScene = YooAssets.LoadSceneAsync(location, sceneMode, suspendLoad, (uint)priority);
|
||||
_currentMainScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, (uint)priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
@@ -169,30 +169,6 @@ namespace TEngine
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location)
|
||||
{
|
||||
if (_currentMainSceneName.Equals(location))
|
||||
{
|
||||
if (_currentMainScene != null)
|
||||
{
|
||||
return _currentMainScene.IsMainScene();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
_subScenes.TryGetValue(location, out SceneHandle subScene);
|
||||
if (subScene != null)
|
||||
{
|
||||
return subScene.IsMainScene();
|
||||
}
|
||||
Log.Warning($"IsMainScene invalid location:{location}");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user