Question by
LexPanin · May 05, 2016 at 02:36 PM ·
guiperformance
Freeze OnGUI()
Hi experts. I use JS and IMGUI to create a huge list of objects. Each object presents by four labels, one button and one box. I have array of these objects. When array populated or element of array is changed, I calculate new values for labels' strings ONE time. But OnGUI() function works all time. Is there a way to refresh the screen only when my array is changed? Could someone help me? Thanks.
Comment
Answer by TBruce · May 05, 2016 at 04:38 PM
Create a boolean variable something like this
var guiIsDirty : bool = true; // set this to tue initially so first time the GUI is drawn
Now anytime you modify a GUI object set guiIsDirty to true.
Next inside OnGui do this
function OnGUI ()
{
if (guiIsDirty == true)
{
// move the bulk of OnGui code here
}
guiIsDirty = false;
}
Sorry, but it doesn't work. When we draw on OnGUI() nothing we'll see nothing (((
function OnGUI () {
switch (stCurrentScreen) {
case "ScreenDataTimeBeg":
ScreenDataTime("BEG");
break;
case "ScreenDataTimeEnd":
ScreenDataTime("END");
break;
case "ScreenTime":
ScreenTime();
break;
case "ScreenTab":
ScreenTab();
break;
case "ScreenNew":
ScreenNew();
break;
case "ScreenOptions":
ScreenOptions();
break;
case "ScreenHelp":
ScreenHelp();
break;
}
switch (stCurrentAlert) {
case "AlertInfo":
rectAlert = GUI.$$anonymous$$odalWindow (0, rectAlert, AlertInfo, "", gsPanel);
break;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612080221im_/https://answers.unity.com/themes/thub/images/avi.jpg)