Example #1
0
 public static UnityAction <int> AddOnValueChangedAction(this Dropdown self, Func <int, bool> onValueChanged)
 {
     if (onValueChanged != null)
     {
         var oldSelection = self.value;
         UnityAction <int> newListener = (newSection) => {
             if (newSection == oldSelection)
             {
                 return;
             }
             // Ignore event event if it was triggered through code, only fire for actual user input:
             if (!self.ChangeInChildWasTriggeredByUserThroughEventSystem())
             {
                 return;
             }
             if (!onValueChanged(newSection))
             {
                 self.value = oldSelection;
             }
             else
             {
                 oldSelection = newSection;
                 EventBus.instance.Publish(EventConsts.catUi + UiEvents.DROPDOWN_CHANGED, self, newSection);
             }
         };
         self.onValueChanged.AddListener(newListener);
         return(newListener);
     }
     return(null);
 }