Author Topic: Simple Menu A/B Switching  (Read 15794 times)

Martin Schultz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • Decane
Simple Menu A/B Switching
« 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Simple Menu A/B Switching
« Reply #1 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).

Martin Schultz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • Decane
Re: Simple Menu A/B Switching
« Reply #2 on: April 28, 2012, 03:20:20 AM »
Ok, thanks!

Martin Schultz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • Decane
Re: Simple Menu A/B Switching
« Reply #3 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.  

legven

  • Guest
Re: Simple Menu A/B Switching
« Reply #4 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Simple Menu A/B Switching
« Reply #5 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.

legven

  • Guest
Re: Simple Menu A/B Switching
« Reply #6 on: October 28, 2012, 10:40:01 AM »
Main question - how I can edit panel 2, panel 3, panel 100?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Simple Menu A/B Switching
« Reply #7 on: October 28, 2012, 12:52:59 PM »
Enable it and edit it? I'm not sure I understand the issue.

robindelange

  • Guest
Re: Simple Menu A/B Switching
« Reply #8 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?