I have to load lots of images using WWW to be used as textures for my scene.
I have tried doing it through awake() and start() but everytime the scene displays, the images appear one by one, maybe it is still downloading the images while the scene has already been displayed. What I want to do is to preload all the images, before starting to display the scene.
How do I go about this? Maybe displaying a loading screen before loading the game scene.
Maybe someone can give a sample javascript to do this. thanks!
UPDATE: Adding codes
I have implemented a loading scene to download all images but it still takes awhile before the textures show up in the scene. The “loading scene” has a script that downloads all images to be used in the games. The “game scene” has many groups of panels that each has a LoadImage script attached to it. LoadImage script access static array in ImageHolder that has been loaded before hand.
Loading Scene:
ImageHolder script attached to main camera:
function Start() {
GetInstance();
LoadImages();
}
private function GetInstance() {
if(!Instance) {
Instance = GameObject.FindObjectOfType(typeof(ImageHolder));
}
}
private function LoadImages() {
var panel_www = new WWW("web-service-url-for-all-images");
yield panel_www; //wait to finish
var parsed = JSONParse.JSONParse(panel_www.text);
var store_array = parsed["result"];
for(i=0; i<store_array.length; i++) {
img_url = store_array*["image"];*
-
if(Instance.img_array[img_url] == null) { //if image has not been downloaded in cache*
-
www = new WWW (img_url); *
-
// Wait for download to complete*
-
yield www; *
-
Instance.img_array[img_url] = www.texture;*
-
}*
-
} *
-
Application.LoadLevel(2);*
- }*
Game scene:
LoadImage attached to group of planes.
function Start() { - yield StartCoroutine(“loadStores”);*
}
function loadStores() {
-
//store images*
-
var parts_img = new Array(17); //16 panels + 1 because index 0 is not used*
-
var panel_www = new WWW(“web-service-url-for-each-panelgroup”);*
yield panel_www; //wait to finish
var parsed = JSONParse.JSONParse(panel_www.text);
-
var store_array = parsed[“result”];*
-
for(i=0; i<store_array.length; i++) {*
var part_number = parseInt(store_array*[“part_number”]);
parts_img[part_number] = store_array[“image”];
_ }*_
* //store image parts*
* var store_panel = transform.Find(‘Panel’);
_ var name;_
for (var child : Transform in store_panel)
_ {
name = parseInt(child.name);*_
* if(parts_img[name] == null) {
_ continue;
}*_
* img_url = parts_img[name];*
* // assign texture*
* child.renderer.material.mainTexture = ImageHolder.Instance.img_array[img_url];
_ }
}*_