Compare commits

...

11 Commits

Author SHA1 Message Date
何冠峰 fcc729a0bf Update CHANGELOG.md 2025-03-08 15:53:46 +08:00
何冠峰 d10e54248b Update package.json 2025-03-08 15:53:35 +08:00
何冠峰 b84800a905 update assembly 2025-03-08 15:51:27 +08:00
何冠峰 8ccd7e552c fix #498 2025-03-08 15:41:03 +08:00
何冠峰 772ba484eb Update HandleFactory.cs 2025-03-08 15:01:19 +08:00
何冠峰 cdbedee705 update asmdef
YooAsset版本宏定义
2025-03-08 14:34:41 +08:00
何冠峰 10cce48e71
Merge pull request #497 from Y-way/support-macros
Support DefineConstants for YooAsset Package
2025-03-08 12:05:07 +08:00
何冠峰 13e8410d80 fix #389 2025-03-08 11:50:35 +08:00
何冠峰 6f07faf4da fix #495 2025-03-08 11:24:17 +08:00
何冠峰 e3228d406e update resource manager
优化Handle生成和移除逻辑
2025-03-08 10:58:19 +08:00
Y-way 9bcbc10862 Support DefineConstants for YooAsset Package
自定义YOO_VERSION_2  以及版本管理宏,用于YooAsset升级时的宏定义处理
2025-03-07 15:00:20 +08:00
23 changed files with 344 additions and 35 deletions

View File

