Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadWithSubAssets issue #23

Open
chebedzic opened this issue Mar 21, 2022 · 2 comments
Open

LoadWithSubAssets issue #23

chebedzic opened this issue Mar 21, 2022 · 2 comments

Comments

@chebedzic
Copy link

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.

@locus84
Copy link
Owner

locus84 commented Mar 22, 2022

Can you explain what exactly you want to achieve?
So I can test with the case. Or you can share sample project I can reproduce the issue.

@chebedzic
Copy link
Author

we are trying to load multiple assets inside of a subdirectory of a bundle. Like we would use Resources.LoadAll("Images/Specia/3l").
So we are trying to load all of the assets in that folder.

but while doing it we tried to write our own method. using Bundle.GetAllAssetNames(), and parse the names to fit our directory needs.

So while doing all of this we bumped into an issue with quoted method up there.

foundIndex is zero.

If no object with appropriate type is found it remains zero.

returned object from method is the first element of the assets array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants