Author Topic: NGUI 3.5.6: Parameters for Delegates How to just pass an int  (Read 17361 times)

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
NGUI 3.5.6: Parameters for Delegates How to just pass an int
« on: April 08, 2014, 09:01:23 PM »
Hi, I need to just pass an int that is set in the inspector for each button. So Button1 passes say 60 to the event button2 61 etc. Seems simple but from your video tutorial I can't figure out how to do such a simple thing. I don't really want to be passing game objects etc, just a simple int parameter. Any ideas?

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: NGUI 3.5.6: Parameters for Delegates How to just pass an int
« Reply #1 on: April 08, 2014, 11:22:44 PM »
I completely agree, this system is very odd and not generic at all, it should allow passing in just an int and not require the entire monobehaviour.  ATM, one has to pass in the monobehaviour and then from there another field popups in the inspector which allows to get access to the public int property of that monobehaviour.  Please change the delegate to allow passing in anything and not only MonoBehaviours.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.5.6: Parameters for Delegates How to just pass an int
« Reply #2 on: April 09, 2014, 03:32:52 AM »
You don't pass monobehaviours, wallabie. You choose a game object so that you can then choose a property that's on one of the scripts attached to that game object. The event delegate parameters bind to properties. They don't bind to explicitly passed values in 3.5.6 -- mainly because there is no way to save an arbitrary value in Unity. It can only serialize specific (and a very limited number of) types -- int, float, vector, string, rect, etc. The problem is that -- and I emphasize -- they must be explicit. Ie: actually defined as the final type -- int, float, etc. I can't say "Unity, save this object that may be an int, float, or something else". Unity doesn't work like that.

I will most likely add a work-around that saves everything as a string later so that this is possible. It won't be pretty or particularly fast, but it will get the job done.

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: NGUI 3.5.6: Parameters for Delegates How to just pass an int
« Reply #3 on: April 09, 2014, 05:38:21 AM »
What about my question? How do I pass an int?

tr4np

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: NGUI 3.5.6: Parameters for Delegates How to just pass an int
« Reply #4 on: April 09, 2014, 10:44:30 AM »
What about my question? How do I pass an int?

What I did was just create a bunch of methods to call the generic method.  For example, I wanted to call this:

public void setIndex(int index) { ... }

So I had to create:

public void setIndex0() { setIndex(0); }
public void setIndex1() { setIndex(1); }
public void setIndex2() { setIndex(2); }

which I can then choose from the list.  It's a little messy, but it works.

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: NGUI 3.5.6: Parameters for Delegates How to just pass an int
« Reply #5 on: April 10, 2014, 05:59:43 PM »
Thanks, this is what I currently do but I just was sure there must be a better way especially when NGUI put in parameters to event delegates.