diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
index ebb41dc..2745f6a 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
+using UnityEngine.SceneManagement;
namespace YooAsset
{
@@ -163,21 +164,18 @@ namespace YooAsset
/// 异步加载场景
///
/// 场景名称
- public static AssetOperationHandle LoadSceneAsync(string scenePath, SceneInstanceParam instanceParam)
+ public static SceneOperationHandle LoadSceneAsync(string scenePath, LoadSceneMode mode, bool activateOnLoad)
{
AssetProviderBase provider = TryGetAssetProvider(scenePath);
if (provider == null)
{
if (SimulationOnEditor)
- provider = new DatabaseSceneProvider(scenePath, instanceParam);
+ provider = new DatabaseSceneProvider(scenePath, mode, activateOnLoad);
else
- provider = new BundledSceneProvider(scenePath, instanceParam);
+ provider = new BundledSceneProvider(scenePath, mode, activateOnLoad);
_providers.Add(provider);
}
-
- // 引用计数增加
- provider.Reference();
- return provider.Handle;
+ return provider.CreateHandle() as SceneOperationHandle;
}
///
@@ -196,10 +194,7 @@ namespace YooAsset
provider = new BundledAssetProvider(assetPath, assetType);
_providers.Add(provider);
}
-
- // 引用计数增加
- provider.Reference();
- return provider.Handle;
+ return provider.CreateHandle() as AssetOperationHandle;
}
///
@@ -218,10 +213,7 @@ namespace YooAsset
provider = new BundledSubAssetsProvider(assetPath, assetType);
_providers.Add(provider);
}
-
- // 引用计数增加
- provider.Reference();
- return provider.Handle;
+ return provider.CreateHandle() as AssetOperationHandle;
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Instance.meta b/Assets/YooAsset/Runtime/AssetSystem/Instance.meta
deleted file mode 100644
index 06a9b1d..0000000
--- a/Assets/YooAsset/Runtime/AssetSystem/Instance.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: a9b18d6c47ddf9b4296619d3d50ff826
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetInstance.cs b/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetInstance.cs
deleted file mode 100644
index eac555e..0000000
--- a/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetInstance.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-
-namespace YooAsset
-{
- public interface IAssetInstance
- {
- }
-}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetInstance.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetInstance.cs.meta
deleted file mode 100644
index ecd0841..0000000
--- a/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetInstance.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: e1d0cfc6a2d5b1f4d9b9ac8f93682497
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetParam.cs b/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetParam.cs
deleted file mode 100644
index 367e529..0000000
--- a/Assets/YooAsset/Runtime/AssetSystem/Instance/IAssetParam.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-
-namespace YooAsset
-{
- public interface IAssetParam
- {
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Instance/SceneInstance.cs b/Assets/YooAsset/Runtime/AssetSystem/Instance/SceneInstance.cs
deleted file mode 100644
index 92c08f8..0000000
--- a/Assets/YooAsset/Runtime/AssetSystem/Instance/SceneInstance.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using UnityEngine;
-using UnityEngine.SceneManagement;
-
-namespace YooAsset
-{
- ///
- /// 扩展的场景实例对象
- ///
- public class SceneInstance : IAssetInstance
- {
- private readonly AsyncOperation _asyncOp;
-
- public SceneInstance(AsyncOperation op)
- {
- _asyncOp = op;
- }
-
- ///
- /// UnityEngine场景对象
- ///
- public UnityEngine.SceneManagement.Scene Scene { internal set; get; }
-
- ///
- /// 激活场景
- ///
- public bool Activate()
- {
- if (Scene == null)
- return false;
-
- if (Scene.IsValid() && Scene.isLoaded)
- {
- return SceneManager.SetActiveScene(Scene);
- }
- else
- {
- YooLogger.Warning($"Scene is invalid or not loaded : {Scene.name}");
- return false;
- }
- }
- }
-
- ///
- /// 加载场景实例对象需要提供的参数类
- ///
- public class SceneInstanceParam : IAssetParam
- {
- ///
- /// 加载模式
- ///
- public LoadSceneMode LoadMode { set; get; }
-
- ///
- /// 物理模式
- ///
- //public LocalPhysicsMode PhysicsMode { set; get;}
-
- ///
- /// 加载完毕时是否主动激活
- ///
- public bool ActivateOnLoad { set; get; }
- }
-}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Instance/SceneInstance.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Instance/SceneInstance.cs.meta
deleted file mode 100644
index 9568688..0000000
--- a/Assets/YooAsset/Runtime/AssetSystem/Instance/SceneInstance.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 0ab6e7cef318cff4684ed733679bca0e
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs
index 13e8a64..a0363be 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs
@@ -1,69 +1,19 @@
-using System.Collections;
-using UnityEngine;
+using UnityEngine;
namespace YooAsset
{
- public struct AssetOperationHandle : IEnumerator
+ public class AssetOperationHandle : OperationHandleBase
{
- private IAssetProvider _provider;
+ private System.Action _callback;
- internal AssetOperationHandle(IAssetProvider provider)
+ internal AssetOperationHandle(AssetProviderBase provider) : base(provider)
{
- _provider = provider;
}
-
- ///
- /// 句柄是否有效(AssetFileLoader销毁会导致所有句柄失效)
- ///
- public bool IsValid
+ internal override void InvokeCallback()
{
- get
+ if (IsValid)
{
- return _provider != null && _provider.IsValid;
- }
- }
-
- ///
- /// 当前状态
- ///
- public EOperationStatus Status
- {
- get
- {
- if (IsValid == false)
- return EOperationStatus.None;
- if (_provider.Status == AssetProviderBase.EStatus.Fail)
- return EOperationStatus.Failed;
- else if (_provider.Status == AssetProviderBase.EStatus.Success)
- return EOperationStatus.Succeed;
- else
- return EOperationStatus.None;
- }
- }
-
- ///
- /// 加载进度
- ///
- public float Progress
- {
- get
- {
- if (IsValid == false)
- return 0;
- return _provider.Progress;
- }
- }
-
- ///
- /// 是否加载完毕
- ///
- public bool IsDone
- {
- get
- {
- if (IsValid == false)
- return false;
- return _provider.IsDone;
+ _callback?.Invoke(this);
}
}
@@ -79,13 +29,13 @@ namespace YooAsset
if (_provider.IsDone)
value.Invoke(this);
else
- _provider.Callback += value;
+ _callback += value;
}
remove
{
if (IsValid == false)
throw new System.Exception($"{nameof(AssetOperationHandle)} is invalid");
- _provider.Callback -= value;
+ _callback -= value;
}
}
@@ -102,32 +52,6 @@ namespace YooAsset
}
}
- ///
- /// 资源对象集合
- ///
- public UnityEngine.Object[] AllAssets
- {
- get
- {
- if (IsValid == false)
- return null;
- return _provider.AllAssets;
- }
- }
-
- ///
- /// 扩展的实例对象
- ///
- public IAssetInstance AssetInstance
- {
- get
- {
- if (IsValid == false)
- return null;
- return _provider.AssetInstance;
- }
- }
-
///
/// 初始化的游戏对象(只限于请求的资源对象类型为GameObject)
///
@@ -143,17 +67,6 @@ namespace YooAsset
}
}
- ///
- /// 释放资源句柄
- ///
- public void Release()
- {
- if (IsValid == false)
- return;
- _provider.Release();
- _provider = null;
- }
-
///
/// 等待异步执行完毕
///
@@ -163,28 +76,5 @@ namespace YooAsset
return;
_provider.WaitForAsyncComplete();
}
-
- #region 异步操作相关
- ///
- /// 异步操作任务
- ///
- public System.Threading.Tasks.Task