I have a script that load a 2048px texture from a Resources folder follow an index (FrameINT):
#pragma strict
var OBJ : GameObject;
var TextName : String = "";
var FrameINT : int ;
var FrameOLD : int;
var Tempo : float = 0.0;
var velocity : float = 0.05;
function Awake () {
OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString()+ "_" + Manager.Frames.ToString(), Texture));
}
function Start () {
}
function Update () {
FrameOLD = FrameINT;
FrameINT = Manager.Frames;
if ( !Manager.FadeON && FrameOLD != FrameINT){
OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString()+ "_" + FrameINT.ToString(), Texture));
}
if (Manager.FadeON){
AssignTexture();
}
}
function AssignTexture () {
OBJ.renderer.material.SetTexture("_MainTexture2", Resources.Load(TextName + Manager.SceneNumber.ToString() + "_" + FrameINT.ToString(), Texture));
if (Tempo < 1.0){
Tempo = Tempo + velocity;
OBJ.renderer.material.SetFloat("_Blend", Tempo);
}
else if (Tempo >= 1.0){
OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString() + "_" + FrameINT.ToString(), Texture));
Tempo = 0.0;
OBJ.renderer.material.SetFloat("_Blend", Tempo);
Resources.UnloadUnusedAssets();
Manager.FadeON = false;
Manager.TouchON = true;
}
}
This system work great and give me possibility to load a large number of big size texture.
At first, the application works fine, but with each new load gets too slow.
I try to use :
Resources.UnloadUnusedAssets();
to unload unused assets but seem not to work.
There is a right way to unload unused texture and speed up my application?