Update runtime code

pull/51/head
hevinci 2022-11-23 12:33:12 +08:00
parent 3fedc5b1b3
commit 015f09d27b
7 changed files with 45 additions and 45 deletions

View File

@ -22,7 +22,7 @@ namespace YooAsset
{ {
add add
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(AssetOperationHandle)} is invalid"); throw new System.Exception($"{nameof(AssetOperationHandle)} is invalid");
if (Provider.IsDone) if (Provider.IsDone)
value.Invoke(this); value.Invoke(this);
@ -31,7 +31,7 @@ namespace YooAsset
} }
remove remove
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(AssetOperationHandle)} is invalid"); throw new System.Exception($"{nameof(AssetOperationHandle)} is invalid");
_callback -= value; _callback -= value;
} }
@ -44,7 +44,7 @@ namespace YooAsset
{ {
get get
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
return Provider.AssetObject; return Provider.AssetObject;
} }
@ -56,7 +56,7 @@ namespace YooAsset
/// <typeparam name="TAsset">资源类型</typeparam> /// <typeparam name="TAsset">资源类型</typeparam>
public TAsset GetAssetObject<TAsset>() where TAsset : UnityEngine.Object public TAsset GetAssetObject<TAsset>() where TAsset : UnityEngine.Object
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
return Provider.AssetObject as TAsset; return Provider.AssetObject as TAsset;
} }
@ -66,7 +66,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void WaitForAsyncComplete() public void WaitForAsyncComplete()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return; return;
Provider.WaitForAsyncComplete(); Provider.WaitForAsyncComplete();
} }
@ -124,7 +124,7 @@ namespace YooAsset
private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent) private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent)
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
if (Provider.AssetObject == null) if (Provider.AssetObject == null)
return null; return null;

View File

@ -30,7 +30,7 @@ namespace YooAsset
{ {
get get
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return EOperationStatus.None; return EOperationStatus.None;
if (Provider.Status == ProviderBase.EStatus.Fail) if (Provider.Status == ProviderBase.EStatus.Fail)
return EOperationStatus.Failed; return EOperationStatus.Failed;
@ -48,7 +48,7 @@ namespace YooAsset
{ {
get get
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return string.Empty; return string.Empty;
return Provider.LastError; return Provider.LastError;
} }
@ -61,7 +61,7 @@ namespace YooAsset
{ {
get get
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return 0; return 0;
return Provider.Progress; return Provider.Progress;
} }
@ -74,7 +74,7 @@ namespace YooAsset
{ {
get get
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return false; return false;
return Provider.IsDone; return Provider.IsDone;
} }
@ -84,6 +84,20 @@ namespace YooAsset
/// 句柄是否有效 /// 句柄是否有效
/// </summary> /// </summary>
public bool IsValid public bool IsValid
{
get
{
if (Provider != null && Provider.IsDestroyed == false)
return true;
else
return false;
}
}
/// <summary>
/// 句柄是否有效
/// </summary>
internal bool IsValidWithWarning
{ {
get get
{ {
@ -102,26 +116,12 @@ namespace YooAsset
} }
} }
/// <summary>
/// 句柄是否有效
/// </summary>
public bool IsValidNoWarning
{
get
{
if (Provider != null && Provider.IsDestroyed == false)
return true;
else
return false;
}
}
/// <summary> /// <summary>
/// 释放句柄 /// 释放句柄
/// </summary> /// </summary>
internal void ReleaseInternal() internal void ReleaseInternal()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return; return;
Provider.ReleaseHandle(this); Provider.ReleaseHandle(this);
Provider = null; Provider = null;

View File

@ -22,7 +22,7 @@ namespace YooAsset
{ {
add add
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid"); throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid");
if (Provider.IsDone) if (Provider.IsDone)
value.Invoke(this); value.Invoke(this);
@ -31,7 +31,7 @@ namespace YooAsset
} }
remove remove
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid"); throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid");
_callback -= value; _callback -= value;
} }
@ -42,7 +42,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void WaitForAsyncComplete() public void WaitForAsyncComplete()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return; return;
Provider.WaitForAsyncComplete(); Provider.WaitForAsyncComplete();
} }
@ -61,7 +61,7 @@ namespace YooAsset
/// </summary> /// </summary>
public byte[] GetRawFileData() public byte[] GetRawFileData()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
string filePath = Provider.RawFilePath; string filePath = Provider.RawFilePath;
if (File.Exists(filePath) == false) if (File.Exists(filePath) == false)
@ -74,7 +74,7 @@ namespace YooAsset
/// </summary> /// </summary>
public string GetRawFileText() public string GetRawFileText()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
string filePath = Provider.RawFilePath; string filePath = Provider.RawFilePath;
if (File.Exists(filePath) == false) if (File.Exists(filePath) == false)
@ -87,7 +87,7 @@ namespace YooAsset
/// </summary> /// </summary>
public string GetRawFilePath() public string GetRawFilePath()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return string.Empty; return string.Empty;
return Provider.RawFilePath; return Provider.RawFilePath;
} }

