We have the potential to have a lot of GUI elements in our game–(buttons, etc.) Probably 80% of the time these will not be in use–but just believe for a minute we need a lot–and they are important.
Of course it would be nice to fade the windows in and out-- which I have done as follows below…
For all the numerous buttons in a window (which are parented to the main window, I have broadcast a message–
However-- I have noticed that even if all these guiTextures are disabled–there existence in the game causes a significant decrease in performance-- Iff a script is attached to them (for instance an onMouseUp function–and the functions I call in the fade script). There are no “if” calls, or “updates” on these scripts, and once the guiTextures are disabled I (wrongly?) expected the functions which are simply waiting to be called not to affect performance.
Artist turned coder would appreciate some direction, as I’ve clearly gone about this the wrong way… :?
For reference-- I can have about 1000 guiTextures, all with a script attached that only disables them, with almost no performance decrease… Once I add OnMouseUp(), and the two functions listed at the bottom, my framerate dies(even while they are still all disabled).
guiTexture.enabled = false;
var duration = 2.0;
var t = 0.0;
private var recieveinput = 1;
function Start () {
//for (var child : GUITexture in guiTexture) {
///child.color.a = 1;
///}
}
function Update () {
if (Input.GetAxis ("Inventory") == 1 recieveinput == 1){
if (guiTexture.enabled == false){
recieveinput = 0;
t = 0.0;
BroadcastMessage ("inventory");
//inventory();
return;
}
if (guiTexture.enabled == true){
recieveinput = 0;
t = 0.0;
BroadcastMessage ("closer");
//closer();
}
}
//end function
}
function inventory () {
guiTexture.color.a = 0;
guiTexture.enabled = true;
while (t < duration){
t += Time.deltaTime;
guiTexture.color.a = Mathf.Lerp (0, 1, t/duration);
yield;
}
//end of loop-function resumes
guiTexture.color.a = 1.0;
recieveinput = 1;
//end
}
function closer () {
guiTexture.color.a = 1;
while (t < duration){
t += Time.deltaTime;
guiTexture.color.a = Mathf.Lerp (1, 0, t/duration);
yield;
}
//end of loop-function resumes
guiTexture.color.a = 0.0;
recieveinput = 1;
guiTexture.enabled = false;
//end
}