system
1
Hello,
I have a blank gameobject that contains 70 some odd prefabs (generated at run-time). I want to be able to loop through the prefabs and add a WWW object which will be setting its texture as soon as the download completes, but I need to track which prefabs have have WWW objects that aren’t isDone, so that I could dispose of the WWW object that is associated with that particular prefab. Here is an example of what I have/need (simplified):
for(var child : Transform in transform){
var txt = new Texture2D(tileSize, tileSize, TextureFormat.DXT1, false);
var www = new WWW("urlgoeshere");
yield www;
www.LoadImageIntoTexture(txt);
child.guiTexture.texture = txt;
child.newpropertynamehere = www; // THIS IS WHAT I NEED
}
So that later I can do:
for(var child : Transform in transform){
if(!child.newpropertynamehere.isDone) child.newpropertynamehere.Dispose();
}
Any help would be greatly appreciated!
Jake
Let every GameObject have a script that loads the textures and keeps the variables for isDone.
var children : WWWLoader[] = GetComponentsInChildren<WWWLoader>();
for (child : WWWLoader in children)
{
child.Load("urlgoeshere");
}
so later you can do:
for (child : WWWLoader in children)
{
if(!child.isDone) child.Dispose();
}
the WWWLoader-class would look something like
var isDone : boolean;
function Load (url : string) {
var txt = new Texture2D(tileSize, tileSize, TextureFormat.DXT1, false);
var www = new WWW(url);
yield www;
www.LoadImageIntoTexture(txt);
guiTexture.texture = txt;
isDone = true;
}