View File

@ -22,7 +22,7 @@ namespace YooAsset
{ {
add add
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SceneOperationHandle)} is invalid"); throw new System.Exception($"{nameof(SceneOperationHandle)} is invalid");
if (Provider.IsDone) if (Provider.IsDone)
value.Invoke(this); value.Invoke(this);
@ -31,7 +31,7 @@ namespace YooAsset
} }
remove remove
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SceneOperationHandle)} is invalid"); throw new System.Exception($"{nameof(SceneOperationHandle)} is invalid");
_callback -= value; _callback -= value;
} }
@ -44,7 +44,7 @@ namespace YooAsset
{ {
get get
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return new Scene(); return new Scene();
return Provider.SceneObject; return Provider.SceneObject;
} }
@ -55,7 +55,7 @@ namespace YooAsset
/// </summary> /// </summary>
public bool ActivateScene() public bool ActivateScene()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return false; return false;
if (SceneObject.IsValid() && SceneObject.isLoaded) if (SceneObject.IsValid() && SceneObject.isLoaded)
@ -74,7 +74,7 @@ namespace YooAsset
/// </summary> /// </summary>
public bool IsMainScene() public bool IsMainScene()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return false; return false;
if (Provider is DatabaseSceneProvider) if (Provider is DatabaseSceneProvider)
@ -99,7 +99,7 @@ namespace YooAsset
public UnloadSceneOperation UnloadAsync() public UnloadSceneOperation UnloadAsync()
{ {
// 如果句柄无效 // 如果句柄无效
if (IsValid == false) if (IsValidWithWarning == false)
{ {
string error = $"{nameof(SceneOperationHandle)} is invalid."; string error = $"{nameof(SceneOperationHandle)} is invalid.";
var operation = new UnloadSceneOperation(error); var operation = new UnloadSceneOperation(error);

View File

@ -21,7 +21,7 @@ namespace YooAsset
{ {
add add
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SubAssetsOperationHandle)} is invalid"); throw new System.Exception($"{nameof(SubAssetsOperationHandle)} is invalid");
if (Provider.IsDone) if (Provider.IsDone)
value.Invoke(this); value.Invoke(this);
@ -30,7 +30,7 @@ namespace YooAsset
} }
remove remove
{ {
if (IsValid == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SubAssetsOperationHandle)} is invalid"); throw new System.Exception($"{nameof(SubAssetsOperationHandle)} is invalid");
_callback -= value; _callback -= value;
} }
@ -43,7 +43,7 @@ namespace YooAsset
{ {
get get
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
return Provider.AllAssetObjects; return Provider.AllAssetObjects;
} }
@ -54,7 +54,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void WaitForAsyncComplete() public void WaitForAsyncComplete()
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return; return;
Provider.WaitForAsyncComplete(); Provider.WaitForAsyncComplete();
} }
@ -75,7 +75,7 @@ namespace YooAsset
/// <param name="assetName">子资源对象名称</param> /// <param name="assetName">子资源对象名称</param>
public TObject GetSubAssetObject<TObject>(string assetName) where TObject : UnityEngine.Object public TObject GetSubAssetObject<TObject>(string assetName) where TObject : UnityEngine.Object
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
foreach (var assetObject in Provider.AllAssetObjects) foreach (var assetObject in Provider.AllAssetObjects)
@ -94,7 +94,7 @@ namespace YooAsset
/// <typeparam name="TObject">子资源对象类型</typeparam> /// <typeparam name="TObject">子资源对象类型</typeparam>
public TObject[] GetSubAssetObjects<TObject>() where TObject : UnityEngine.Object public TObject[] GetSubAssetObjects<TObject>() where TObject : UnityEngine.Object
{ {
if (IsValid == false) if (IsValidWithWarning == false)
return null; return null;
List<TObject> ret = new List<TObject>(Provider.AllAssetObjects.Length); List<TObject> ret = new List<TObject>(Provider.AllAssetObjects.Length);

View File

@ -41,7 +41,7 @@ namespace YooAsset
if (_steps == ESteps.Clone) if (_steps == ESteps.Clone)
{ {
if (_handle.IsValid == false) if (_handle.IsValidWithWarning == false)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;

View File

@ -223,7 +223,7 @@ namespace YooAsset
List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles); List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles);
foreach (var hande in tempers) foreach (var hande in tempers)
{ {
if (hande.IsValid) if (hande.IsValidWithWarning)
{ {
hande.InvokeCallback(); hande.InvokeCallback();
} }