Author Topic: On adding events  (Read 1281 times)

Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
On adding events
« on: September 11, 2014, 04:58:47 AM »
I need to be sure about one point.
About:
  1. UIEventListener.Get(gameObject).onHover = OnHoverNGUI;
and
  1. UIEventListener.Get(gameObject).onHover += OnHoverNGUI;
(which is just the "+" symbol), please, tell me if I am right:
The second ADD a new method/function to be execute on a click and the first set the ONLY method/function, so it there were a previous one, the previous will be never execute.

Is it correct?
Game developer on Casual Arena.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: On adding events
« Reply #1 on: September 11, 2014, 07:20:08 AM »
Yes.

Think if it as a list. += and -= adds or removes, while = overwrites with a new one. Generally it's frowned upon doing the straight = because it will potentially remove other events that should be there. For C# events you're not allowed to do anything other than += and -= outside the origin class, for instance. Delegates are a little bit looser and leave it in the developer's hands to handle it.