mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-25 18:20:15 +00:00
Compare commits
5 Commits
e3a12ef361
...
090e4f4b15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
090e4f4b15 | ||
|
|
53163a75ae | ||
|
|
273401cb20 | ||
|
|
97fe3b0681 | ||
|
|
d401086fd1 |
@@ -2,11 +2,12 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.3.11] - 2025-06-30
|
||||
## [2.3.12] - 2025-07-01
|
||||
|
||||
### Improvements
|
||||
|
||||
- 优化了同步接口导致的资源拷贝和资源验证性能开销高的现象。
|
||||
- 微信小游戏和抖音小游戏支持资源清单加密。
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace YooAsset
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
{
|
||||
// 注意:业务层的解压下载器会依赖内置文件系统的下载方法
|
||||
options.LocalFilePath = GetBuildinFileLoadPath(bundle);
|
||||
options.ImportFilePath = GetBuildinFileLoadPath(bundle);
|
||||
return _unpackFileSystem.DownloadFileAsync(bundle, options);
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
|
||||
@@ -82,15 +82,31 @@ namespace YooAsset
|
||||
return oldDownloader;
|
||||
}
|
||||
|
||||
// 创建新的下载器
|
||||
DefaultDownloadFileOperation newDownloader;
|
||||
if (string.IsNullOrEmpty(options.LocalFilePath))
|
||||
// 获取下载地址
|
||||
if (string.IsNullOrEmpty(options.ImportFilePath))
|
||||
{
|
||||
// 远端下载地址
|
||||
// 注意:如果是解压文件系统类,这里会返回本地内置文件的下载路径
|
||||
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:把本地导入文件路径转换为下载器请求地址
|
||||
options.MainURL = DownloadSystemHelper.ConvertToWWWPath(options.ImportFilePath);
|
||||
options.FallbackURL = options.MainURL;
|
||||
}
|
||||
|
||||
// 创建新的下载器
|
||||
// 创建新的下载器
|
||||
DefaultDownloadFileOperation newDownloader;
|
||||
bool isRequestLocalFile = DownloadSystemHelper.IsRequestLocalFile(options.MainURL);
|
||||
if (isRequestLocalFile)
|
||||
{
|
||||
newDownloader = new DownloadLocalFileOperation(_fileSystem, bundle, options);
|
||||
AddChildOperation(newDownloader);
|
||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize)
|
||||
{
|
||||
newDownloader = new DownloadResumeFileOperation(_fileSystem, bundle, options);
|
||||
@@ -104,18 +120,6 @@ namespace YooAsset
|
||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:把本地文件路径指定为可下载地址
|
||||
options.MainURL = DownloadSystemHelper.ConvertToWWWPath(options.LocalFilePath);
|
||||
options.FallbackURL = options.MainURL;
|
||||
|
||||
// 创建新的下载器
|
||||
newDownloader = new DownloadLocalFileOperation(_fileSystem, bundle, options);
|
||||
AddChildOperation(newDownloader);
|
||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||
}
|
||||
|
||||
return newDownloader;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,9 +159,12 @@ namespace YooAsset
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
//TODO 同步加载失败
|
||||
//TODO 尝试同步加载远端的资源文件失败
|
||||
if (Status == EOperationStatus.Failed)
|
||||
{
|
||||
YooLogger.Error($"Try load bundle {Bundle.BundleName} from remote !");
|
||||
YooLogger.Error($"The load remote bundle url : {_requestURL}");
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
|
||||
@@ -177,9 +177,12 @@ namespace YooAsset
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
//TODO 同步加载失败
|
||||
//TODO 尝试同步加载远端的资源文件失败
|
||||
if (Status == EOperationStatus.Failed)
|
||||
{
|
||||
YooLogger.Error($"Try load bundle {Bundle.BundleName} from remote !");
|
||||
YooLogger.Error($"The load remote bundle url : {_requestURL}");
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 拷贝的本地文件路径
|
||||
/// </summary>
|
||||
public string LocalFilePath { set; get; }
|
||||
public string ImportFilePath { set; get; }
|
||||
|
||||
public DownloadFileOptions(int failedTryAgain, int timeout)
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 尝试卸载指定资源的资源包(包括依赖资源)
|
||||
/// </summary>
|
||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
@@ -68,34 +68,39 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
// 卸载主资源包加载器
|
||||
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
||||
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
||||
if (mainLoader != null)
|
||||
while (loopCount > 0)
|
||||
{
|
||||
mainLoader.TryDestroyProviders();
|
||||
if (mainLoader.CanDestroyLoader())
|
||||
{
|
||||
string bundleName = mainLoader.LoadBundleInfo.Bundle.BundleName;
|
||||
mainLoader.DestroyLoader();
|
||||
LoaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
loopCount--;
|
||||
|
||||
// 卸载依赖资源包加载器
|
||||
string[] dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo);
|
||||
foreach (var dependBundleName in dependBundleNames)
|
||||
{
|
||||
var dependLoader = TryGetBundleFileLoader(dependBundleName);
|
||||
if (dependLoader != null)
|
||||
// 卸载主资源包加载器
|
||||
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
||||
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
||||
if (mainLoader != null)
|
||||
{
|
||||
if (dependLoader.CanDestroyLoader())
|
||||
mainLoader.TryDestroyProviders();
|
||||
if (mainLoader.CanDestroyLoader())
|
||||
{
|
||||
string bundleName = dependLoader.LoadBundleInfo.Bundle.BundleName;
|
||||
dependLoader.DestroyLoader();
|
||||
string bundleName = mainLoader.LoadBundleInfo.Bundle.BundleName;
|
||||
mainLoader.DestroyLoader();
|
||||
LoaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
|
||||
// 卸载依赖资源包加载器
|
||||
string[] dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo);
|
||||
foreach (var dependBundleName in dependBundleNames)
|
||||
{
|
||||
var dependLoader = TryGetBundleFileLoader(dependBundleName);
|
||||
if (dependLoader != null)
|
||||
{
|
||||
if (dependLoader.CanDestroyLoader())
|
||||
{
|
||||
string bundleName = dependLoader.LoadBundleInfo.Bundle.BundleName;
|
||||
dependLoader.DestroyLoader();
|
||||
LoaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
||||
public FSDownloadFileOperation CreateDownloader(int failedTryAgain, int timeout)
|
||||
{
|
||||
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain, timeout);
|
||||
options.LocalFilePath = _importFilePath;
|
||||
options.ImportFilePath = _importFilePath;
|
||||
return _fileSystem.DownloadFileAsync(Bundle, options);
|
||||
}
|
||||
|
||||
|
||||
@@ -361,21 +361,21 @@ namespace YooAsset
|
||||
/// 资源回收
|
||||
/// 说明:尝试卸载指定的资源
|
||||
/// </summary>
|
||||
public void TryUnloadUnusedAsset(string location)
|
||||
public void TryUnloadUnusedAsset(string location, int loopCount = 10)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
||||
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源回收
|
||||
/// 说明:尝试卸载指定的资源
|
||||
/// </summary>
|
||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount = 10)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
||||
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -168,14 +168,14 @@ public class T0_InitYooAssets : IPrebuildSetup, IPostBuildCleanup
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "e082d492b9da65e499cee3495be3645d"; //TestRes3/music目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackDirectory);
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(referenceGroup, collector1);
|
||||
|
||||
var collector2 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector2.CollectPath = "";
|
||||
collector2.CollectorGUID = "8c5a1726d94498e4cbe30f5f510cc796"; //TestRes3/prefab目录
|
||||
collector2.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector2.PackRuleName = nameof(YooAsset.Editor.PackDirectory);
|
||||
collector2.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(referenceGroup, collector2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,22 @@ public class TestBundleEncryption
|
||||
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
// 加载音乐播放预制体
|
||||
// 异步加载音乐播放预制体
|
||||
{
|
||||
var assetHandle = package.LoadAssetAsync<GameObject>("prefab_audio");
|
||||
var assetHandle = package.LoadAssetAsync<GameObject>("prefab_audioA");
|
||||
yield return assetHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
|
||||
|
||||
var go = assetHandle.InstantiateSync(Vector3.zero, Quaternion.identity);
|
||||
Assert.IsNotNull(go);
|
||||
|
||||
var audioSource = go.GetComponent<AudioSource>();
|
||||
Assert.IsNotNull(audioSource.clip);
|
||||
}
|
||||
|
||||
// 同步加载音乐播放预制体
|
||||
{
|
||||
var assetHandle = package.LoadAssetSync<GameObject>("prefab_audioB");
|
||||
yield return assetHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 502e4faa60c5fc441a6a8ae9a61fbf35
|
||||
AudioImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 7
|
||||
defaultSettings:
|
||||
serializedVersion: 2
|
||||
loadType: 2
|
||||
sampleRateSetting: 0
|
||||
sampleRateOverride: 0
|
||||
compressionFormat: 1
|
||||
quality: 0.5
|
||||
conversionMode: 0
|
||||
preloadAudioData: 1
|
||||
platformSettingOverrides:
|
||||
1:
|
||||
serializedVersion: 2
|
||||
loadType: 2
|
||||
sampleRateSetting: 0
|
||||
sampleRateOverride: 0
|
||||
compressionFormat: 1
|
||||
quality: 0.5
|
||||
conversionMode: 0
|
||||
preloadAudioData: 1
|
||||
4:
|
||||
serializedVersion: 2
|
||||
loadType: 2
|
||||
sampleRateSetting: 0
|
||||
sampleRateOverride: 0
|
||||
compressionFormat: 1
|
||||
quality: 0.5
|
||||
conversionMode: 0
|
||||
preloadAudioData: 1
|
||||
7:
|
||||
serializedVersion: 2
|
||||
loadType: 2
|
||||
sampleRateSetting: 0
|
||||
sampleRateOverride: 0
|
||||
compressionFormat: 1
|
||||
quality: 0.5
|
||||
conversionMode: 0
|
||||
preloadAudioData: 1
|
||||
13:
|
||||
serializedVersion: 2
|
||||
loadType: 2
|
||||
sampleRateSetting: 2
|
||||
sampleRateOverride: 44100
|
||||
compressionFormat: 7
|
||||
quality: 0.5
|
||||
conversionMode: 0
|
||||
preloadAudioData: 1
|
||||
forceToMono: 0
|
||||
normalize: 1
|
||||
loadInBackground: 0
|
||||
ambisonic: 0
|
||||
3D: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,7 +12,7 @@ GameObject:
|
||||
- component: {fileID: 8364371343008149393}
|
||||
- component: {fileID: 7423861191467597400}
|
||||
m_Layer: 0
|
||||
m_Name: prefab_audio
|
||||
m_Name: prefab_audioA
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@@ -0,0 +1,139 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &3749121449083481702
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1740794871874781600}
|
||||
- component: {fileID: 8364371343008149393}
|
||||
- component: {fileID: 7423861191467597400}
|
||||
m_Layer: 0
|
||||
m_Name: prefab_audioB
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1740794871874781600
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3749121449083481702}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -1.5441012, y: -1.4355755, z: -5.0895267}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!82 &8364371343008149393
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3749121449083481702}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 8300000, guid: 502e4faa60c5fc441a6a8ae9a61fbf35, type: 3}
|
||||
m_PlayOnAwake: 1
|
||||
m_Volume: 1
|
||||
m_Pitch: 1
|
||||
Loop: 1
|
||||
Mute: 0
|
||||
Spatialize: 0
|
||||
SpatializePostEffects: 0
|
||||
Priority: 128
|
||||
DopplerLevel: 1
|
||||
MinDistance: 1
|
||||
MaxDistance: 500
|
||||
Pan2D: 0
|
||||
rolloffMode: 0
|
||||
BypassEffects: 0
|
||||
BypassListenerEffects: 0
|
||||
BypassReverbZones: 0
|
||||
rolloffCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
panLevelCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
spreadCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
reverbZoneMixCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
--- !u!81 &7423861191467597400
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3749121449083481702}
|
||||
m_Enabled: 1
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea7f727cf3cd1b7499c5431e766891c3
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "2.3.11",
|
||||
"version": "2.3.12",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user