Compare commits

..

No commits in common. "19c46a2f60906c0c2f208941db60eaee223b7d3e" and "f24ae6eb2a566a5f7e36df6e84d802b1dc287463" have entirely different histories.

45 changed files with 161 additions and 163 deletions

View File

@ -275,7 +275,8 @@ namespace YooAsset.Editor
buildParameters.PackageName = AssetBundleBuilderSettingData.Setting.BuildPackage; buildParameters.PackageName = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.PackageVersion = _buildVersionField.value; buildParameters.PackageVersion = _buildVersionField.value;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.SharedPackRule = new ZeroRedundancySharedPackRule(); buildParameters.AutoAnalyzeRedundancy = true;
buildParameters.ShareAssetPackRule = new DefaultShareAssetPackRule();
buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption; buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle; buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;

View File

@ -164,7 +164,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 计算共享资源包的完整包名 /// 计算共享资源包的完整包名
/// </summary> /// </summary>
public void CalculateShareBundleName(ISharedPackRule sharedPackRule, bool uniqueBundleName, string packageName, string shadersBundleName) public void CalculateShareBundleName(IShareAssetPackRule packRule, bool uniqueBundleName, string packageName, string shadersBundleName)
{ {
if (CollectorType != ECollectorType.None) if (CollectorType != ECollectorType.None)
return; return;
@ -180,7 +180,7 @@ namespace YooAsset.Editor
{ {
if (_referenceBundleNames.Count > 1) if (_referenceBundleNames.Count > 1)
{ {
PackRuleResult packRuleResult = sharedPackRule.GetPackRuleResult(AssetPath); PackRuleResult packRuleResult = packRule.GetPackRuleResult(AssetPath);
BundleName = packRuleResult.GetShareBundleName(packageName, uniqueBundleName); BundleName = packRuleResult.GetShareBundleName(packageName, uniqueBundleName);
} }
else else
@ -196,9 +196,12 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool IsRedundancyAsset() public bool IsRedundancyAsset()
{ {
if (HasBundleName()) if (CollectorType != ECollectorType.None)
return false; return false;
if (IsRawAsset)
throw new Exception("Should never get here !");
return _referenceBundleNames.Count > 1; return _referenceBundleNames.Count > 1;
} }

View File

@ -49,7 +49,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 参与构建的资源列表 /// 参与构建的资源列表
/// 注意:不包含零依赖资源和冗余资源 /// 注意:不包含零依赖资源
/// </summary> /// </summary>
public readonly List<BuildAssetInfo> AllMainAssets = new List<BuildAssetInfo>(); public readonly List<BuildAssetInfo> AllMainAssets = new List<BuildAssetInfo>();
@ -149,15 +149,7 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取构建的资源路径列表 /// 获取该资源包内的所有资源(包括零依赖资源)
/// </summary>
public string[] GetAllMainAssetPaths()
{
return AllMainAssets.Select(t => t.AssetPath).ToArray();
}
/// <summary>
/// 获取该资源包内的所有资源(包括零依赖资源和冗余资源)
/// </summary> /// </summary>
public List<string> GetAllBuiltinAssetPaths() public List<string> GetAllBuiltinAssetPaths()
{ {
@ -169,7 +161,6 @@ namespace YooAsset.Editor
continue; continue;
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos) foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
{ {
// 注意:依赖资源里只添加零依赖资源和冗余资源
if (dependAssetInfo.HasBundleName() == false) if (dependAssetInfo.HasBundleName() == false)
{ {
if (result.Contains(dependAssetInfo.AssetPath) == false) if (result.Contains(dependAssetInfo.AssetPath) == false)
@ -180,6 +171,22 @@ namespace YooAsset.Editor
return result; return result;
} }
/// <summary>
/// 获取构建的资源路径列表
/// </summary>
public string[] GetAllMainAssetPaths()
{
return AllMainAssets.Select(t => t.AssetPath).ToArray();
}
/// <summary>
/// 获取所有写入补丁清单的资源
/// </summary>
public BuildAssetInfo[] GetAllMainAssetInfos()
{
return AllMainAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
}
/// <summary> /// <summary>
/// 创建AssetBundleBuild类 /// 创建AssetBundleBuild类
/// </summary> /// </summary>
@ -193,14 +200,6 @@ namespace YooAsset.Editor
return build; return build;
} }
/// <summary>
/// 获取所有写入补丁清单的资源
/// </summary>
public BuildAssetInfo[] GetAllManifestAssetInfos()
{
return AllMainAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
}
/// <summary> /// <summary>
/// 创建PackageBundle类 /// 创建PackageBundle类
/// </summary> /// </summary>

View File

@ -77,10 +77,15 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool VerifyBuildingResult = false; public bool VerifyBuildingResult = false;
/// <summary>
/// 自动分析冗余资源
/// </summary>
public bool AutoAnalyzeRedundancy = true;
/// <summary> /// <summary>
/// 共享资源的打包规则 /// 共享资源的打包规则
/// </summary> /// </summary>
public ISharedPackRule SharedPackRule = null; public IShareAssetPackRule ShareAssetPackRule = null;
/// <summary> /// <summary>
/// 资源的加密接口 /// 资源的加密接口

View File

@ -74,9 +74,14 @@ namespace YooAsset.Editor
public bool UniqueBundleName; public bool UniqueBundleName;
/// <summary> /// <summary>
/// 共享资源的打包规则类名 /// 自动分析冗余
/// </summary> /// </summary>
public string SharedPackRuleClassName; public bool AutoAnalyzeRedundancy;
/// <summary>
/// 共享资源的打包类名称
/// </summary>
public string ShareAssetPackRuleClassName;
/// <summary> /// <summary>
/// 加密服务类名称 /// 加密服务类名称

View File

@ -139,7 +139,7 @@ namespace YooAsset.Editor
List<PackageAsset> result = new List<PackageAsset>(1000); List<PackageAsset> result = new List<PackageAsset>(1000);
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
var assetInfos = bundleInfo.GetAllManifestAssetInfos(); var assetInfos = bundleInfo.GetAllMainAssetInfos();
foreach (var assetInfo in assetInfos) foreach (var assetInfo in assetInfos)
{ {
PackageAsset packageAsset = new PackageAsset(); PackageAsset packageAsset = new PackageAsset();

View File

@ -49,8 +49,9 @@ namespace YooAsset.Editor
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower; buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID; buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName; buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
buildReport.Summary.SharedPackRuleClassName = buildParameters.SharedPackRule == null ? buildReport.Summary.AutoAnalyzeRedundancy = buildParameters.AutoAnalyzeRedundancy;
"null" : buildParameters.SharedPackRule.GetType().FullName; buildReport.Summary.ShareAssetPackRuleClassName = buildParameters.ShareAssetPackRule == null ?
"null" : buildParameters.ShareAssetPackRule.GetType().FullName;
buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ? buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ?
"null" : buildParameters.EncryptionServices.GetType().FullName; "null" : buildParameters.EncryptionServices.GetType().FullName;
@ -160,7 +161,7 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取该资源包内的所有资源 /// 获取该资源包内的所有资源(包括零依赖资源)
/// </summary> /// </summary>
private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName) private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName)
{ {

View File

@ -26,9 +26,10 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public BuildMapContext CreateBuildMap(BuildParameters buildParameters) public BuildMapContext CreateBuildMap(BuildParameters buildParameters)
{ {
var buildMode = buildParameters.BuildMode; EBuildMode buildMode = buildParameters.BuildMode;
var packageName = buildParameters.PackageName; string packageName = buildParameters.PackageName;
var sharedPackRule = buildParameters.SharedPackRule; IShareAssetPackRule sharePackRule = buildParameters.ShareAssetPackRule;
bool autoAnalyzeRedundancy = buildParameters.AutoAnalyzeRedundancy;
Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000); Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000);
@ -99,14 +100,18 @@ namespace YooAsset.Editor
context.AssetFileCount = allBuildAssetInfoDic.Count; context.AssetFileCount = allBuildAssetInfoDic.Count;
context.Command = collectResult.Command; context.Command = collectResult.Command;
// 8. 计算共享资源的包名 // 8. 计算共享的资源包名
if (autoAnalyzeRedundancy)
{
var command = collectResult.Command; var command = collectResult.Command;
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values) foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{ {
buildAssetInfo.CalculateShareBundleName(sharedPackRule, command.UniqueBundleName, command.PackageName, command.ShadersBundleName); buildAssetInfo.CalculateShareBundleName(sharePackRule, command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
} }
}
// 9. 记录冗余资源 else
{
// 记录冗余资源
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values) foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{ {
if (buildAssetInfo.IsRedundancyAsset()) if (buildAssetInfo.IsRedundancyAsset())
@ -120,8 +125,9 @@ namespace YooAsset.Editor
context.RedundancyInfos.Add(redundancyInfo); context.RedundancyInfos.Add(redundancyInfo);
} }
} }
}
// 10. 移除不参与构建的资源 // 9. 移除不参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>(); List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values) foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{ {
@ -133,7 +139,7 @@ namespace YooAsset.Editor
allBuildAssetInfoDic.Remove(removeValue.AssetPath); allBuildAssetInfoDic.Remove(removeValue.AssetPath);
} }
// 11. 构建资源列表 // 10. 构建资源包
var allPackAssets = allBuildAssetInfoDic.Values.ToList(); var allPackAssets = allBuildAssetInfoDic.Values.ToList();
if (allPackAssets.Count == 0) if (allPackAssets.Count == 0)
throw new Exception("构建的资源列表不能为空"); throw new Exception("构建的资源列表不能为空");
@ -141,7 +147,6 @@ namespace YooAsset.Editor
{ {
context.PackAsset(assetInfo); context.PackAsset(assetInfo);
} }
return context; return context;
} }
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos) private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)