@ -2,12 +2,41 @@
All notable changes to this package will be documented in this file.
## [2.3.4-preview] - 2025-03-08
### Improvements
- YooAsset支持了版本宏定义。
```csharp
YOO_ASSET_2
YOO_ASSET_2_3
YOO_ASSET_2_3_OR_NEWER
```
### Fixed
- (#389) 修复了禁用域重载(Reload Domain)的情况下,再次启动游戏报错的问题。
- (#496) 修复了文件系统参数RESUME_DOWNLOAD_MINMUM_SIZE传入int值会导致异常的错误。
- (#498) 修复了v2.3版本尝试加载安卓包内的原生资源包失败的问题。
### Added
- 新增了YooAssets.GetAllPackages()方法
```csharp
/// <summary>
/// 获取所有资源包裹
/// </summary>
public static List<ResourcePackage> GetAllPackages()
```
## [2.3.3-preview] - 2025-03-06
### Improvements
- 新增了异步操作任务调试器AssetBundleDebugger窗口-->OperationView视图模式
- 编辑器下模拟构建默认启用依赖关系数据库,可以大幅增加编辑器下开始游戏时间。
- 编辑器下模拟构建默认启用依赖关系数据库,可以大幅降低编辑器下启动游戏的时间。
- 单元测试用例增加加密解密测试用例。
### Fixed

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fab3cd742c11be2479b07f5d447a78c9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,109 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using UnityEditor;
namespace YooAsset.Editor
{
[InitializeOnLoad]
public class MacrosProcessor : AssetPostprocessor
{
static MacrosProcessor()
{
}
/// <summary>
/// YooAsset版本宏定义
/// </summary>
private static readonly List<string> YooAssetMacros = new List<string>()
{
"YOO_ASSET_2",
"YOO_ASSET_2_3",
"YOO_ASSET_2_3_OR_NEWER",
};
static string OnGeneratedCSProject(string path, string content)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(content);
if (IsCSProjectReferenced(xmlDoc.DocumentElement) == false)
return content;
if (ProcessDefineConstants(xmlDoc.DocumentElement) == false)
return content;
// 将修改后的XML结构重新输出为文本
var stringWriter = new StringWriter();
var writerSettings = new XmlWriterSettings();
writerSettings.Indent = true;
var xmlWriter = XmlWriter.Create(stringWriter, writerSettings);
xmlDoc.WriteTo(xmlWriter);
xmlWriter.Flush();
return stringWriter.ToString();
}
/// <summary>
/// 处理宏定义
/// </summary>
private static bool ProcessDefineConstants(XmlElement element)
{
if (element == null)
return false;
bool processed = false;
foreach (XmlNode node in element.ChildNodes)
{
if (node.Name != "PropertyGroup")
continue;
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.Name != "DefineConstants")
continue;
string[] defines = childNode.InnerText.Split(';');
HashSet<string> hashSets = new HashSet<string>(defines);
foreach (string yooMacro in YooAssetMacros)
{
string tmpMacro = yooMacro.Trim();
if (hashSets.Contains(tmpMacro) == false)
hashSets.Add(tmpMacro);
}
childNode.InnerText = string.Join(";", hashSets.ToArray());
processed = true;
}
}
return processed;
}
/// <summary>
/// 检测工程是否引用了YooAsset
/// </summary>
private static bool IsCSProjectReferenced(XmlElement element)
{
if (element == null)
return false;
foreach (XmlNode node in element.ChildNodes)
{
if (node.Name != "ItemGroup")
continue;
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.Name != "Reference" && childNode.Name != "ProjectReference")
continue;
string include = childNode.Attributes["Include"].Value;
if (include.Contains("YooAsset"))
return true;
}
}
return false;
}
}
}

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 569f60ef80f74a642bac91eca0b20a2b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7,6 +7,15 @@ namespace YooAsset
{
internal class RemoteDebuggerInRuntime : MonoBehaviour
{
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
_sampleOnce = false;
_autoSample = false;
}
#endif
private static bool _sampleOnce = false;
private static bool _autoSample = false;

View File

@ -8,6 +8,14 @@ namespace YooAsset
{
internal class RemoteEditorConnection
{
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
_instance = null;
}
#endif
private static RemoteEditorConnection _instance;
public static RemoteEditorConnection Instance
{

View File

@ -8,6 +8,14 @@ namespace YooAsset
{
internal class RemotePlayerConnection
{
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
_instance = null;
}
#endif
private static RemotePlayerConnection _instance;
public static RemotePlayerConnection Instance
{

View File

@ -1,4 +1,5 @@
using UnityEngine.Networking;
using UnityEngine;
namespace YooAsset
{
@ -9,6 +10,14 @@ namespace YooAsset
internal class DownloadSystemHelper
{
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
UnityWebRequestCreater = null;
}
#endif
public static UnityWebRequestDelegate UnityWebRequestCreater = null;
public static UnityWebRequest NewUnityWebRequestGet(string requestURL)
{

View File

@ -6,6 +6,14 @@ namespace YooAsset
{
internal class WebRequestCounter
{
#if UNITY_EDITOR
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
_requestFailedRecorder.Clear();
}
#endif
/// <summary>
/// 记录网络请求失败事件的次数
/// </summary>

View File

@ -239,6 +239,11 @@ namespace YooAsset
if (Exists(bundle) == false)
return null;
#if UNITY_ANDROID
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
YooLogger.Error($"Android platform not support read buildin bundle file data !");
return null;
#else
if (bundle.Encrypted)
{
if (DecryptionServices == null)
@ -261,6 +266,7 @@ namespace YooAsset
string filePath = GetBuildinFileLoadPath(bundle);
return FileUtility.ReadAllBytes(filePath);
}
#endif
}
public virtual string ReadBundleFileText(PackageBundle bundle)
{
@ -270,6 +276,11 @@ namespace YooAsset
if (Exists(bundle) == false)
return null;
#if UNITY_ANDROID
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
YooLogger.Error($"Android platform not support read buildin bundle file text !");
return null;
#else
if (bundle.Encrypted)
{
if (DecryptionServices == null)
@ -292,6 +303,7 @@ namespace YooAsset
string filePath = GetBuildinFileLoadPath(bundle);
return FileUtility.ReadAllText(filePath);
}
#endif
}
#region 内部方法

View File

@ -176,6 +176,12 @@ namespace YooAsset
if (_steps == ESteps.LoadBuildinRawBundle)
{
#if UNITY_ANDROID
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
_steps = ESteps.Done;
Result = new RawBundleResult(_fileSystem, _bundle);
Status = EOperationStatus.Succeed;
#else
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
if (File.Exists(filePath))
{
@ -190,6 +196,7 @@ namespace YooAsset
Error = $"Can not found buildin raw bundle file : {filePath}";
YooLogger.Error(Error);
}
#endif
}
}
internal override void InternalWaitForAsyncComplete()

View File

@ -6,6 +6,14 @@ namespace YooAsset
{
internal class OperationSystem
{
#if UNITY_EDITOR
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
DestroyAll();
}
#endif
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(1000);
private static readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(1000);

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
namespace YooAsset
{
internal static class HandleFactory
{
private static readonly Dictionary<Type, Func<ProviderOperation, HandleBase>> _handleFactory = new Dictionary<Type, Func<ProviderOperation, HandleBase>>()
{
{ typeof(AssetHandle), op => new AssetHandle(op) },
{ typeof(SceneHandle), op => new SceneHandle(op) },
{ typeof(SubAssetsHandle), op => new SubAssetsHandle(op) },
{ typeof(AllAssetsHandle), op => new AllAssetsHandle(op) },
{ typeof(RawFileHandle), op => new RawFileHandle(op) }
};
public static HandleBase CreateHandle(ProviderOperation operation, Type type)
{
if (_handleFactory.TryGetValue(type, out var factory) == false)
{
throw new NotImplementedException($"Handle type {type.FullName} is not supported.");
}
return factory(operation);
}
}
}

View File

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

View File

@ -1,7 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System;
using System.Linq;
namespace YooAsset
{
@ -69,8 +69,8 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
private readonly LoadBundleFileOperation _mainBundleLoader;
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>();
private readonly List<HandleBase> _handles = new List<HandleBase>();
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>(10);
private readonly HashSet<HandleBase> _handles = new HashSet<HandleBase>();
public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
@ -220,20 +220,7 @@ namespace YooAsset
// 引用计数增加
RefCount++;
HandleBase handle;
if (typeof(T) == typeof(AssetHandle))
handle = new AssetHandle(this);
else if (typeof(T) == typeof(SceneHandle))
handle = new SceneHandle(this);
else if (typeof(T) == typeof(SubAssetsHandle))
handle = new SubAssetsHandle(this);
else if (typeof(T) == typeof(AllAssetsHandle))
handle = new AllAssetsHandle(this);
else if (typeof(T) == typeof(RawFileHandle))
handle = new RawFileHandle(this);
else
throw new System.NotImplementedException();
HandleBase handle = HandleFactory.CreateHandle(this, typeof(T));
_handles.Add(handle);
return handle as T;
}
@ -258,9 +245,9 @@ namespace YooAsset
/// </summary>
public void ReleaseAllHandles()
{
for (int i = _handles.Count - 1; i >= 0; i--)
List<HandleBase> tempers = _handles.ToList();
foreach (var handle in tempers)
{
var handle = _handles[i];
handle.Release();
}
}
@ -276,7 +263,7 @@ namespace YooAsset
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
// 注意:回调方法如果发生异常,会阻断列表里的后续回调方法!
List<HandleBase> tempers = new List<HandleBase>(_handles);
List<HandleBase> tempers = _handles.ToList();
foreach (var hande in tempers)
{
if (hande.IsValid)

View File

@ -5,6 +5,14 @@ namespace YooAsset
{
public static class YooAssetSettingsData
{
#if UNITY_EDITOR
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
_setting = null;
}
#endif
private static YooAssetSettings _setting = null;
internal static YooAssetSettings Setting
{

View File

@ -9,6 +9,22 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.tuyoogame.yooasset",
"expression": "",
"define": "YOO_ASSET_2"
},
{
"name": "com.tuyoogame.yooasset",
"expression": "2.3",
"define": "YOO_ASSET_2_3"
},
{
"name": "com.tuyoogame.yooasset",
"expression": "2.3",
"define": "YOO_ASSET_2_3_OR_NEWER"
}
],
"noEngineReferences": false
}

View File

@ -2,12 +2,23 @@ using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace YooAsset
{
public static partial class YooAssets
{
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
_isInitialize = false;
_packages.Clear();
_defaultPackage = null;
}
#endif
private static bool _isInitialize = false;
private static GameObject _driver = null;
private static readonly List<ResourcePackage> _packages = new List<ResourcePackage>();
@ -77,9 +88,9 @@ namespace YooAsset
}
/// <summary>
/// 创建资源包
/// 创建资源包
/// </summary>
/// <param name="packageName">资源包名称</param>
/// <param name="packageName">名称</param>
public static ResourcePackage CreatePackage(string packageName)
{
CheckException(packageName);
@ -93,9 +104,9 @@ namespace YooAsset
}
/// <summary>
/// 获取资源包
/// 获取资源包
/// </summary>
/// <param name="packageName">资源包名称</param>
/// <param name="packageName">名称</param>
public static ResourcePackage GetPackage(string packageName)
{
CheckException(packageName);
@ -106,9 +117,9 @@ namespace YooAsset
}
/// <summary>
/// 尝试获取资源包
/// 尝试获取资源包
/// </summary>
/// <param name="packageName">资源包名称</param>
/// <param name="packageName">名称</param>
public static ResourcePackage TryGetPackage(string packageName)
{
CheckException(packageName);
@ -116,9 +127,17 @@ namespace YooAsset
}
/// <summary>
/// 移除资源包
/// 获取所有资源包裹
/// </summary>
/// <param name="packageName">资源包名称</param>
public static List<ResourcePackage> GetAllPackages()
{
return _packages.ToList();
}
/// <summary>
/// 移除资源包裹
/// </summary>
/// <param name="packageName">包裹名称</param>
public static bool RemovePackage(string packageName)
{
CheckException(packageName);
@ -130,9 +149,9 @@ namespace YooAsset
}
/// <summary>
/// 移除资源包
/// 移除资源包
/// </summary>
/// <param name="package">资源包实例对象</param>
/// <param name="package">实例对象</param>
public static bool RemovePackage(ResourcePackage package)
{
CheckException(package);
@ -149,9 +168,9 @@ namespace YooAsset
}
/// <summary>
/// 检测资源包是否存在
/// 检测资源包是否存在
/// </summary>
/// <param name="packageName">资源包名称</param>
/// <param name="packageName">名称</param>
public static bool ContainsPackage(string packageName)
{
CheckException(packageName);

View File

@ -5,6 +5,14 @@ namespace YooAsset
{
internal class YooAssetsDriver : MonoBehaviour
{
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
LastestUpdateFrame = 0;
}
#endif
private static int LastestUpdateFrame = 0;
void Update()

View File

@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "2.3.3-preview",
"version": "2.3.4-preview",
"unity": "2019.4",
"description": "unity3d resources management system.",
"author": {