mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-24 17:50:15 +00:00
AssetOperationHandle类新增便捷方法,便于链式编程
TextAsset asset;
YooAssets.LoadAssetAsync<TextAsset>(name).WaitForAsyncOperationComplete().GetAssetObjet<TextAsset>(out asset).Release();
YooAssets.LoadAssetAsync<TextAsset>(name).Completed += handler => {
handler.GetAssetObjet(out asset).Release();
};
This commit is contained in:
@@ -49,21 +49,41 @@ namespace YooAsset
|
|||||||
return Provider.AssetObject;
|
return Provider.AssetObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源对象
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TAsset"></typeparam>
|
||||||
|
/// <param name="asset"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public AssetOperationHandle GetAssetObjet<TAsset>(out TAsset asset) where TAsset : UnityEngine.Object
|
||||||
|
{
|
||||||
|
asset = AssetObject as TAsset;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 等待异步执行完毕
|
/// 等待异步执行完毕
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void WaitForAsyncComplete()
|
public AssetOperationHandle WaitForAsyncOperationComplete()
|
||||||
{
|
{
|
||||||
if (IsValid == false)
|
if (IsValid == false)
|
||||||
return;
|
return this;
|
||||||
Provider.WaitForAsyncComplete();
|
Provider.WaitForAsyncComplete();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 等待异步执行完毕
|
||||||
|
/// </summary>
|
||||||
|
public void WaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
if(IsValid == false)
|
||||||
|
return;
|
||||||
|
Provider.WaitForAsyncComplete();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 释放资源句柄
|
/// 释放资源句柄
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Release()
|
public void Release()
|
||||||
{
|
{
|
||||||
this.ReleaseInternal();
|
this.ReleaseInternal();
|
||||||
}
|
}
|
||||||
@@ -109,8 +129,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
return InstantiateAsyncInternal(position, rotation, parent, true);
|
return InstantiateAsyncInternal(position, rotation, parent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||||
{
|
{
|
||||||
if (IsValid == false)
|
if (IsValid == false)
|
||||||
@@ -142,4 +160,4 @@ namespace YooAsset
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user