Author Topic: Event Delegate for UICamera.onHover  (Read 3564 times)

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Event Delegate for UICamera.onHover
« on: September 09, 2014, 12:44:19 PM »
Trying to register for OnHover events from UICamera in script.

The below works for UIEventTrigger but can't get it or variations thereon to work for UICamera.

            UIEventTrigger theButtonUIEventTriggerScript = theBtn.GetComponent<UIEventTrigger>();
            if (theButtonUIEventTriggerScript == null) theButtonUIEventTriggerScript = theBtn.AddComponent<UIEventTrigger>();
            EventDelegate del2 = new EventDelegate();
            del2.target = this;
            del2.methodName = "NGUI3ButtonPressHandler";
            EventDelegate.Parameter theParameter2 = new EventDelegate.Parameter(theButtonUIEventTriggerScript, "ITEM_VALUE");
            del2.parameters.SetValue(theParameter2, 0);
            EventDelegate.Set(theButtonUIEventTriggerScript.onPress, del2);

Checked the vids and they don't seem to cover this. Anyone know how you do it ?

Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event Delegate for UICamera.onHover
« Reply #1 on: September 10, 2014, 01:01:28 AM »
I'm not sure what this has to do with UICamera... UICamera is just the event system -- it is responsible for sending out all the events. Your code seems to be adding a press event trigger to the button and there is no mention of UICamera there.

Note that GetComponent/AddComponent can be combined into one: AddMissingComponent().

If you're actually trying to get the parameters set via code, you should be doing it like this:
  1. EventDelegate del2 = new EventDelegate(NGUI3ButtonPressHandler);
  2. del2.parameters[0].value = "ITEM_VALUE";
  3. EventDelegate.Set(theButtonUIEventTriggerScript.onPress, del2);
« Last Edit: September 10, 2014, 01:08:23 AM by ArenMook »

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Event Delegate for UICamera.onHover
« Reply #2 on: September 10, 2014, 02:47:03 AM »
Thanks, but the post was an example of what had tried and works for onPress from UIEventTrigger. The approach does not work for UICamera.

We do a lot of processing in UICamera.genericEventHandler which is now warning that it is deprecated and delegates are to be used, but we have not managed to get this working or find an example of how to do it.

Any clues ?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event Delegate for UICamera.onHover
« Reply #3 on: September 11, 2014, 01:05:57 AM »
UICamera uses C# delegates, not NGUI delegates.
  1. UICamera.onClick += YourClick;
  2.  
  3. void YourClick (GameObject go) { Debug.Log("Clicked on " + go.name); }