private static void DoBindProperty(IBindable field, SerializedObjectUpdateWrapper obj, SerializedProperty property) { var fieldElement = field as VisualElement; if (property == null || fieldElement == null) { // Object is null or property was not found, we have to make sure we delete any previous binding RemoveBinding(fieldElement); return; } // This covers the case where a field is being manually bound to a property field.bindingPath = property.propertyPath; if (property != null && fieldElement != null) { using (var evt = SerializedPropertyBindEvent.GetPooled(property)) { if (SendBindingEvent(evt, fieldElement)) { return; } } } CreateBindingObjectForProperty(fieldElement, obj, property); }
private static void Bind(VisualElement element, SerializedObjectUpdateWrapper objWrapper, SerializedProperty parentProperty) { IBindable field = element as IBindable; using (var evt = SerializedObjectBindEvent.GetPooled(objWrapper.obj)) { if (SendBindingEvent(evt, element)) { return; } } if (field != null) { if (!string.IsNullOrEmpty(field.bindingPath)) { var foundProperty = BindPropertyWithParent(field, objWrapper, parentProperty); if (foundProperty != null) { parentProperty = foundProperty; } } } for (int i = 0; i < element.shadow.childCount; ++i) { Bind(element.shadow[i], objWrapper, parentProperty); } }
public static void CreateBind(PopupField <string> field, SerializedObjectUpdateWrapper objWrapper, SerializedProperty property) { var newBinding = s_Pool.Get(); newBinding.isReleased = false; newBinding.SetBinding(field, objWrapper, property); }
public static void CreateBind(INotifyValueChanged <TValue> field, SerializedObjectUpdateWrapper objWrapper, SerializedProperty property, Func <SerializedProperty, TValue> propGetValue, Action <SerializedProperty, TValue> propSetValue, Func <TValue, SerializedProperty, Func <SerializedProperty, TValue>, bool> propCompareValues) { var newBinding = s_Pool.Get(); newBinding.isReleased = false; newBinding.SetBinding(field, objWrapper, property, propGetValue, propSetValue, propCompareValues); }
private static SerializedProperty BindPropertyWithParent(IBindable field, SerializedObjectUpdateWrapper objWrapper, SerializedProperty parentProperty) { var property = parentProperty?.FindPropertyRelative(field.bindingPath); if (property == null) { property = objWrapper.obj?.FindProperty(field.bindingPath); } DoBindProperty(field, objWrapper, property); return(property); }
private void SetBinding(PopupField <string> c, SerializedObjectUpdateWrapper objWrapper, SerializedProperty property) { this.field = c; property.unsafeMode = true; this.boundPropertyPath = property.propertyPath; this.boundObject = objWrapper; this.boundProperty = property; this.originalChoices = field.choices; this.originalIndex = field.index; this.field.choices = property.enumLocalizedDisplayNames.ToList(); this.lastFieldValueIndex = c.index; Update(); }
private static void DefaultBind <TValue>(VisualElement element, SerializedObjectUpdateWrapper objWrapper, SerializedProperty prop, Func <SerializedProperty, TValue> propertyReadFunc, Action <SerializedProperty, TValue> propertyWriteFunc, Func <TValue, SerializedProperty, Func <SerializedProperty, TValue>, bool> valueComparerFunc) { var field = element as INotifyValueChanged <TValue>; if (field != null) { SerializedObjectBinding <TValue> .CreateBind(field, objWrapper, prop, propertyReadFunc, propertyWriteFunc, valueComparerFunc); } else { Debug.LogWarning(string.Format("Field type {0} is not compatible with {2} property \"{1}\"", element.GetType().FullName, prop.propertyPath, prop.type)); } }
private void SetBinding(INotifyValueChanged <TValue> c, SerializedObjectUpdateWrapper objWrapper, SerializedProperty property, Func <SerializedProperty, TValue> getValue, Action <SerializedProperty, TValue> setValue, Func <TValue, SerializedProperty, Func <SerializedProperty, TValue>, bool> compareValues) { this.field = c; property.unsafeMode = true; this.boundPropertyPath = property.propertyPath; this.boundObject = objWrapper; this.boundProperty = property; this.propGetValue = getValue; this.propSetValue = setValue; this.propCompareValues = compareValues; this.lastFieldValue = c.value; Update(); }
private static void CreateBindingObjectForProperty(VisualElement element, SerializedObjectUpdateWrapper objWrapper, SerializedProperty prop) { if (element is Foldout) { var foldout = element as Foldout; SerializedObjectBinding <bool> .CreateBind( foldout, objWrapper, prop, p => p.isExpanded, (p, v) => p.isExpanded = v, ValueEquals <bool>); return; } switch (prop.propertyType) { case SerializedPropertyType.Integer: DefaultBind(element, objWrapper, prop, GetIntPropertyValue, SetIntPropertyValue, ValueEquals); break; case SerializedPropertyType.Boolean: DefaultBind(element, objWrapper, prop, GetBoolPropertyValue, SetBoolPropertyValue, ValueEquals); break; case SerializedPropertyType.Float: if (prop.type == "float") { if (element is INotifyValueChanged <double> ) { DefaultBind(element, objWrapper, prop, GetFloatPropertyValueAsDouble, SetFloatPropertyValueFromDouble, ValueEquals); } else { DefaultBind(element, objWrapper, prop, GetFloatPropertyValue, SetFloatPropertyValue, ValueEquals); } } else { if (element is INotifyValueChanged <float> ) { DefaultBind(element, objWrapper, prop, GetDoublePropertyValueAsFloat, SetDoublePropertyValueFromFloat, ValueEquals); } else { DefaultBind(element, objWrapper, prop, GetDoublePropertyValue, SetDoublePropertyValue, ValueEquals); } } break; case SerializedPropertyType.String: DefaultBind(element, objWrapper, prop, GetStringPropertyValue, SetStringPropertyValue, ValueEquals); break; case SerializedPropertyType.Color: DefaultBind(element, objWrapper, prop, GetColorPropertyValue, SetColorPropertyValue, ValueEquals); break; case SerializedPropertyType.ObjectReference: DefaultBind(element, objWrapper, prop, GetObjectRefPropertyValue, SetObjectRefPropertyValue, ValueEquals); break; case SerializedPropertyType.LayerMask: DefaultBind(element, objWrapper, prop, GetLayerMaskPropertyValue, SetLayerMaskPropertyValue, ValueEquals); break; case SerializedPropertyType.Enum: if (element is PopupField <string> ) { EnumBind((PopupField <string>)element, objWrapper, prop); } else { DefaultBind(element, objWrapper, prop, GetEnumPropertyValueAsString, SetEnumPropertyValueFromString, SlowEnumValueEquals); } break; case SerializedPropertyType.Vector2: DefaultBind(element, objWrapper, prop, GetVector2PropertyValue, SetVector2PropertyValue, ValueEquals); break; case SerializedPropertyType.Vector3: DefaultBind(element, objWrapper, prop, GetVector3PropertyValue, SetVector3PropertyValue, ValueEquals); break; case SerializedPropertyType.Vector4: DefaultBind(element, objWrapper, prop, GetVector4PropertyValue, SetVector4PropertyValue, ValueEquals); break; case SerializedPropertyType.Rect: DefaultBind(element, objWrapper, prop, GetRectPropertyValue, SetRectPropertyValue, ValueEquals); break; case SerializedPropertyType.ArraySize: DefaultBind(element, objWrapper, prop, GetIntPropertyValue, SetIntPropertyValue, ValueEquals); break; case SerializedPropertyType.AnimationCurve: DefaultBind(element, objWrapper, prop, GetAnimationCurvePropertyValue, SetAnimationCurvePropertyValue, ValueEquals); break; case SerializedPropertyType.Bounds: DefaultBind(element, objWrapper, prop, GetBoundsPropertyValue, SetBoundsPropertyValue, ValueEquals); break; case SerializedPropertyType.Gradient: DefaultBind(element, objWrapper, prop, GetGradientPropertyValue, SetGradientPropertyValue, ValueEquals); break; case SerializedPropertyType.Quaternion: DefaultBind(element, objWrapper, prop, GetQuaternionPropertyValue, SetQuaternionPropertyValue, ValueEquals); break; case SerializedPropertyType.FixedBufferSize: DefaultBind(element, objWrapper, prop, GetIntPropertyValue, SetIntPropertyValue, ValueEquals); break; case SerializedPropertyType.Vector2Int: DefaultBind(element, objWrapper, prop, GetVector2IntPropertyValue, SetVector2IntPropertyValue, ValueEquals); break; case SerializedPropertyType.Vector3Int: DefaultBind(element, objWrapper, prop, GetVector3IntPropertyValue, SetVector3IntPropertyValue, ValueEquals); break; case SerializedPropertyType.RectInt: DefaultBind(element, objWrapper, prop, GetRectIntPropertyValue, SetRectIntPropertyValue, ValueEquals); break; case SerializedPropertyType.BoundsInt: DefaultBind(element, objWrapper, prop, GetBoundsIntPropertyValue, SetBoundsIntPropertyValue, ValueEquals); break; case SerializedPropertyType.Character: if (element is INotifyValueChanged <string> ) { DefaultBind(element, objWrapper, prop, GetCharacterPropertyValueAsString, SetCharacterPropertyValueFromString, ValueEquals); } else { DefaultBind(element, objWrapper, prop, GetCharacterPropertyValue, SetCharacterPropertyValue, ValueEquals); } break; case SerializedPropertyType.ExposedReference: case SerializedPropertyType.Generic: // nothing to bind here break; default: Debug.LogWarning(string.Format("Binding is not supported for {0} properties \"{1}\"", prop.type, prop.propertyPath)); break; } }
private static void EnumBind(PopupField <string> popup, SerializedObjectUpdateWrapper objWrapper, SerializedProperty prop) { SerializedEnumBinding.CreateBind(popup, objWrapper, prop); }