/// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="initializer">Initializer that takes care about the initialization of this connector.</param>
        /// <param name="monoBehaviour">Mono behaviour this node is assigned to.</param>
        /// <param name="path">Path in context this node is bound to.</param>
        public DataContextNodeConnector(DataContextNodeConnectorInitializer initializer, MonoBehaviour monoBehaviour,
                                        string path)
        {
            if (initializer == null)
            {
                throw new ArgumentNullException("initializer", "No initializer provided");
            }
            if (monoBehaviour == null)
            {
                throw new ArgumentNullException("monoBehaviour", "No mono behaviour provided");
            }

            this.initializer   = initializer;
            this.monoBehaviour = monoBehaviour;
            this.path          = path;
            this.OnHierarchyChanged();
        }
예제 #2
0
        /// <summary>
        ///     Initializes the data binding, depending on the type of data binding.
        /// </summary>
        /// <param name="dataContextNodeConnectorInitializer">Initializer for data context node connectors.</param>
        /// <param name="monoBehaviour">Mono behaviour this data binding belongs to.</param>
        public void Init(DataContextNodeConnectorInitializer dataContextNodeConnectorInitializer, MonoBehaviour monoBehaviour)
        {
            if (this.IsInitialized)
            {
                Debug.LogWarning("Data Binding is already initialized", monoBehaviour);
                return;
            }

            switch (this.Type)
            {
            case DataBindingType.Context:
            {
                this.dataContextNodeConnector = new DataContextNodeConnector(dataContextNodeConnectorInitializer, monoBehaviour, this.Path);
                var initialValue = this.dataContextNodeConnector.SetValueListener(this.OnTargetValueChanged);
                if (this.dataContextNodeConnector.IsInitialized)
                {
                    this.OnTargetValueChanged(initialValue);
                }
            }
            break;

            case DataBindingType.Provider:
            {
                this.InitProvider(this.Provider);
            }
            break;

            case DataBindingType.Constant:
            {
                this.OnTargetValueChanged(this.Constant);
            }
            break;

            case DataBindingType.Reference:
            {
                this.OnTargetValueChanged(this.Reference == null ? null : this.Reference);
            }
            break;
            }
        }