Ejemplo n.º 1
0
 public static IObservable <ChangeEvent <T> > OnValueChange <T>(this INotifyValueChanged <T> source)
 {
     return(Observable.FromEvent <EventCallback <ChangeEvent <T> >, ChangeEvent <T> >(
                h => new EventCallback <ChangeEvent <T> >(h),
                h => source.RegisterValueChangedCallback(h),
                h => source.UnregisterValueChangedCallback(h)));
 }
        protected override void DoSubscribeForValueChange(object target)
        {
            if (this.notifyValueChanged == null || target == null)
            {
                return;
            }

            notifyValueChanged.RegisterValueChangedCallback(OnValueChanged);
        }
Ejemplo n.º 3
0
        // TODO: See if we can use `this INotifyValueChanged<T> ve` without `element` argument
        public static void InitField <T>(this VisualElement ve, INotifyValueChanged <T> element,
                                         EventCallback <ChangeEvent <T> > onValueChange, Func <T> getInitialValue)
        {
            element.RegisterValueChangedCallback(onValueChange);

            ve.RegisterCallback <AttachToPanelEvent>(InitValue);

            void InitValue(AttachToPanelEvent e)
            {
                element.value = getInitialValue();
                ve.UnregisterCallback <AttachToPanelEvent>(InitValue);
            }
        }
Ejemplo n.º 4
0
        private void RegistEvent <T>(INotifyValueChanged <T> notify, FieldInfo fieldInfo)
        {
#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
            notify.RegisterValueChangedCallback((val) =>
            {
                fieldInfo.SetValue(this.target, val.newValue);
                this.onDirty?.Invoke();
            });
#else
            notify.OnValueChanged((val) =>
            {
                fieldInfo.SetValue(this.target, val.newValue);
                this.onDirty?.Invoke();
            });
#endif
        }
Ejemplo n.º 5
0
        static INotifyValueChanged <F> CreateFieldS <F>(string _label, F _value, Type _realFieldType, Action <object> _onValueChanged)
        {
            INotifyValueChanged <F> fieldDrawer = null;

            // 如果没有Drawer创建方法,返回空
            if (!fieldDrawerCreatorMap.TryGetValue(typeof(F), out Func <Type, BindableElement> drawerCreator))
            {
                return(null);
            }

            // 创建Drawer,设置初始值,注册onValueChanged方法
            fieldDrawer = drawerCreator(_realFieldType) as INotifyValueChanged <F>;
            fieldDrawer.SetValueWithoutNotify(_value);
            fieldDrawer.RegisterValueChangedCallback((e) =>
            {
                _onValueChanged(e.newValue);
            });

            BaseField <F> tDrawer = fieldDrawer as BaseField <F>;

            tDrawer.label = _label;
            return(fieldDrawer);
        }