Author Topic: SGSK - pause menu  (Read 4811 times)

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
SGSK - pause menu
« on: January 22, 2013, 03:04:34 PM »
I would like some guidance on where I should hook-up a pause menu (using NGUI or other).

It looks like I can add the button to the "UI Root/Camera 3D (HUD Stats are in there). It could also be a key press (say "P"). What I'm envisioning is a nice slide-down menu with "Resume, Menu, Options" (which I'll make using NGUI).

In looking over the code (I have the new, awesome NGUI + SGSK  8)), it looks like UIButtonKeys is the receiver of the Notify messages and that seems like a good place to tie in my "p", pause key, however, now I'm messing with the "template" code and I'm not sure I want to start off doing that.

I will also have to add it to the Input settings too, right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SGSK - pause menu
« Reply #1 on: January 22, 2013, 09:00:51 PM »
UIButtonPressKey is the script that can listen for a key of your choice, and when pressed -- send an OnClick message. It's ideal to attach this script to buttons, making them activated with both mouse clicks as well as keyboard keys (for example hotbar keys in World of Warcraft -- 1, 2, 3, 4, etc)
  1. [AddComponentMenu("Game/UI/Button Press Key")]
  2. public class UIButtonPressKey : MonoBehaviour
  3. {
  4.         public KeyCode keyCode = KeyCode.None;
  5.  
  6.         void Update ()
  7.         {
  8.                 if (!UICamera.inputHasFocus)
  9.                 {
  10.                         if (keyCode == KeyCode.None) return;
  11.                        
  12.                         if (Input.GetKeyDown(keyCode))
  13.                         {
  14.                                 SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
  15.                         }
  16.  
  17.                         if (Input.GetKeyUp(keyCode))
  18.                         {
  19.                                 SendMessage("OnPress", false, SendMessageOptions.DontRequireReceiver);
  20.                                 SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
  21.                         }
  22.                 }
  23.         }
  24. }

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: SGSK - pause menu
« Reply #2 on: January 23, 2013, 12:07:18 PM »
Cool - thanks.

I got the menu to display and provide basic functionality. I looked at SGPlayer and might hook up the pause menu so that when you press {Esc} it will switch ControlScheme to uiMode and display the pause menu.

Since I'll use the pause menu on future scenes it seemed to make sense to save it as a prefab and just instantiate it whenever I need it.

Thanks again for an awesome kit