Hello,
I am making a game involving lots of GUI : inventory, stats, skills, stash, merchant, loader and so on.
I hade great performance issue because my moving camera. I solved 25% of this issue by moving my panels in a fake anchor in my scene who where static, not moving and hidden. Each time i need a panel, i change its parent and put it into the main camera anchor to show it after doing weird stuff like removing static and reactivating panel :
Code sample to desactivate my fake panel after moving my window :
GameObject.Find("PanelFake").GetComponent<UIPanel>().widgetsAreStatic = true;
GameObject.Find("PanelFake").GetComponent<UIPanel>().enabled = false;
Even with that, the profiler told me 50% of my CPU usage was consumed by UIPanel.LateUpdate and without vsync, i was caped at 70 fps.
By disabling ingame my fake anchor, i found my fps where going back to 250 fps. So i made 2 method to enable and disable everything inside. This is a raw example (i dont care the time it take, the game is paused when a window is shown) :
public void enableFakePanel() {
GameObject.Find("PanelFake").GetComponent<UIPanel>().enabled = true;
GameObject.Find("PanelFake").GetComponent<UIPanel>().widgetsAreStatic = false;
UISprite[] spriteChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UISprite>();
foreach (UISprite child in spriteChilds) {
child.enabled = true;
}
UIButton[] buttonChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UIButton>();
foreach (UIButton child in buttonChilds) {
child.enabled = true;
}
UILabel[] labelChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UILabel>();
foreach (UILabel child in labelChilds) {
child.enabled = true;
}
UISlicedSprite[] slicedSpriteChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UISlicedSprite>();
foreach (UISlicedSprite child in slicedSpriteChilds) {
child.enabled = true;
}
UIImageButton[] UIImageButtonChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UIImageButton>();
foreach (UIImageButton child in UIImageButtonChilds) {
child.enabled = true;
}
}
public void disableFakePanel() {
UISprite[] spriteChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UISprite>();
foreach (UISprite child in spriteChilds) {
child.enabled = false;
}
UIButton[] buttonChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UIButton>();
foreach (UIButton child in buttonChilds) {
child.enabled = false;
}
UILabel[] labelChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UILabel>();
foreach (UILabel child in labelChilds) {
child.enabled = false;
}
UISlicedSprite[] slicedSpriteChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UISlicedSprite>();
foreach (UISlicedSprite child in slicedSpriteChilds) {
child.enabled = false;
}
UIImageButton[] UIImageButtonChilds = GameObject.Find("PanelFake").GetComponentsInChildren<UIImageButton>();
foreach (UIImageButton child in UIImageButtonChilds) {
child.enabled = false;
}
GameObject.Find("PanelFake").GetComponent<UIPanel>().widgetsAreStatic = true;
GameObject.Find("PanelFake").GetComponent<UIPanel>().enabled = false;
}
With that piece of code, i'm back to 200 fps. So i gained nearly 3 times of cpu usage with this trick.
So, after all that stuff, my question is : is there a true and clean way to do this in NGUI ? Something who will totally disable the widget and processing inside a panel ?