public override void RegisterDataBinding()
        {
            base.RegisterDataBinding();
            if (isBound)
            {
                return;
            }
            if (_viewModel == null)
            {
                Debug.LogErrorFormat("Binding Error | Could not Find ViewModel {0} for collection {1}", ViewModelName,
                                     SrcCollectionName);

                return;
            }

            src = SrcCollectionName.ToBindTarget(_viewModel, true);
            if (!(src is null))
            {
                _subscription = src.ReactiveCollectionBind(CollectionAdd, CollectionRemove, CollectionReplace,
                                                           CollectionMove, CollectionReset);

                var items = (IList)src.propertyOwner;
                for (int i = 0; i < items.Count; i++)
                {
                    CollectionAdd(new CollectionAddEvent(i, items[i]));
                }
                isBound = true;
                _collectionBinded.Invoke();
            }
        }
示例#2
0
        public DataBindingConnection(GameObject owner, BindTarget src, BindTarget dst,
                                     IValueConverter[] converters = null) : base(owner, src, dst)
        {
            _converters = converters;

            PropertyChanged = OnSrcUpdated;

            BindingMonitor.RegisterConnection(this);
        }
示例#3
0
        public static BindTarget Create(object propOwner, string propName, string path = null,
                                        UnityEvent dstChangedEvent = null, bool isReactive = false, bool isCommand = false)
        {
            var result = new BindTarget();

            if (isReactive)
            {
                var propertyInfo = propOwner.GetType().GetProperty(propName);

                result.propertyOwner = propertyInfo?.GetValue(propOwner);
                if (result.propertyOwner == null && propertyInfo != null)
                {
                    Debug.LogWarning($"{propOwner.GetType().Name} :: {propName} property is null, can't bind");
                    return(null);
                }

                if (isCommand)
                {
                    result._command      = result.propertyOwner;
                    result.propertyOwner = result.propertyOwner.GetType()
                                           .GetPropertyRecursive("CanExecute")
                                           .GetValue(result.propertyOwner);
                }
            }
            else
            {
                result.propertyOwner = propOwner;
            }

            if (result.propertyOwner == null)
            {
                Debug.LogErrorFormat("Could not find propertyOwner (ViewModel?) for Property {0}", propName);
                return(null);
            }

            result.propertyName = propName;
            result.propertyPath = path;
            result.IsReactive   = isReactive;
            result.IsCommand    = isCommand;


            result.property = result.propertyOwner.GetType().GetProperties()
                              .FirstOrDefault(p => p.Name == (isReactive ? "Value" : result.propertyName));

            if (dstChangedEvent != null)
            {
                dstChangedEvent.AddListener(() => { });
            }

            return(result);
        }
 protected DataBindingConnectionBase(GameObject owner, BindTarget src, BindTarget dst)
 {
     OwnerObject = owner;
     SrcTarget   = src;
     DstTarget   = dst;
 }
 public BindTarget ToBindTarget(object owner, bool isReactive = false, string path = null,
                                UnityEngine.Events.UnityEvent dstChangedEvent = null) =>
 BindTarget.Create(owner, PropertyName, path, dstChangedEvent, isReactive && !IsStatic,
                   PropertyType.Replace(" ", "").ToLower().Equals("canexecute"));