protected virtual void BindEvent() { _dstViewModel = ViewModelProvider.Instance.GetViewModelBehaviour(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, _dstViewModel, _method); var p = new object[] { d }; method.Invoke(_srcEventProp.GetValue(_srcView), p); }
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 }; if (_binder != null && _connection != null) { _binder.OnChange -= _connection.DstUpdated; } removeListenerMethod.Invoke(propInfo.GetValue(_dstView), p); }
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); }
// Even though this method is never called, the fact that it exists will // ensure the compiler includes the types referenced in it so that we can // later refer to those via reflection. private void EnsureGenericTypes() { // Used by InputField var strEventBinder = new UnityEventBinder <string>(null, null); // Used by Slider and Scrollbar var floatEventBinder = new UnityEventBinder <float>(null, null); // Used by Toggle var boolEventBinder = new UnityEventBinder <bool>(null, null); // Used by Dropdown var intEventBinder = new UnityEventBinder <int>(null, null); // Used by ScrollRect var vector2EventBinder = new UnityEventBinder <Vector2>(null, null); // Used by ColorTween var colorEventBinder = new UnityEventBinder <Color>(null, null); // Used by EventTrigger var baseEventDataEventBinder = new UnityEventBinder <BaseEventData>(null, null); }
// Even though this method is never called, the fact that it exists will // ensure the compiler includes the types referenced in it so that we can // later refer to those via reflection. private void EnsureGenericTypes() { var strEventBinder = new UnityEventBinder <string>(null, null); var floatEventBinder = new UnityEventBinder <float>(null, null); }