Пример #1
0
        protected virtual void BindEvent()
        {
            //TODO: Wrap PropertyInfo & MethodInfo in Serializable classes so we don't need reflection here
            try
            {
                if (_srcEventProp == null)
                {
                    _srcEventProp = _srcView.GetType().GetProperty(SrcEventName);
                }

                if (_method == null)
                {
                    _method = this.GetType().GetMethod(nameof(SetProp));
                }

                var method = UnityEventBinder.GetAddListener(_srcEventProp.GetValue(_srcView));

                var arg = method.GetParameters()[0];
                d = Delegate.CreateDelegate(arg.ParameterType, this, _method);

                var p = new object[] { d };

                method.Invoke(_srcEventProp.GetValue(_srcView), p);
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("EventPropertyBinding error in {0}. {1}", gameObject.name, e.Message);
            }
        }
Пример #2
0
        protected virtual void BindEvent()
        {
            var vm = ViewModelProvider.Instance.GetViewModelBehaviour(gameObject, ViewModelName);

            //TODO: Wrap PropertyInfo & MethodInfo in Serializable classes so we don't need reflection here

            if (_srcEventProp == null)
            {
                _srcEventProp = SrcView.GetType().GetProperty(SrcEventName);
            }

            if (_method == null)
            {
                _method = ViewModelProvider.GetViewModelType(ViewModelName).GetMethod(DstMethodName);
            }

            if (_method == null)
            {
                Debug.LogErrorFormat("EventBinding error in {0}. No method found in {1} with name {2}", gameObject.name, ViewModelName, DstMethodName);

                return;
            }

            var method = UnityEventBinder.GetAddListener(_srcEventProp.GetValue(SrcView));

            var arg = method.GetParameters()[0];

            d = Delegate.CreateDelegate(arg.ParameterType, vm, _method);

            var p = new object[] { d };

            method.Invoke(_srcEventProp.GetValue(SrcView), p);

            _isEventBound = true;
        }
Пример #3
0
        public override void RegisterDataBinding()
        {
            base.RegisterDataBinding();

            var propInfo = _dstView.GetType().GetProperty(_dstChangedEventName);

            var type = propInfo.PropertyType.BaseType;
            var args = type.GetGenericArguments();

            var evn = propInfo.GetValue(_dstView);

            var addListenerMethod = UnityEventBinder.GetAddListener(propInfo.GetValue(_dstView));

            changeDelegate = UnityEventBinder.GetDelegate(_binder, args);

            var p = new object[] { changeDelegate };

            _binder.OnChange += _connection.DstUpdated;

            addListenerMethod.Invoke(propInfo.GetValue(_dstView), p);
        }
Пример #4
0
        private void BindDstChangedHandler()
        {
            //Debug.Log($"Bind DstChangedHandler {_gameObject}");

            var owner    = DstTarget.propertyOwner;
            var propInfo = owner.GetType().GetProperty(DstTarget.eventName);

            var type = propInfo.PropertyType.BaseType;
            var args = type.GetGenericArguments();

            var evn = propInfo.GetValue(owner);

            var addListenerMethod = UnityEventBinder.GetAddListener(propInfo.GetValue(owner));

            changeDelegate = UnityEventBinder.GetDelegate(_eventBinder, args);

            var p = new object[] { changeDelegate };

            _eventBinder.OnChange += DstUpdated;

            addListenerMethod.Invoke(propInfo.GetValue(owner), p);
        }