I need to load a file in my application and since it is big ( around 250MB) I need to perform this loading off the main thread. What is more, because assets on Android are not stored in a regular directory, but a jar file, I need to use WWW or UnityWebRequest class.
I ended up with helper method like that:
public static byte[] ReadAllBytes(string filePath)
{
if (Application.platform == RuntimePlatform.Android)
{
var reader = new WWW(filePath);
while (!reader.isDone) { }
return reader.bytes;
}
else
{
return File.ReadAllBytes(filePath);
}
}
The problem is I cannot use it on background thread - Unity won't allow me to create WWW object there. How can I create a method like this, which will read those bytes on current thread?