Hi there,
We were hoping to find a replacement for resources.loadall method, and bumped into a LoadWithSubAssets method, but there is an issue with it in the code snippet bellow,So it searches for Sprites, but finds Texture2D, So no results are type compatible, and the only reason it works is that the default value(which is not changed) of found index is 0, or the first element is returned.
|
public string GetAssetPath<T>(string bundleName, string assetName) where T : UnityEngine.Object |
|
{ |
|
var assets = GetAssetPaths(bundleName, assetName); |
|
if (assets.Count == 0) return string.Empty; |
|
|
|
var typeExpected = typeof(T); |
|
var foundIndex = 0; |
|
|
|
for (int i = 0; i < assets.Count; i++) |
|
{ |
|
var foundType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assets[i]); |
|
if (foundType == typeExpected || foundType.IsSubclassOf(typeExpected)) |
|
{ |
|
foundIndex = i; |
|
break; |
|
} |
|
} |
|
|
|
return assets[foundIndex]; |
|
} |
Also while we are discussing this method is there a way to do LoadWithSubAssets, that loads multiple prefabs/scriptable objects from a subdirectory, we are currently working with GetAllAssetNames(), method and parsing the string to check for subdirectories.
Hi there,
We were hoping to find a replacement for resources.loadall method, and bumped into a LoadWithSubAssets method, but there is an issue with it in the code snippet bellow,So it searches for Sprites, but finds Texture2D, So no results are type compatible, and the only reason it works is that the default value(which is not changed) of found index is 0, or the first element is returned.
Locus-Bundle-System/Runtime/EditorAssetMap.cs
Lines 63 to 82 in bc8d911
Also while we are discussing this method is there a way to do LoadWithSubAssets, that loads multiple prefabs/scriptable objects from a subdirectory, we are currently working with GetAllAssetNames(), method and parsing the string to check for subdirectories.