public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); if (property.propertyType == SerializedPropertyType.String) { EditorGUILayout.LabelField(property.displayName); EditorGUI.BeginChangeCheck(); string textAreaValue = EditorGUILayout.TextArea(property.stringValue, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 3f)); if (EditorGUI.EndChangeCheck()) { property.stringValue = textAreaValue; } } else { string warning = PropertyUtility.GetAttributes <ResizableTextAreaAttribute>(property)[0].GetType().Name + " can only be used on string fields"; EditorGUILayout.HelpBox(warning, MessageType.Warning); Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawPropertyField(property); if (property.propertyType == SerializedPropertyType.ObjectReference) { if (property.objectReferenceValue != null) { Texture2D previewTexture = AssetPreview.GetAssetPreview(property.objectReferenceValue); if (previewTexture != null) { ShowAssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttribute <ShowAssetPreviewAttribute>(property); int width = Mathf.Clamp(showAssetPreviewAttribute.Width, 0, previewTexture.width); int height = Mathf.Clamp(showAssetPreviewAttribute.Height, 0, previewTexture.height); GUILayout.Label(previewTexture, GUILayout.MaxWidth(width), GUILayout.MaxHeight(height)); } else { this.DrawWarningBox(property.name + " doesn't have an asset preview", property); } } } else { this.DrawWarningBox(property.name + " doesn't have an asset preview", property); } }
private void DrawField(FieldInfo field) { // Check if the field has draw conditions PropertyDrawCondition drawCondition = this.GetPropertyDrawConditionForField(field); if (drawCondition != null) { bool canDrawProperty = drawCondition.CanDrawProperty(this.serializedPropertiesByFieldName[field.Name]); if (!canDrawProperty) { return; } } // Check if the field has HideInInspectorAttribute HideInInspector[] hideInInspectorAttributes = (HideInInspector[])field.GetCustomAttributes(typeof(HideInInspector), true); if (hideInInspectorAttributes.Length > 0) { return; } // Draw the field EditorGUI.BeginChangeCheck(); PropertyDrawer drawer = this.GetPropertyDrawerForField(field); if (drawer != null) { drawer.DrawProperty(this.serializedPropertiesByFieldName[field.Name]); } else { EditorDrawUtility.DrawPropertyField(this.serializedPropertiesByFieldName[field.Name]); } if (EditorGUI.EndChangeCheck()) { OnValueChangedAttribute[] onValueChangedAttributes = (OnValueChangedAttribute[])field.GetCustomAttributes(typeof(OnValueChangedAttribute), true); foreach (var onValueChangedAttribute in onValueChangedAttributes) { PropertyMeta meta = PropertyMetaDatabase.GetMetaForAttribute(onValueChangedAttribute.GetType()); if (meta != null) { meta.ApplyPropertyMeta(this.serializedPropertiesByFieldName[field.Name], onValueChangedAttribute); } } } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); if (property.isArray) { if (!this.reorderableListsByPropertyName.ContainsKey(property.name)) { ReorderableList reorderableList = new ReorderableList(property.serializedObject, property, true, true, true, true) { drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, string.Format("{0}: {1}", property.displayName, property.arraySize), EditorStyles.label); }, drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = property.GetArrayElementAtIndex(index); rect.y += 2f; EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element); } }; this.reorderableListsByPropertyName[property.name] = reorderableList; } this.reorderableListsByPropertyName[property.name].DoLayoutList(); } else { string warning = typeof(ReorderableListAttribute).Name + " can be used only on arrays or lists"; EditorGUILayout.HelpBox(warning, MessageType.Warning); Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); SliderAttribute sliderAttribute = PropertyUtility.GetAttribute <SliderAttribute>(property); if (property.propertyType == SerializedPropertyType.Integer) { EditorGUILayout.IntSlider(property, (int)sliderAttribute.MinValue, (int)sliderAttribute.MaxValue); } else if (property.propertyType == SerializedPropertyType.Float) { EditorGUILayout.Slider(property, sliderAttribute.MinValue, sliderAttribute.MaxValue); } else { string warning = sliderAttribute.GetType().Name + " can be used only on int or float fields"; EditorGUILayout.HelpBox(warning, MessageType.Warning); Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void DrawProperty(SerializedProperty property) { GUI.enabled = false; EditorDrawUtility.DrawPropertyField(property); GUI.enabled = true; }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); MinMaxSliderAttribute minMaxSliderAttribute = PropertyUtility.GetAttribute <MinMaxSliderAttribute>(property); if (property.propertyType == SerializedPropertyType.Vector2) { Rect controlRect = EditorGUILayout.GetControlRect(); float labelWidth = EditorGUIUtility.labelWidth; float floatFieldWidth = EditorGUIUtility.fieldWidth; float sliderWidth = controlRect.width - labelWidth - 2f * floatFieldWidth; float sliderPadding = 5f; Rect labelRect = new Rect( controlRect.x, controlRect.y, labelWidth, controlRect.height); Rect sliderRect = new Rect( controlRect.x + labelWidth + floatFieldWidth + sliderPadding, controlRect.y, sliderWidth - 2f * sliderPadding, controlRect.height); Rect minFloatFieldRect = new Rect( controlRect.x + labelWidth, controlRect.y, floatFieldWidth, controlRect.height); Rect maxFloatFieldRect = new Rect( controlRect.x + labelWidth + floatFieldWidth + sliderWidth, controlRect.y, floatFieldWidth, controlRect.height); // Draw the label EditorGUI.LabelField(labelRect, property.displayName); // Draw the slider EditorGUI.BeginChangeCheck(); Vector2 sliderValue = property.vector2Value; EditorGUI.MinMaxSlider(sliderRect, ref sliderValue.x, ref sliderValue.y, minMaxSliderAttribute.MinValue, minMaxSliderAttribute.MaxValue); sliderValue.x = EditorGUI.FloatField(minFloatFieldRect, sliderValue.x); sliderValue.x = Mathf.Clamp(sliderValue.x, minMaxSliderAttribute.MinValue, Mathf.Min(minMaxSliderAttribute.MaxValue, sliderValue.y)); sliderValue.y = EditorGUI.FloatField(maxFloatFieldRect, sliderValue.y); sliderValue.y = Mathf.Clamp(sliderValue.y, Mathf.Max(minMaxSliderAttribute.MinValue, sliderValue.x), minMaxSliderAttribute.MaxValue); if (EditorGUI.EndChangeCheck()) { property.vector2Value = sliderValue; } } else { string warning = minMaxSliderAttribute.GetType().Name + " can be used only on Vector2 fields"; EditorGUILayout.HelpBox(warning, MessageType.Warning); Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }