Hey. In Unity Editor, I have been iterating through the StreamingAssets folder with the following code:
if (Application.platform == RuntimePlatform.WindowsEditor)
{
var info = new DirectoryInfo(Application.streamingAssetsPath + "/" + gameObject.name + "/JPEG/");
var fileInfo = info.GetFiles();
int i = 0;
foreach (FileInfo file in fileInfo)
{
if (file.Extension == ".jpg")
{
// do stuff
}
}
}
I tried to do it on Android by using the WWW class and other paths, but to no avail.
Any ideas?
Thanks in advance.
Thanks for your answer - but what do you actually mean with “another folder”? As I’ve understood it, you can’t use Resources for this either. Either way, I’m pretty sure there has to be a way of iterating files, even on Android, but I just can’t find any solution to it… For example, how would you go about accessing that .jar file, and iterating the files after the access?
I’m not looking for anything that complicated - just to get a list of .jpg files so I know how many gameObjects I need to create etc.
On Android, the StreamingAssets path is actually embedded inside the installed .apk, and so you cannot access it directly exactly like you access other folders.
On Android, the files are contained
within a compressed .jar file (which
is essentially the same format as
standard zip-compressed files). This
means that if you do not use Unity’s
WWW class to retrieve the file, you
need to use additional software to see
inside the .jar archive and obtain the
file.
The contents of this folder are known at build time, you can probably build some sort of mechanism or a “manifest” with all files under Streaming assets, instead of querying that folder at runtime.
Another solution is to copy the contents of Streaming assets to another folder that is accessible at runtime. This can work, but is not space-efficient since you are essentially duplicating the files and consuming twice the size that is actually needed.