Example #1
0
 public static UnityAction <string> AddOnValueChangedAction(this InputField self, Func <string, bool> onValueChanged)
 {
     if (onValueChanged != null)
     {
         var oldText = self.text;
         UnityAction <string> newListener = (newText) => {
             if (newText == oldText)
             {
                 return;
             }
             // Ignore event event if it was triggered through code, only fire for actual user input:
             if (!self.ChangeWasTriggeredByUserThroughEventSystem())
             {
                 return;
             }
             if (!onValueChanged(newText))
             {
                 self.text = oldText;
             }
             else
             {
                 oldText = newText;
                 EventBus.instance.Publish(EventConsts.catUi + UiEvents.INPUTFIELD_CHANGED, self, newText);
             }
         };
         self.onValueChanged.AddListener(newListener);
         return(newListener);
     }
     return(null);
 }