Author Topic: NGUI 3.0 Popup menu - scripting menu items  (Read 4521 times)

nonlinearcreative

  • Guest
NGUI 3.0 Popup menu - scripting menu items
« on: October 16, 2013, 01:32:39 PM »
I'm still very much a newbie to NGUI (I started using it half way through release 2.7) and still relatively green with scripting in C#. But I have found the tutorials helpful and for the most part, I think I've got some very basic aspects of the EventDelegate figured out to do most of what I want it to do. 

However, I cannot find any good deep tutorial on the pop up menu using EventDelegate. (Tutorial 11 is the only one which is not selectable on the tasharen website... it's grayed out)

I am trying to just send a simple custom command to another game object based on a list item selection in the pop up menu and I can't find anything describing the new way of doing that. The only way I am somewhat familiar with, is using OnSelectionChange and passing a string into the receiver based on the line item name. I got it to work just fine in 2.7.

Now in 3.0, in the inspector, when I have my popup menu selected, I can see my menu item names inside the UIPopup List widget. There is a white warning that says "This popup list has no label to update, so it will behave like a menu."
Menu Option 0
Menu Option 1
Menu Option 2
default, position, localized (I leave localized not checked).

Below that is the Appearance widget and below that is an "On Value Change" widget. Inside On Value Change is a window for Notify, which I assume, is meant for the receiver. So I plug my receiver into it (see code below that is on my receiver).  It now gives me a pulldown for "Method" and inside the pulldown I see <Choose>.  Clicking on the <choose> pulldown reveals no possible selections even though my receiver script is in fact on my receiver. I have never been able to see any methods in this pulldown. My receiver is an empty game object with this script on it. 


I kept the script super simple. This is all I want to be able to do from the items in the pulldown menu:




using UnityEngine;
using System.Collections;


public class PulldownMenuReceiver : MonoBehaviour
{


    void OnSelectionChange (string val)
   {
      switch (val)
      {
     
         case "Menu Option 0":   
         Debug.Log ("I hit 0");
         break;
         
         case "Menu Option 1":   
         Debug.Log ("I hit 1");
         break;
         
         case "Menu Option 2":   
         Debug.Log ("I hit 2");
         break;
         
      }
   }
   
}



I get no errors. But I get no debug registering in the log either.

All I want to be able to do is customize the list names to each do a separate thing when they are clicked (touched).
What am I missing here?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0 Popup menu - scripting menu items
« Reply #1 on: October 18, 2013, 06:56:23 PM »
The function must be of "void FuncName (void)" signature.

UIPopupList.current.value tells you the selection instead of a string parameter.

nonlinearcreative

  • Guest
Re: NGUI 3.0 Popup menu - scripting menu items
« Reply #2 on: November 13, 2013, 07:21:06 PM »
Thanks Aren. I came up with a temporary solution for the time being in order to meet a deadline, but I will play around with this and try to get it working. I'll post my solution back to the forum.