- Home /
Loading textures into an array after build
I am trying to build an application that lets you change add and remove textures (allowing for a variable amount of images) after building the executables for Mac and Windows.
Here is the code, which works fine when adding images to the Resources folder within Unity:
#pragma strict
var texture : Texture2D;
var textures : Object[];
var i : int = 0;
function Start () {
textures = Resources.LoadAll("Textures",Texture2D);
texture = textures[i];
renderer.material.mainTexture = texture;
}
function Update () {
if(Input.GetKeyUp("o")){
if(i == textures.Length - 1)
i = 0;
else
i ++;
texture = textures[i];
renderer.material.mainTexture = texture;
}
if(Input.GetKeyUp("i")){
if(i == 0)
i = textures.Length - 1;
else
i --;
texture = textures[i];
renderer.material.mainTexture = texture;
}
}
I would like to be able to make this work the same way after the executables have been built. For example, I could use the www class and load something from a folder next to (same path as) the executable. But I don't know how to do the equivalent with the www class. Specifically, loadAll() and then make an array from that.
Any hints?
Thanks!
Answer by Berenger · Feb 21, 2012 at 09:56 PM
Maybe it's possible to execute a batch that copy everyhting in the folder you're talking about into the Resources folder ? No idea if that's a good idea, just throwing ideas.
Hmm... interesting idea. Thank you! It's worth mentioning that the idea here is to be able to hand off a unity-built executable with a folder along side of it that the end user (a non unity-user) would be able to throw images into or remove images from (assu$$anonymous$$g they are power of 2 and formatted correctly) without having to do anything else. If your solution would require them somehow running a batch every time, I'd probably try to avoid it. I probably should have clarified my intentions in my original post.
Anyway I'm pretty sure my idea is wrong. I think the Resources folder only matter to tell the build to take everything in it. After the build, I don't think you can use a Resource folder, other than the one compressed in the .unity3d.