Ejemplo n.º 1
0
 /// <summary>
 /// Updates all bindings manually
 /// </summary>
 /// <remarks>
 /// Bindings can automatically update if enabled and there are sufficient property changed event(s),
 /// However in some cases you will want to update the bindings manually, for example if you want to save
 /// the data on the form, it would validate first, then update the bound object(s) with the updated values.
 /// </remarks>
 public void Update(BindingUpdateMode mode = BindingUpdateMode.Source)
 {
     foreach (var binding in this)
     {
         binding.Update(mode);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates all bindings in this widget, and recurses to this container's children
 /// </summary>
 public override void UpdateBindings(BindingUpdateMode mode = BindingUpdateMode.Source)
 {
     base.UpdateBindings(mode);
     foreach (var control in LogicalControls)
     {
         control.UpdateBindings(mode);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates all bindings in this widget
        /// </summary>
        public virtual void UpdateBindings(BindingUpdateMode mode = BindingUpdateMode.Source)
        {
            var bindings = Properties.Get <BindingCollection>(Bindings_Key);

            if (bindings != null)
            {
                bindings.Update(mode);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Updates all bindings in this widget, and recurses to this container's children
 /// </summary>
 public override void UpdateBindings(BindingUpdateMode mode = BindingUpdateMode.Source)
 {
     base.UpdateBindings(mode);
     if (Handler.RecurseToChildren)
     {
         foreach (var control in Controls)
         {
             control.UpdateBindings(mode);
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the binding value (sets the source with the value of the destination)
        /// </summary>
        public override void Update(BindingUpdateMode mode = BindingUpdateMode.Destination)
        {
            base.Update(mode);

            if (mode == BindingUpdateMode.Source)
            {
                SetSource();
            }
            else
            {
                SetDestination();
            }
        }
Ejemplo n.º 6
0
		/// <summary>
		/// Updates all bindings in this widget
		/// </summary>
		public virtual void UpdateBindings(BindingUpdateMode mode = BindingUpdateMode.Source)
		{
			var bindings = Properties.Get<BindingCollection>(Bindings_Key);
			if (bindings != null)
			{
				bindings.Update(mode);
			}
		}
Ejemplo n.º 7
0
 /// <summary>
 /// Updates the bound target object's value
 /// </summary>
 /// <remarks>
 /// Typically the source would be your custom class and the destination would be a UI control, but this is not
 /// always the case.
 /// </remarks>
 /// <param name="mode">Direction of the update</param>
 public virtual void Update(BindingUpdateMode mode = BindingUpdateMode.Destination)
 {
 }
Ejemplo n.º 8
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.ObjectField(SourceP);
        UnityEngine.Component selectedSource = SourceP.objectReferenceValue as UnityEngine.Component;
        if (selectedSource == null)
        {
            return;
        }
        if (GUILayout.Button(selectedSource.ToString()))
        {
            System.Action <object> callback = o => {
                serializedObject.Update();
                InitializePropertyNames(SourceP.objectReferenceValue);
            };
            GenericMenu dropdownMenu = EditorHelper.CreateAvailableComponentsDropdown(SourceP, typeof(UnityEngine.Component), callback);
            dropdownMenu.ShowAsContext();
        }
        bool sourceChanged = EditorGUI.EndChangeCheck();


        BindingUpdateMode oldUpdateMode = (BindingUpdateMode)BindingUpdateModeP.enumValueIndex;
        BindingUpdateMode newUpdateMode = oldUpdateMode;

        if (drawEditUpdateMode)
        {
            newUpdateMode = (BindingUpdateMode)EditorGUILayout.EnumPopup(oldUpdateMode);
        }
        if (oldUpdateMode != newUpdateMode && drawEditUpdateMode)
        {
            BindingUpdateModeP.enumValueIndex = (int)newUpdateMode;
        }

        Object unconvertedSource = SourceP.objectReferenceValue;
        INotifyPropertyChanged convertedSource = unconvertedSource as INotifyPropertyChanged;

        if (convertedSource == null && unconvertedSource != null && newUpdateMode == BindingUpdateMode.PropertyChangedEvent)
        {
            EditorGUILayout.HelpBox("The target you have selected does not implement the INotifyPropertyChanged interface. Without this reacting to changes at the source will not be possible.", MessageType.Error);
        }
        else if (unconvertedSource != null)
        {
            if (sourceChanged || AvailablePropertyNames == null)
            {
                unconvertedSource = SourceP.objectReferenceValue;
                InitializePropertyNames(unconvertedSource);
            }
            SerializedProperty PropertyNameP = this.serializedObject.FindProperty("propertyName");
            EditorGUI.BeginChangeCheck();
            selectedPropertyIndex = EditorGUILayout.Popup("Property", selectedPropertyIndex, AvailablePropertyNames);
            if (EditorGUI.EndChangeCheck() || sourceChanged)
            {
                PropNameP.stringValue = AvailablePropertyNames.ElementAtOrDefault(selectedPropertyIndex);
                if (PropNameP.stringValue == null)
                {
                    selectedPropertyIndex = 0;
                    PropNameP.stringValue = AvailablePropertyNames.ElementAtOrDefault(selectedPropertyIndex);
                }
                System.Reflection.PropertyInfo propertyInfo = unconvertedSource.GetType().GetProperty(PropNameP.stringValue);
                System.Type  rawType = propertyInfo.PropertyType;
                VariableType type    = VariableUtilities.ClassifyType(rawType);

                PropTypeP.enumValueIndex = (int)type;
            }
        }

        GUI.enabled = false;
        EditorGUILayout.PropertyField(this.serializedObject.FindProperty("sourceType"));
        GUI.enabled = true;
        serializedObject.ApplyModifiedProperties();
    }
Ejemplo n.º 9
0
		/// <summary>
		/// Updates all bindings in this widget, and recurses to this container's children
		/// </summary>
		public override void UpdateBindings(BindingUpdateMode mode = BindingUpdateMode.Source)
		{
			base.UpdateBindings(mode);
			if (Handler.RecurseToChildren)
			{
				foreach (var control in Controls)
				{
					control.UpdateBindings(mode);
				}
			}
		}
Ejemplo n.º 10
0
		/// <summary>
		/// Updates the bound target object's value
		/// </summary>
		/// <remarks>
		/// Typically the source would be your custom class and the destination would be a UI control, but this is not
		/// always the case.
		/// </remarks>
		/// <param name="mode">Direction of the update</param>
		public virtual void Update(BindingUpdateMode mode = BindingUpdateMode.Destination)
		{
		}