Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: pretender on January 29, 2015, 04:37:58 AM

Title: UIEventListener subscribe/unsubscribe
Post by: pretender on January 29, 2015, 04:37:58 AM
I was wondering if it is needed to unsubscribe onClick event for example that is subscribe to with UIEventListener?

here is what i am doing

  1. UIEventListener.Get(Button).onClick += go =>
  2.                     {
  3.                         Debug.Log(go.name);
  4.                     };
  5.  
  6. ...
  7.  
  8. UIEventListener.Get(Button).onClick -= go =>
  9.                     {
  10.                         Debug.Log(go.name);
  11.                     };
  12.  

Unsubscribe part gives me warning in Visual Studio...what is the proper way of doing this? Thanks!
Title: Re: UIEventListener subscribe/unsubscribe
Post by: ArenMook on January 29, 2015, 01:12:41 PM
You can't do that with => I'm pretty sure, as this creates a new inlined function in that part of the code. They're effectively different functions.

The only way to -= is to have a proper non-anonymous function reference for both += and -=.