mirror of https://github.com/tuyoogame/YooAsset
parent
d9c4e5336b
commit
43c40e4bbe
|
@ -169,7 +169,7 @@ namespace YooAsset
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载场景
|
/// 加载场景
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool allowSceneActivation ,int priority)
|
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, 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,allowSceneActivation, priority);
|
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad, priority);
|
||||||
else
|
else
|
||||||
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode,allowSceneActivation, priority);
|
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad, priority);
|
||||||
provider.InitSpawnDebugInfo();
|
provider.InitSpawnDebugInfo();
|
||||||
_providerList.Add(provider);
|
_providerList.Add(provider);
|
||||||
_providerDic.Add(providerGUID, provider);
|
_providerDic.Add(providerGUID, provider);
|
||||||
|
|
|
@ -6,10 +6,9 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
private System.Action<SceneOperationHandle> _callback;
|
private System.Action<SceneOperationHandle> _callback;
|
||||||
internal string PackageName { set; get; }
|
internal string PackageName { set; get; }
|
||||||
private ProviderBase _providerBase;
|
|
||||||
internal SceneOperationHandle(ProviderBase provider) : base(provider)
|
internal SceneOperationHandle(ProviderBase provider) : base(provider)
|
||||||
{
|
{
|
||||||
_providerBase = provider;
|
|
||||||
}
|
}
|
||||||
internal override void InvokeCallback()
|
internal override void InvokeCallback()
|
||||||
{
|
{
|
||||||
|
@ -59,23 +58,9 @@ namespace YooAsset
|
||||||
if (IsValidWithWarning == false)
|
if (IsValidWithWarning == false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (SceneObject.IsValid())
|
if (SceneObject.IsValid() && SceneObject.isLoaded)
|
||||||
{
|
{
|
||||||
var isChangeState = false;
|
return SceneManager.SetActiveScene(SceneObject);
|
||||||
#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
|
else
|
||||||
{
|
{
|
||||||
|
@ -84,6 +69,38 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解除场景加载挂起操作
|
||||||
|
/// </summary>
|
||||||
|
public bool UnSuspend()
|
||||||
|
{
|
||||||
|
if (IsValidWithWarning == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (SceneObject.IsValid())
|
||||||
|
{
|
||||||
|
if (Provider is DatabaseSceneProvider)
|
||||||
|
{
|
||||||
|
var temp = Provider as DatabaseSceneProvider;
|
||||||
|
return temp.UnSuspendLoad();
|
||||||
|
}
|
||||||
|
else if (Provider is BundledSceneProvider)
|
||||||
|
{
|
||||||
|
var temp = Provider as BundledSceneProvider;
|
||||||
|
return temp.UnSuspendLoad();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Scene is invalid : {SceneObject.name}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否为主场景
|
/// 是否为主场景
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -10,16 +10,16 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
public readonly LoadSceneMode SceneMode;
|
public readonly LoadSceneMode SceneMode;
|
||||||
private readonly string _sceneName;
|
private readonly string _sceneName;
|
||||||
|
private readonly bool _suspendLoad;
|
||||||
private readonly int _priority;
|
private readonly int _priority;
|
||||||
private readonly bool _allowSceneActivation;
|
private AsyncOperation _asyncOperation;
|
||||||
public AsyncOperation AsyncOp { private set; get; }
|
|
||||||
|
|
||||||
public BundledSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool allowSceneActivation, int priority) : base(impl, providerGUID, assetInfo)
|
public BundledSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, int priority) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
SceneMode = sceneMode;
|
SceneMode = sceneMode;
|
||||||
_sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
_sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||||
|
_suspendLoad = suspendLoad;
|
||||||
_priority = priority;
|
_priority = priority;
|
||||||
_allowSceneActivation = allowSceneActivation;
|
|
||||||
}
|
}
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
|
@ -64,11 +64,11 @@ namespace YooAsset
|
||||||
if (Status == EStatus.Loading)
|
if (Status == EStatus.Loading)
|
||||||
{
|
{
|
||||||
// 注意:如果场景不存在则返回NULL
|
// 注意:如果场景不存在则返回NULL
|
||||||
AsyncOp = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
||||||
if (AsyncOp != null)
|
if (_asyncOperation != null)
|
||||||
{
|
{
|
||||||
AsyncOp.allowSceneActivation = _allowSceneActivation;
|
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||||
AsyncOp.priority = _priority;
|
_asyncOperation.priority = _priority;
|
||||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||||
Status = EStatus.Checking;
|
Status = EStatus.Checking;
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,8 @@ namespace YooAsset
|
||||||
// 3. 检测加载结果
|
// 3. 检测加载结果
|
||||||
if (Status == EStatus.Checking)
|
if (Status == EStatus.Checking)
|
||||||
{
|
{
|
||||||
Progress = AsyncOp.progress;
|
Progress = _asyncOperation.progress;
|
||||||
if (AsyncOp.isDone)
|
if (_asyncOperation.isDone)
|
||||||
{
|
{
|
||||||
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
||||||
if (Status == EStatus.Failed)
|
if (Status == EStatus.Failed)
|
||||||
|
@ -97,5 +97,17 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解除场景加载挂起操作
|
||||||
|
/// </summary>
|
||||||
|
public bool UnSuspendLoad()
|
||||||
|
{
|
||||||
|
if (_asyncOperation == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_asyncOperation.allowSceneActivation = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,15 +6,15 @@ namespace YooAsset
|
||||||
internal sealed class DatabaseSceneProvider : ProviderBase
|
internal sealed class DatabaseSceneProvider : ProviderBase
|
||||||
{
|
{
|
||||||
public readonly LoadSceneMode SceneMode;
|
public readonly LoadSceneMode SceneMode;
|
||||||
|
private readonly bool _suspendLoad;
|
||||||
private readonly int _priority;
|
private readonly int _priority;
|
||||||
private readonly bool _allowSceneActivation;
|
private AsyncOperation _asyncOperation;
|
||||||
public AsyncOperation AsyncOp { private set; get; }
|
|
||||||
|
|
||||||
public DatabaseSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool allowSceneActivation, int priority) : base(impl, providerGUID, assetInfo)
|
public DatabaseSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, int priority) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
SceneMode = sceneMode;
|
SceneMode = sceneMode;
|
||||||
|
_suspendLoad = suspendLoad;
|
||||||
_priority = priority;
|
_priority = priority;
|
||||||
_allowSceneActivation = allowSceneActivation;
|
|
||||||
}
|
}
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
|
@ -54,11 +54,11 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
|
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
|
||||||
loadSceneParameters.loadSceneMode = SceneMode;
|
loadSceneParameters.loadSceneMode = SceneMode;
|
||||||
AsyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||||
if (AsyncOp != null)
|
if (_asyncOperation != null)
|
||||||
{
|
{
|
||||||
AsyncOp.allowSceneActivation = _allowSceneActivation;
|
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||||
AsyncOp.priority = _priority;
|
_asyncOperation.priority = _priority;
|
||||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||||
Status = EStatus.Checking;
|
Status = EStatus.Checking;
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@ namespace YooAsset
|
||||||
// 3. 检测加载结果
|
// 3. 检测加载结果
|
||||||
if (Status == EStatus.Checking)
|
if (Status == EStatus.Checking)
|
||||||
{
|
{
|
||||||
Progress = AsyncOp.progress;
|
Progress = _asyncOperation.progress;
|
||||||
if (AsyncOp.isDone)
|
if (_asyncOperation.isDone)
|
||||||
{
|
{
|
||||||
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
||||||
if (Status == EStatus.Failed)
|
if (Status == EStatus.Failed)
|
||||||
|
@ -88,5 +88,17 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解除场景加载挂起操作
|
||||||
|
/// </summary>
|
||||||
|
public bool UnSuspendLoad()
|
||||||
|
{
|
||||||
|
if (_asyncOperation == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_asyncOperation.allowSceneActivation = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -455,13 +455,13 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">场景的定位地址</param>
|
/// <param name="location">场景的定位地址</param>
|
||||||
/// <param name="sceneMode">场景加载模式</param>
|
/// <param name="sceneMode">场景加载模式</param>
|
||||||
/// <param name="allowSceneActivation">场景加载后自动激活</param>
|
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||||
/// <param name="priority">优先级</param>
|
/// <param name="priority">优先级</param>
|
||||||
public SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool allowSceneActivation = true, int priority = 100)
|
public SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode,allowSceneActivation, priority);
|
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,12 +470,12 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="assetInfo">场景的资源信息</param>
|
/// <param name="assetInfo">场景的资源信息</param>
|
||||||
/// <param name="sceneMode">场景加载模式</param>
|
/// <param name="sceneMode">场景加载模式</param>
|
||||||
/// <param name="allowSceneActivation">场景加载后自动激活</param>
|
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||||
/// <param name="priority">优先级</param>
|
/// <param name="priority">优先级</param>
|
||||||
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool allowSceneActivation = true, int priority = 100)
|
public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode,allowSceneActivation, priority);
|
var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -128,12 +128,12 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">场景的定位地址</param>
|
/// <param name="location">场景的定位地址</param>
|
||||||
/// <param name="sceneMode">场景加载模式</param>
|
/// <param name="sceneMode">场景加载模式</param>
|
||||||
/// <param name="allowSceneActivation">场景加载后自动激活</param>
|
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||||
/// <param name="priority">优先级</param>
|
/// <param name="priority">优先级</param>
|
||||||
public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single,bool allowSceneActivation = true, int priority = 100)
|
public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
|
||||||
{
|
{
|
||||||
DebugCheckDefaultPackageValid();
|
DebugCheckDefaultPackageValid();
|
||||||
return _defaultPackage.LoadSceneAsync(location, sceneMode, allowSceneActivation, priority);
|
return _defaultPackage.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -141,12 +141,12 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="assetInfo">场景的资源信息</param>
|
/// <param name="assetInfo">场景的资源信息</param>
|
||||||
/// <param name="sceneMode">场景加载模式</param>
|
/// <param name="sceneMode">场景加载模式</param>
|
||||||
/// <param name="allowSceneActivation">场景加载后自动激活</param>
|
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||||
/// <param name="priority">优先级</param>
|
/// <param name="priority">优先级</param>
|
||||||
public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool allowSceneActivation = true, int priority = 100)
|
public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
|
||||||
{
|
{
|
||||||
DebugCheckDefaultPackageValid();
|
DebugCheckDefaultPackageValid();
|
||||||
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, allowSceneActivation, priority);
|
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue