So I can’t really think of whats going on so I figure I would post something here.
What happening is we have a menu system that shows comics ahead of the levels playing. Unfortunately ‘uptake’ time is very important so we load our main menu gui elements in the package, and then we stream in our comic pages on load.
On our “Menu” game object, we have a manager script which publicly exposes an array of the below class.
We then link the below script components into those publicly exposed spots.
Whats happening is, on level change, they retain all their data BUT the textures all get wiped out.
using UnityEngine;
using System.Collections;
public class LevelComic : MonoBehaviour
{
public string title;
public Texture2D defaultPage;
public Texture2D[] pages;
public bool[] loaded;
private string baseStreamingPath = "./";
public string[] comicPagesPaths;
void Awake()
{
if (!(Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer))
{
this.baseStreamingPath = "my address base :smile:";
}
}
void Start()
{
// Start caching the images outside of the load order of Unity's webstreaming
StartCoroutine("loadImages");
}
void OnLevelWasLoaded()
{
/** MY ANNOYING HACK FIX TO HELP RIGHT NOW TILL I FIND OUT WHATS GOING ON **/
if ( Application.loadedLevelName == "Main Menu" )
{
// Clear out the already loaded status
for (int x = 1; x < this.loaded.Length; x++)
{
this.loaded[x] = false;
}
// Link defaults to avoid no images being shown
// (basically now i cant stream in one of the assets so it
// gets packaged with unity)
this.loaded[0] = true;
this.pages[0] = this.defaultPage;
// Go get the images AGAIN!! *grumble*
StartCoroutine("loadImages");
}
}
IEnumerator loadImages()
{
// Slot counter
int x = 0;
foreach ( string path in comicPagesPaths )
{
// Check if we already have a texture in the slot
if ( !this.loaded[x] )
{
// Start getting the texture
WWW www = new WWW(baseStreamingPath + path);
// Go get some coffee
yield return www;
// If there is an error just make sure we set the check to false
if ([url]www.error[/url] != null)
{
this.loaded[x] = false;
}
else
{
// Assign texture to slot and record it being saved
this.pages[x] = (Texture2D)[url]www.texture;[/url]
this.loaded[x] = true;
}
}
// Increment our slot
x++;
}
}
}
It’s just an oddity that I cant think of whats causing, possibly some sort of texture clearing when you change levels? but then why does my menu still have its? I dont know … it just boggles me mind! The boolean array is left untouched! I’m going to keep reading about WWW class, maybe all data is not permanent when you read it! who knows …
Just looking for input.
UPDATE:
Tried using www.LoadImageIntoTexture to see if it was just the way i handled the texture, it did the same thing