Update asset system

新增获取所有子资源对象的方法。
pull/13/head
hevinci 2022-05-13 14:57:49 +08:00
parent 8260653eae
commit 029b850d6b
1 changed files with 25 additions and 23 deletions

View File

@ -1,4 +1,5 @@
 using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
public sealed class SubAssetsOperationHandle : OperationHandleBase public sealed class SubAssetsOperationHandle : OperationHandleBase
@ -77,34 +78,35 @@ namespace YooAsset
if (IsValid == false) if (IsValid == false)
return null; return null;
foreach (var asset in Provider.AllAssetObjects) foreach (var assetObject in Provider.AllAssetObjects)
{ {
if (asset.name == assetName) if (assetObject.name == assetName)
return asset as TObject; return assetObject as TObject;
} }
YooLogger.Warning($"Not found sub asset object : {assetName}"); YooLogger.Warning($"Not found sub asset object : {assetName}");
return null; return null;
} }
/// <summary> /// <summary>
/// 获取图集下所有的精灵对象集合 /// 获取所有的子资源对象集合
/// </summary> /// </summary>
/// <typeparam name="TObject">子资源对象类型</typeparam> /// <typeparam name="TObject">子资源对象类型</typeparam>
public TObject[] GetSubAssetObjects<TObject>() where TObject : UnityEngine.Object public TObject[] GetSubAssetObjects<TObject>() where TObject : UnityEngine.Object
{ {
List<TObject> ret = new List<TObject>(); if (IsValid == false)
if (IsValid == false) return null;
{
return null;
}
foreach (var e in _provider.AllAssetObjects) List<TObject> ret = new List<TObject>(Provider.AllAssetObjects.Length);
{ foreach (var assetObject in Provider.AllAssetObjects)
ret.Add(e as TObject); {
} var retObject = assetObject as TObject;
return ret.ToArray(); if (retObject != null)
} ret.Add(retObject);
else
YooLogger.Warning($"The type conversion failed : {assetObject.name}");
}
return ret.ToArray();
}
} }
} }