public static void CreateBind(PopupField <string> field, SerializedObjectUpdateWrapper objWrapper, SerializedProperty property) { var newBinding = s_Pool.Get(); newBinding.isReleased = false; newBinding.SetBinding(field, objWrapper, property); }
protected override void SyncPropertyToField(PopupField <string> c, SerializedProperty p) { int propValueIndex = p.enumValueIndex; if (propValueIndex != lastFieldValueIndex) { lastFieldValueIndex = propValueIndex; c.index = propValueIndex; } }
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 VisualElement CreateFieldFromProperty(SerializedProperty property) { var propertyType = property.propertyType; if (EditorGUI.HasVisibleChildFields(property)) { return(CreateFoldout(property)); } switch (propertyType) { case SerializedPropertyType.Integer: return(CreateLabeledField(new IntegerField(), property)); case SerializedPropertyType.Boolean: return(CreateLabeledField(new Toggle(), property)); case SerializedPropertyType.Float: return(CreateLabeledField(new FloatField(), property)); case SerializedPropertyType.String: return(CreateLabeledField(new TextField(), property)); case SerializedPropertyType.Color: return(CreateLabeledField(new ColorField(), property)); case SerializedPropertyType.ObjectReference: { var field = new ObjectField(); Type requiredType = null; // Checking if the target ExtendsANativeType() avoids a native error when // getting the type about: "type is not a supported pptr value" var target = property.serializedObject.targetObject; if (NativeClassExtensionUtilities.ExtendsANativeType(target)) { ScriptAttributeUtility.GetFieldInfoFromProperty(property, out requiredType); } if (requiredType == null) { requiredType = typeof(UnityEngine.Object); } field.objectType = requiredType; return(CreateLabeledField(field, property)); } case SerializedPropertyType.LayerMask: return(CreateLabeledField(new LayerMaskField(), property)); case SerializedPropertyType.Enum: { var field = new PopupField <string>(property.enumDisplayNames.ToList(), property.enumValueIndex); field.index = property.enumValueIndex; return(CreateLabeledField(field, property)); } case SerializedPropertyType.Vector2: return(CreateLabeledField(new Vector2Field(), property)); case SerializedPropertyType.Vector3: return(CreateLabeledField(new Vector3Field(), property)); case SerializedPropertyType.Vector4: return(CreateLabeledField(new Vector4Field(), property)); case SerializedPropertyType.Rect: return(CreateLabeledField(new RectField(), property)); case SerializedPropertyType.ArraySize: { var field = new IntegerField(); field.SetValueWithoutNotify(property.intValue); // This avoids the OnValueChanged/Rebind feedback loop. field.isDelayed = true; // To match IMGUI. Also, focus is lost anyway due to the rebind. field.OnValueChanged((e) => { UpdateArrayFoldout(e, this, m_ParentPropertyField); }); return(CreateLabeledField(field, property)); } case SerializedPropertyType.Character: { var field = new TextField(); field.maxLength = 1; return(CreateLabeledField(field, property)); } case SerializedPropertyType.AnimationCurve: return(CreateLabeledField(new CurveField(), property)); case SerializedPropertyType.Bounds: return(CreateLabeledField(new BoundsField(), property)); case SerializedPropertyType.Gradient: return(CreateLabeledField(new GradientField(), property)); case SerializedPropertyType.Quaternion: return(null); case SerializedPropertyType.ExposedReference: return(null); case SerializedPropertyType.FixedBufferSize: return(null); case SerializedPropertyType.Vector2Int: return(CreateLabeledField(new Vector2IntField(), property)); case SerializedPropertyType.Vector3Int: return(CreateLabeledField(new Vector3IntField(), property)); case SerializedPropertyType.RectInt: return(CreateLabeledField(new RectIntField(), property)); case SerializedPropertyType.BoundsInt: return(CreateLabeledField(new BoundsIntField(), property)); case SerializedPropertyType.Generic: default: return(null); } }
private static void EnumBind(PopupField <string> popup, SerializedObjectUpdateWrapper objWrapper, SerializedProperty prop) { SerializedEnumBinding.CreateBind(popup, objWrapper, prop); }