Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Martin Schultz on April 26, 2012, 10:46:52 AM

Title: Simple Menu A/B Switching
Post by: Martin Schultz on April 26, 2012, 10:46:52 AM
I'm starting to use NGUI now for the first project and try to learn how it works. I'm trying to achieve a simple switching between menus / panels as first exercise. What is the correct way to achieve this? I'm having at the moment 2 panels with a button each and at each button I attached a UIButtonTween script twice per button to activate the new menu and deactivate the current menu.

But this can't be the right way as in that manner it is not guaranteed which of the scripts get executed first and that is what I see right now. Switching from A to B works, but not back.

Any help greatly appreciated. :-)

Thanks
Martin
Title: Re: Simple Menu A/B Switching
Post by: ArenMook on April 26, 2012, 03:15:43 PM
Write a simple script to do it. Inside OnClick, NGUITools.SetActive(nextPanelObject, true) and NGUITools.SetActive(currentPanelObject, false).
Title: Re: Simple Menu A/B Switching
Post by: Martin Schultz on April 28, 2012, 03:20:20 AM
Ok, thanks!
Title: Re: Simple Menu A/B Switching
Post by: Martin Schultz on April 28, 2012, 03:31:31 AM
So for anyone else needing this, see code below. Just attach it to a button and set the current panel GameObject as currentPanelObject and the destination panel to the nextPanelObject.


  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [AddComponentMenu("NGUI/Interaction/Switch Menu AB")]
  5. public class NGUISwitchMenu : MonoBehaviour {
  6.        
  7.         public GameObject currentPanelObject;
  8.         public GameObject nextPanelObject;
  9.  
  10.         void OnClick() {
  11.                 NGUITools.SetActive(nextPanelObject, true);
  12.                 NGUITools.SetActive(currentPanelObject, false);
  13.         }
  14. }
  15.  
Title: Re: Simple Menu A/B Switching
Post by: legven on October 28, 2012, 05:29:51 AM
Please help with undestanding http://www.tasharen.com/ngui/example8.html.
How are you setting unvisibility of second panel?
How user can edit gray panel?
Title: Re: Simple Menu A/B Switching
Post by: ArenMook on October 28, 2012, 07:09:54 AM
The panel is shown when the animation or tween starts playing. It's a settong on UIButtonPlayAnimation / UIButtonTween.

Not sure what you mean by editing of a gray panel.
Title: Re: Simple Menu A/B Switching
Post by: legven on October 28, 2012, 10:40:01 AM
Main question - how I can edit panel 2, panel 3, panel 100?
Title: Re: Simple Menu A/B Switching
Post by: ArenMook on October 28, 2012, 12:52:59 PM
Enable it and edit it? I'm not sure I understand the issue.
Title: Re: Simple Menu A/B Switching
Post by: robindelange on October 24, 2013, 03:00:46 PM
I've always used this method, but haven't found a good way to overcome the flashes when switching between panels on mobile devices. Is the only way for this to play animations in between? This takes a lot of time right, when you have a lot of switches between panels?