Author Topic: UIButton inspector onClick not support function with basic type param?  (Read 2054 times)

maxtangli

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Suppose I have a Controller class to sort a datalist:

  1. public enum SortType {t1,t2...t20}
  2. public Class Controller {
  3.     public void sort(SortType t);
  4. }
  5.  

then I have 20 buttons to call sort.
It would be convenient by using UIButton inspector to set callback function and param,
but when I select sort method, the appeared arg0 turn to type of Object.

So what would be the best practice to use UIButon for this case?

I know I could attach a script for each button, but it still need extra code:
  1. class SortButton : Monobehavior {
  2.     public SortType type;
  3.     public Controller controller;
  4.     void OnClick() {controller.sort(type)}
  5. }
  6.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You currently can't pass static values into the callback functions -- only dynamically linked properties. Ability to specify static parameters is a planned feature. I suggest going with the second approach for now.

maxtangli

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Thanks for your answer.
Anticipate the coming of that feature :)