View File

@ -48,7 +48,7 @@ namespace YooAsset.Editor
} }
// 检测共享资源打包规则 // 检测共享资源打包规则
if (buildParameters.SharedPackRule == null) if (buildParameters.ShareAssetPackRule == null)
throw new Exception("共享资源打包规则不能为空!"); throw new Exception("共享资源打包规则不能为空!");
#if UNITY_WEBGL #if UNITY_WEBGL

View File

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

View File

@ -20,7 +20,7 @@ namespace YooAsset.Editor
} }
} }
[DisplayName("定位地址: 分组名_文件名")] [DisplayName("定位地址: 分组名+文件名")]
public class AddressByGroupAndFileName : IAddressRule public class AddressByGroupAndFileName : IAddressRule
{ {
string IAddressRule.GetAssetAddress(AddressRuleData data) string IAddressRule.GetAssetAddress(AddressRuleData data)
@ -30,7 +30,7 @@ namespace YooAsset.Editor
} }
} }
[DisplayName("定位地址: 文件夹名_文件名")] [DisplayName("定位地址: 文件夹名+文件名")]
public class AddressByFolderAndFileName : IAddressRule public class AddressByFolderAndFileName : IAddressRule
{ {
string IAddressRule.GetAssetAddress(AddressRuleData data) string IAddressRule.GetAssetAddress(AddressRuleData data)

View File

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

View File

@ -1,31 +0,0 @@
using System;
using System.IO;
using UnityEditor;
namespace YooAsset.Editor
{
/// <summary>
/// 零冗余的共享资源打包规则
/// </summary>
public class ZeroRedundancySharedPackRule : ISharedPackRule
{
public PackRuleResult GetPackRuleResult(string assetPath)
{
string bundleName = Path.GetDirectoryName(assetPath);
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return result;
}
}
/// <summary>
/// 全部冗余的共享资源打包规则
/// </summary>
public class FullRedundancySharedPackRule : ISharedPackRule
{
public PackRuleResult GetPackRuleResult(string assetPath)
{
PackRuleResult result = new PackRuleResult(string.Empty, string.Empty);
return result;
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.IO;
using UnityEditor;
namespace YooAsset.Editor
{
public class DefaultShareAssetPackRule : IShareAssetPackRule
{
public PackRuleResult GetPackRuleResult(string assetPath)
{
string bundleName = Path.GetDirectoryName(assetPath);
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return result;
}
}
}

View File

@ -54,10 +54,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string GetShareBundleName(string packageName, bool uniqueBundleName) public string GetShareBundleName(string packageName, bool uniqueBundleName)
{ {
// 注意:冗余的共享资源包名返回空
if (string.IsNullOrEmpty(_bundleName) && string.IsNullOrEmpty(_bundleExtension))
return string.Empty;
string fullName; string fullName;
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower(); string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
if (uniqueBundleName) if (uniqueBundleName)

View File

@ -4,7 +4,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 共享资源的打包规则 /// 共享资源的打包规则
/// </summary> /// </summary>
public interface ISharedPackRule public interface IShareAssetPackRule
{ {
/// <summary> /// <summary>
/// 获取打包规则结果 /// 获取打包规则结果

View File

@ -66,13 +66,13 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("包裹名称", buildReport.Summary.BuildPackageName)); _items.Add(new ItemWrapper("包裹名称", buildReport.Summary.BuildPackageName));
_items.Add(new ItemWrapper("包裹版本", buildReport.Summary.BuildPackageVersion)); _items.Add(new ItemWrapper("包裹版本", buildReport.Summary.BuildPackageVersion));
_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}")); _items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));
_items.Add(new ItemWrapper("资源定位地址大小写不敏感", $"{buildReport.Summary.LocationToLower}")); _items.Add(new ItemWrapper("资源定位地址大小写不敏感", $"{buildReport.Summary.LocationToLower}"));
_items.Add(new ItemWrapper("包含资源GUID数据", $"{buildReport.Summary.IncludeAssetGUID}")); _items.Add(new ItemWrapper("包含资源GUID数据", $"{buildReport.Summary.IncludeAssetGUID}"));
_items.Add(new ItemWrapper("资源包名唯一化", $"{buildReport.Summary.UniqueBundleName}")); _items.Add(new ItemWrapper("资源包名唯一化", $"{buildReport.Summary.UniqueBundleName}"));
_items.Add(new ItemWrapper("共享资源打包规则", buildReport.Summary.SharedPackRuleClassName)); _items.Add(new ItemWrapper("自动分析冗余资源", $"{buildReport.Summary.AutoAnalyzeRedundancy}"));
_items.Add(new ItemWrapper("资源加密服务类", buildReport.Summary.EncryptionServicesClassName)); _items.Add(new ItemWrapper("共享资源的打包类名称", buildReport.Summary.ShareAssetPackRuleClassName));
_items.Add(new ItemWrapper("加密服务类名称", buildReport.Summary.EncryptionServicesClassName));
_items.Add(new ItemWrapper(string.Empty, string.Empty)); _items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("构建参数", string.Empty)); _items.Add(new ItemWrapper("构建参数", string.Empty));

View File

@ -169,7 +169,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 加载场景 /// 加载场景
/// </summary> /// </summary>
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, int priority) public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
{ {
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
@ -190,9 +190,9 @@ namespace YooAsset
ProviderBase provider; ProviderBase provider;
{ {
if (_simulationOnEditor) if (_simulationOnEditor)
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, priority); provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, activateOnLoad, priority);
else else
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, priority); provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, activateOnLoad, priority);
provider.InitSpawnDebugInfo(); provider.InitSpawnDebugInfo();
_providerList.Add(provider); _providerList.Add(provider);
_providerDic.Add(providerGUID, provider); _providerDic.Add(providerGUID, provider);

View File

@ -51,7 +51,7 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 激活场景(当同时存在多个场景时用于切换激活场景) /// 激活场景
/// </summary> /// </summary>
public bool ActivateScene() public bool ActivateScene()
{ {

View File

@ -4,17 +4,17 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal class DependAssetBundles internal class DependAssetBundleGroup
{ {
/// <summary> /// <summary>
/// 依赖的资源包加载器列表 /// 依赖的资源包加载器列表
/// </summary> /// </summary>
internal readonly List<BundleLoaderBase> DependList; internal readonly List<BundleLoaderBase> DependBundles;
public DependAssetBundles(List<BundleLoaderBase> dpendList) public DependAssetBundleGroup(List<BundleLoaderBase> dpendBundles)
{ {
DependList = dpendList; DependBundles = dpendBundles;
} }
/// <summary> /// <summary>
@ -22,7 +22,7 @@ namespace YooAsset
/// </summary> /// </summary>
public bool IsDone() public bool IsDone()
{ {
foreach (var loader in DependList) foreach (var loader in DependBundles)
{ {
if (loader.IsDone() == false) if (loader.IsDone() == false)
return false; return false;
@ -35,7 +35,7 @@ namespace YooAsset
/// </summary> /// </summary>
public bool IsSucceed() public bool IsSucceed()
{ {
foreach (var loader in DependList) foreach (var loader in DependBundles)
{ {
if (loader.Status != BundleLoaderBase.EStatus.Succeed) if (loader.Status != BundleLoaderBase.EStatus.Succeed)
{ {
@ -50,7 +50,7 @@ namespace YooAsset
/// </summary> /// </summary>
public string GetLastError() public string GetLastError()
{ {
foreach (var loader in DependList) foreach (var loader in DependBundles)
{ {
if (loader.Status != BundleLoaderBase.EStatus.Succeed) if (loader.Status != BundleLoaderBase.EStatus.Succeed)
{ {
@ -65,7 +65,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void WaitForAsyncComplete() public void WaitForAsyncComplete()
{ {
foreach (var loader in DependList) foreach (var loader in DependBundles)
{ {
if (loader.IsDone() == false) if (loader.IsDone() == false)
loader.WaitForAsyncComplete(); loader.WaitForAsyncComplete();
@ -77,7 +77,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void Reference() public void Reference()
{ {
foreach (var loader in DependList) foreach (var loader in DependBundles)
{ {
loader.Reference(); loader.Reference();
} }
@ -88,7 +88,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void Release() public void Release()
{ {
foreach (var loader in DependList) foreach (var loader in DependBundles)
{ {
loader.Release(); loader.Release();
} }
@ -99,7 +99,7 @@ namespace YooAsset
/// </summary> /// </summary>
internal void GetBundleDebugInfos(List<DebugBundleInfo> output) internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{ {
foreach (var loader in DependList) foreach (var loader in DependBundles)
{ {
var bundleInfo = new DebugBundleInfo(); var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName; bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName;

View File

@ -28,19 +28,19 @@ namespace YooAsset
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
DependBundles.WaitForAsyncComplete(); DependBundleGroup.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete(); OwnerBundle.WaitForAsyncComplete();
} }
if (DependBundles.IsDone() == false) if (DependBundleGroup.IsDone() == false)
return; return;
if (OwnerBundle.IsDone() == false) if (OwnerBundle.IsDone() == false)
return; return;
if (DependBundles.IsSucceed() == false) if (DependBundleGroup.IsSucceed() == false)
{ {
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = DependBundles.GetLastError(); LastError = DependBundleGroup.GetLastError();
InvokeCompletion(); InvokeCompletion();
return; return;
} }

View File

@ -28,19 +28,19 @@ namespace YooAsset
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
DependBundles.WaitForAsyncComplete(); DependBundleGroup.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete(); OwnerBundle.WaitForAsyncComplete();
} }
if (DependBundles.IsDone() == false) if (DependBundleGroup.IsDone() == false)
return; return;
if (OwnerBundle.IsDone() == false) if (OwnerBundle.IsDone() == false)
return; return;
if (DependBundles.IsSucceed() == false) if (DependBundleGroup.IsSucceed() == false)
{ {
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = DependBundles.GetLastError(); LastError = DependBundleGroup.GetLastError();
InvokeCompletion(); InvokeCompletion();
return; return;
} }

View File

@ -10,13 +10,15 @@ namespace YooAsset
{ {
public readonly LoadSceneMode SceneMode; public readonly LoadSceneMode SceneMode;
private readonly string _sceneName; private readonly string _sceneName;
private readonly bool _activateOnLoad;
private readonly int _priority; private readonly int _priority;
private AsyncOperation _asyncOp; private AsyncOperation _asyncOp;
public BundledSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, int priority) : base(impl, providerGUID, assetInfo) public BundledSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo)
{ {
SceneMode = sceneMode; SceneMode = sceneMode;
_sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath); _sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_activateOnLoad = activateOnLoad;
_priority = priority; _priority = priority;
} }
public override void Update() public override void Update()
@ -34,15 +36,15 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (Status == EStatus.CheckBundle) if (Status == EStatus.CheckBundle)
{ {
if (DependBundles.IsDone() == false) if (DependBundleGroup.IsDone() == false)
return; return;
if (OwnerBundle.IsDone() == false) if (OwnerBundle.IsDone() == false)
return; return;
if (DependBundles.IsSucceed() == false) if (DependBundleGroup.IsSucceed() == false)
{ {
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = DependBundles.GetLastError(); LastError = DependBundleGroup.GetLastError();
InvokeCompletion(); InvokeCompletion();
return; return;
} }
@ -85,6 +87,9 @@ namespace YooAsset
Progress = _asyncOp.progress; Progress = _asyncOp.progress;
if (_asyncOp.isDone) if (_asyncOp.isDone)
{ {
if (SceneObject.IsValid() && _activateOnLoad)
SceneManager.SetActiveScene(SceneObject);
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed; Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
if (Status == EStatus.Failed) if (Status == EStatus.Failed)
{ {

View File

@ -28,19 +28,19 @@ namespace YooAsset
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
DependBundles.WaitForAsyncComplete(); DependBundleGroup.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete(); OwnerBundle.WaitForAsyncComplete();
} }
if (DependBundles.IsDone() == false) if (DependBundleGroup.IsDone() == false)
return; return;
if (OwnerBundle.IsDone() == false) if (OwnerBundle.IsDone() == false)
return; return;
if (DependBundles.IsSucceed() == false) if (DependBundleGroup.IsSucceed() == false)
{ {
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = DependBundles.GetLastError(); LastError = DependBundleGroup.GetLastError();
InvokeCompletion(); InvokeCompletion();
return; return;
} }

View File

@ -6,12 +6,14 @@ namespace YooAsset
internal sealed class DatabaseSceneProvider : ProviderBase internal sealed class DatabaseSceneProvider : ProviderBase
{ {
public readonly LoadSceneMode SceneMode; public readonly LoadSceneMode SceneMode;
private readonly bool _activateOnLoad;
private readonly int _priority; private readonly int _priority;
private AsyncOperation _asyncOp; private AsyncOperation _asyncOp;
public DatabaseSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, int priority) : base(impl, providerGUID, assetInfo) public DatabaseSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo)
{ {
SceneMode = sceneMode; SceneMode = sceneMode;
_activateOnLoad = activateOnLoad;
_priority = priority; _priority = priority;
} }
public override void Update() public override void Update()
@ -75,6 +77,9 @@ namespace YooAsset
Progress = _asyncOp.progress; Progress = _asyncOp.progress;
if (_asyncOp.isDone) if (_asyncOp.isDone)
{ {
if (SceneObject.IsValid() && _activateOnLoad)
SceneManager.SetActiveScene(SceneObject);
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed; Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
if (Status == EStatus.Failed) if (Status == EStatus.Failed)
{ {

View File

@ -91,7 +91,7 @@ namespace YooAsset
protected BundleLoaderBase OwnerBundle { private set; get; } protected BundleLoaderBase OwnerBundle { private set; get; }
protected DependAssetBundles DependBundles { private set; get; } protected DependAssetBundleGroup DependBundleGroup { private set; get; }
protected bool IsWaitForAsyncComplete { private set; get; } = false; protected bool IsWaitForAsyncComplete { private set; get; } = false;
private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>(); private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>();
@ -109,9 +109,9 @@ namespace YooAsset
OwnerBundle.Reference(); OwnerBundle.Reference();
OwnerBundle.AddProvider(this); OwnerBundle.AddProvider(this);
var dependList = impl.CreateDependAssetBundleLoaders(assetInfo); var dependBundles = impl.CreateDependAssetBundleLoaders(assetInfo);
DependBundles = new DependAssetBundles(dependList); DependBundleGroup = new DependAssetBundleGroup(dependBundles);
DependBundles.Reference(); DependBundleGroup.Reference();
} }
} }
@ -133,10 +133,10 @@ namespace YooAsset
OwnerBundle.Release(); OwnerBundle.Release();
OwnerBundle = null; OwnerBundle = null;
} }
if (DependBundles != null) if (DependBundleGroup != null)
{ {
DependBundles.Release(); DependBundleGroup.Release();
DependBundles = null; DependBundleGroup = null;
} }
} }
@ -322,7 +322,7 @@ namespace YooAsset
DownloadReport result = new DownloadReport(); DownloadReport result = new DownloadReport();
result.TotalSize = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize; result.TotalSize = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize;
result.DownloadedBytes = OwnerBundle.DownloadedBytes; result.DownloadedBytes = OwnerBundle.DownloadedBytes;
foreach (var dependBundle in DependBundles.DependList) foreach (var dependBundle in DependBundleGroup.DependBundles)
{ {
result.TotalSize += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize; result.TotalSize += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize;
result.DownloadedBytes += dependBundle.DownloadedBytes; result.DownloadedBytes += dependBundle.DownloadedBytes;
@ -342,7 +342,7 @@ namespace YooAsset
bundleInfo.Status = OwnerBundle.Status.ToString(); bundleInfo.Status = OwnerBundle.Status.ToString();
output.Add(bundleInfo); output.Add(bundleInfo);
DependBundles.GetBundleDebugInfos(output); DependBundleGroup.GetBundleDebugInfos(output);
} }
#endregion #endregion
} }

View File

@ -455,12 +455,13 @@ namespace YooAsset
/// </summary> /// </summary>
/// <param name="location">场景的定位地址</param> /// <param name="location">场景的定位地址</param>
/// <param name="sceneMode">场景加载模式</param> /// <param name="sceneMode">场景加载模式</param>
/// <param name="activateOnLoad">加载完毕时是否主动激活</param>
/// <param name="priority">优先级</param> /// <param name="priority">优先级</param>
public SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, int priority = 100) public SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, priority); var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority);
return handle; return handle;
} }
@ -469,11 +470,12 @@ namespace YooAsset
/// </summary> /// </summary>
/// <param name="assetInfo">场景的资源信息</param> /// <param name="assetInfo">场景的资源信息</param>
/// <param name="sceneMode">场景加载模式</param> /// <param name="sceneMode">场景加载模式</param>
/// <param name="activateOnLoad">加载完毕时是否主动激活</param>
/// <param name="priority">优先级</param> /// <param name="priority">优先级</param>
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, int priority = 100) public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, priority); var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority);
return handle; return handle;
} }
#endregion #endregion

View File

@ -128,11 +128,12 @@ namespace YooAsset
/// </summary> /// </summary>
/// <param name="location">场景的定位地址</param> /// <param name="location">场景的定位地址</param>
/// <param name="sceneMode">场景加载模式</param> /// <param name="sceneMode">场景加载模式</param>
/// <param name="activateOnLoad">加载完毕时是否主动激活</param>
/// <param name="priority">优先级</param> /// <param name="priority">优先级</param>
public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, int priority = 100) public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
DebugCheckDefaultPackageValid(); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(location, sceneMode, priority); return _defaultPackage.LoadSceneAsync(location, sceneMode, activateOnLoad, priority);
} }
/// <summary> /// <summary>
@ -140,11 +141,12 @@ namespace YooAsset
/// </summary> /// </summary>
/// <param name="assetInfo">场景的资源信息</param> /// <param name="assetInfo">场景的资源信息</param>
/// <param name="sceneMode">场景加载模式</param> /// <param name="sceneMode">场景加载模式</param>
/// <param name="activateOnLoad">加载完毕时是否主动激活</param>
/// <param name="priority">优先级</param> /// <param name="priority">优先级</param>
public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, int priority = 100) public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
DebugCheckDefaultPackageValid(); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, priority); return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority);
} }
#endregion #endregion