I have tried using the Resources folder an the Resources.Load method in the hopes that when standalone executeable was build a Resources folder would be along side the executeable to put new textures in to load at runtime. But there is no folder only one executeable and looking at the API that is understandable the way it should work as the resources folder seem to be intended for dynamic loading of assets that are not external to the unity project.
I also found the part about writing a texture plugin which passes the OpenGL texture id to the plugin, which in terms can render what ever it wants to the texture using the id. This actually present an option for what i want, but i was hoping there was a way which did not involve writing plugins as it seem to be a pretty basic feature.
In Unity 1.6 the only built-in way to load external texture files is through WWW class (but the texture has to be on some web server).
In Unity 2.0 the same WWW class will be able to load from local files in standalone players. So your pseudo code example will pretty much look like that.
I get an error from Unity saying: ‘UnityEngine.WWW.GetTextureFromURL(string)’ is obsolete: 'All blocking WWW functions have been deprecated, please use one of the asynchronous functions instead.
What asynchronous functions are this refering to, can’t seem to find them.
I know i can do:
IEnumerator GetTexture(file) {
WWW www = new WWW(file);
yield return www;
if([url]www.error[/url] == null) {
Texture2D image = new Texture2D(width, height);
www.LoadImageIntoTexture(image);
}
// Cannot return image here as this is an IEnumerator
}
I take it this is the asyncronous function? The problem with this is i really would like to have a function simply just read a texture from the disk and return it, sorta like:
Texture2D GetTexture(string file) {
// Read texture from disk
// Create Texture2D object for use in unity.
// Return the newly read texture.
}
But for the above code using WWW. That function cannot return Texture but must be IEnumerator as it has to be a corutine?
If you are working in a standalone or editor and you are loading from disk using file:// prefix then you can leave out the yield part. If you are reading from a url you need to use yield as Unity would otherwise stall while fetching the texture, something you don’t want to do in a web browser.
WWW www = new WWW(file);
Texture2D myDownloadedTexture = [url]www.texture;[/url]