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); } }
public static Delegate GetDelegate(object owner, Type[] args) { var mInfo = UnityEventBinder.GetHandler(args); var delegateType = UnityEventBinder.GetDelegateType(args); return(Delegate.CreateDelegate(delegateType, owner, mInfo)); }
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; }
private void OnDestroy() { var method = UnityEventBinder.GetRemoveListener(_srcEventProp.GetValue(_srcView)); if (d == null || method == null) { return; } var p = new object[] { d }; method.Invoke(_srcEventProp.GetValue(_srcView), p); }
public override void UnregisterDataBinding() { base.UnregisterDataBinding(); var propInfo = _dstView.GetType().GetProperty(_dstChangedEventName); var removeListenerMethod = UnityEventBinder.GetRemoveListener(propInfo.GetValue(_dstView)); var p = new object[] { changeDelegate }; _binder.OnChange -= _connection.DstUpdated; removeListenerMethod.Invoke(propInfo.GetValue(_dstView), p); }
private void UnbindDstchangedHandler() { //Debug.Log($"UnBind DstChangedHandler {_gameObject}"); var owner = DstTarget.propertyOwner; var propInfo = owner.GetType().GetProperty(DstTarget.eventName); var removeListenerMethod = UnityEventBinder.GetRemoveListener(propInfo.GetValue(owner)); var p = new object[] { changeDelegate }; _eventBinder.OnChange -= DstUpdated; removeListenerMethod.Invoke(propInfo.GetValue(owner), p); }
public override void UnregisterDataBinding() { var method = UnityEventBinder.GetRemoveListener(_srcEventProp.GetValue(SrcView)); if (d == null || method == null) { return; } var p = new object[] { d }; method.Invoke(_srcEventProp.GetValue(SrcView), p); _isEventBound = false; }
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); }
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); }