Пример #1
0
        /// <summary>
        ///     Registers an initialization for a connector with the passed initial value.
        /// </summary>
        /// <param name="connector">Connector to initialize.</param>
        /// <param name="initialValue">Initial value of the connector.</param>
        /// <exception cref="InvalidOperationException">Thrown if an initialization was already registered for the connector.</exception>
        public void RegisterInitialization(DataContextNodeConnector connector, object initialValue)
        {
            // Check if there is already an initialization registered for the connector.
            if (this.initializations.Any(initialization => initialization.Connector == connector))
            {
                throw new InvalidOperationException("There is already an initialization registered for the connector");
            }

            this.initializations.Add(new Initialization {
                Connector = connector, InitialValue = initialValue
            });
        }
Пример #2
0
        /// <summary>
        ///     Deinitializes the data binding, e.g. unregistering from events.
        /// </summary>
        public void Deinit()
        {
            if (this.provider != null)
            {
                this.provider.ValueChanged -= this.OnProviderValueChanged;
            }

            if (this.dataContextNodeConnector != null)
            {
                this.dataContextNodeConnector.SetValueListener(null);
                this.dataContextNodeConnector = null;
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
 /// <summary>
 ///     Removes a registered initialization for the specified connector.
 /// </summary>
 /// <param name="connector">Connector to remove scheduled initialization for.</param>
 /// <returns>True if there was an initialization which was removed; otherwise, false.</returns>
 public bool RemoveInitialization(DataContextNodeConnector connector)
 {
     return(this.initializations.RemoveAll(initialization => initialization.Connector == connector) != 0);
 }