修复场景加载时设置自动激活 false 无效 #121
parent
90d8842f06
commit
6acf9f6302
|
@ -147,7 +147,7 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 加载场景
|
||||
/// </summary>
|
||||
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, int priority)
|
||||
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool allowSceneActivation ,int priority)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
|
@ -168,9 +168,9 @@ namespace YooAsset
|
|||
ProviderBase provider;
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, priority);
|
||||
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode,allowSceneActivation, priority);
|
||||
else
|
||||
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, priority);
|
||||
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode,allowSceneActivation, priority);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providerList.Add(provider);
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
|
|
|
@ -6,9 +6,10 @@ namespace YooAsset
|
|||
{
|
||||
private System.Action<SceneOperationHandle> _callback;
|
||||
internal string PackageName { set; get; }
|
||||
|
||||
private ProviderBase _providerBase;
|
||||
internal SceneOperationHandle(ProviderBase provider) : base(provider)
|
||||
{
|
||||
_providerBase = provider;
|
||||
}
|
||||
internal override void InvokeCallback()
|
||||
{
|
||||
|
@ -58,9 +59,23 @@ namespace YooAsset
|
|||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (SceneObject.IsValid() && SceneObject.isLoaded)
|
||||
if (SceneObject.IsValid())
|
||||
{
|
||||
return SceneManager.SetActiveScene(SceneObject);
|
||||
var isChangeState = false;
|
||||
#if UNITY_EDITOR
|
||||
if (_providerBase is DatabaseSceneProvider dsp)
|
||||
{
|
||||
dsp.AsyncOp.allowSceneActivation = true;
|
||||
isChangeState = true;
|
||||
}
|
||||
#endif
|
||||
if (_providerBase is BundledSceneProvider bsp)
|
||||
{
|
||||
bsp.AsyncOp.allowSceneActivation = true;
|
||||
isChangeState = true;
|
||||
}
|
||||
|
||||
return isChangeState;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -11,13 +11,15 @@ namespace YooAsset
|
|||
public readonly LoadSceneMode SceneMode;
|
||||
private readonly string _sceneName;
|
||||
private readonly int _priority;
|
||||
private AsyncOperation _asyncOp;
|
||||
private readonly bool _allowSceneActivation;
|
||||
public AsyncOperation AsyncOp { private set; get; }
|
||||
|
||||
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 allowSceneActivation, int priority) : base(impl, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
_sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_priority = priority;
|
||||
_allowSceneActivation = allowSceneActivation;
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
|
@ -62,11 +64,11 @@ namespace YooAsset
|
|||
if (Status == EStatus.Loading)
|
||||
{
|
||||
// 注意:如果场景不存在则返回NULL
|
||||
_asyncOp = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
||||
if (_asyncOp != null)
|
||||
AsyncOp = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
||||
if (AsyncOp != null)
|
||||
{
|
||||
_asyncOp.allowSceneActivation = true;
|
||||
_asyncOp.priority = _priority;
|
||||
AsyncOp.allowSceneActivation = _allowSceneActivation;
|
||||
AsyncOp.priority = _priority;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
Status = EStatus.Checking;
|
||||
}
|
||||
|
@ -82,8 +84,8 @@ namespace YooAsset
|
|||
// 3. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone)
|
||||
Progress = AsyncOp.progress;
|
||||
if (AsyncOp.isDone)
|
||||
{
|
||||
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
||||
if (Status == EStatus.Failed)
|
||||
|
|
|
@ -7,12 +7,14 @@ namespace YooAsset
|
|||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private readonly int _priority;
|
||||
private AsyncOperation _asyncOp;
|
||||
private readonly bool _allowSceneActivation;
|
||||
public AsyncOperation AsyncOp { private set; get; }
|
||||
|
||||
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 allowSceneActivation, int priority) : base(impl, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
_priority = priority;
|
||||
_allowSceneActivation = allowSceneActivation;
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
|
@ -52,11 +54,11 @@ namespace YooAsset
|
|||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
|
||||
loadSceneParameters.loadSceneMode = SceneMode;
|
||||
_asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
if (_asyncOp != null)
|
||||
AsyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
if (AsyncOp != null)
|
||||
{
|
||||
_asyncOp.allowSceneActivation = true;
|
||||
_asyncOp.priority = _priority;
|
||||
AsyncOp.allowSceneActivation = _allowSceneActivation;
|
||||
AsyncOp.priority = _priority;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
Status = EStatus.Checking;
|
||||
}
|
||||
|
@ -72,8 +74,8 @@ namespace YooAsset
|
|||
// 3. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone)
|
||||
Progress = AsyncOp.progress;
|
||||
if (AsyncOp.isDone)
|
||||
{
|
||||
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
||||
if (Status == EStatus.Failed)
|
||||
|
|
|
@ -455,12 +455,13 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="allowSceneActivation">场景加载后自动激活</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 allowSceneActivation = true, int priority = 100)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, priority);
|
||||
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode,allowSceneActivation, priority);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -469,11 +470,12 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="allowSceneActivation">场景加载后自动激活</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 allowSceneActivation = true, int priority = 100)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, priority);
|
||||
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode,allowSceneActivation, priority);
|
||||
return handle;
|
||||
}
|
||||
#endregion
|
||||
|
|
|
@ -128,11 +128,12 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="allowSceneActivation">场景加载后自动激活</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 allowSceneActivation = true, int priority = 100)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneAsync(location, sceneMode, priority);
|
||||
return _defaultPackage.LoadSceneAsync(location, sceneMode, allowSceneActivation, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -140,11 +141,12 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="allowSceneActivation">场景加载后自动激活</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 allowSceneActivation = true, int priority = 100)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, priority);
|
||||
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, allowSceneActivation, priority);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
Loading…
Reference in New Issue