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 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; } }