public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property.propertyType != SerializedPropertyType.AnimationCurve) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } if (this.attribute is AnimationCurveConstraintAttribute) { var attrib = this.attribute as AnimationCurveConstraintAttribute; var ranges = new Rect(attrib.x, attrib.y, attrib.width, attrib.height); property.animationCurveValue = EditorGUI.CurveField(position, label, property.animationCurveValue, attrib.color, ranges); } else if (this.attribute is AnimationCurveEaseScaleAttribute) { var attrib = this.attribute as AnimationCurveEaseScaleAttribute; var ranges = new Rect(0f, -Mathf.Max(0f, attrib.overscan), 1f, Mathf.Max(1f, 1f + attrib.overscan * 2f)); property.animationCurveValue = EditorGUI.CurveField(position, label, property.animationCurveValue, attrib.color, ranges); } else { SPEditorGUI.DefaultPropertyField(position, property, label); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (!_initialized) { this.Init(true); } this.OnBeforeGUI(property); if (_subDrawer != null) { _subDrawer.OnGUI(position, property, label); } else { bool includeChildren = false; if (this.attribute is PropertyModifierAttribute) { includeChildren = (this.attribute as PropertyModifierAttribute).IncludeChidrenOnDraw; } SPEditorGUI.DefaultPropertyField(position, property, label, includeChildren); } this.OnPostGUI(property); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var attrib = this.attribute as DisplayNestedPropertyAttribute; if (attrib == null) { EditorGUI.LabelField(position, label, EditorHelper.TempContent("DisplayNestedPropertyAttribute could not be found.")); return; } var p = property.FindPropertyRelative(attrib.InnerPropName); if (p != null) { if (attrib.Label != null) { label = EditorHelper.TempContent(attrib.Label, attrib.Tooltip); } SPEditorGUI.DefaultPropertyField(position, p, label); } else { EditorGUI.LabelField(position, label, EditorHelper.TempContent(string.Format("Nested Property with name {0} could not be found.", attrib.InnerPropName))); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { bool cache = property.isExpanded; property.isExpanded = true; if (!property.hasChildren) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } float h = SPEditorGUI.GetDefaultPropertyHeight(property, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight; var area = new Rect(position.x, position.yMax - h, position.width, h); var drawArea = new Rect(area.x, area.y + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD); GUI.BeginGroup(area, label, GUI.skin.box); GUI.EndGroup(); EditorGUI.indentLevel++; SPEditorGUI.FlatChildPropertyField(drawArea, property); EditorGUI.indentLevel--; property.isExpanded = cache; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { _totalWeight = 0f; if (!property.isArray) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } if (!this.ManuallyConfigured) { var attrib = this.attribute as WeightedValueCollectionAttribute; if (attrib == null) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } else { this.WeightPropertyName = attrib.WeightPropertyName; } } for (int i = 0; i < property.arraySize; i++) { var element = property.GetArrayElementAtIndex(i); var weightProp = element.FindPropertyRelative(this.WeightPropertyName); if (weightProp != null && weightProp.propertyType == SerializedPropertyType.Float) { _totalWeight += weightProp.floatValue; } } base.OnGUI(position, property, label); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property.propertyType != SerializedPropertyType.String) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } var tr = GameObjectUtil.GetTransformFromSource(property.serializedObject.targetObject); if (tr == null) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } IAIController controller = tr.GetComponentInParent <IAIController>() ?? tr.FindComponent <IAIController>(); if (controller == null) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } var names = (controller.Variables == null) ? ArrayUtil.Empty <string>() : controller.Variables.Names.ToArray(); /* * var guiNames = (from n in names select EditorHelper.TempContent(n)).Append(EditorHelper.TempContent("Custom...")).ToArray(); * int index = names.IndexOf(property.stringValue); * if (index < 0) index = names.Length; * if(index == names.Length) * { * var fw = position.width - EditorGUIUtility.labelWidth; * var wl = EditorGUIUtility.labelWidth + (fw / 4f); * var wr = position.width - wl - 1f; * * var rl = new Rect(position.xMin, position.yMin, wl, EditorGUIUtility.singleLineHeight); * var rr = new Rect(rl.xMax + 1f, rl.yMin, wr, EditorGUIUtility.singleLineHeight); * * index = EditorGUI.Popup(rl, label, index, guiNames); * if (index >= 0 && index < names.Length) * { * property.stringValue = names[index]; * } * else * { * property.stringValue = EditorGUI.TextField(rr, property.stringValue); * } * } * else * { * index = EditorGUI.Popup(position, label, index, guiNames); * property.stringValue = (index >= 0 && index < names.Length) ? names[index] : null; * } */ property.stringValue = SPEditorGUI.OptionPopupWithCustom(position, label, property.stringValue, names); }
private void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused) { var element = _lst.serializedProperty.GetArrayElementAtIndex(index); if (element == null) { return; } //EditorGUI.PropertyField(area, element, GUIContent.none, false); var attrib = this.attribute as ReorderableArrayAttribute; GUIContent label = GUIContent.none; if (attrib != null) { if (attrib.ElementLabelFormatString != null) { label = EditorHelper.TempContent(string.Format(attrib.ElementLabelFormatString, index)); } if (attrib.ElementPadding > 0f) { area = new Rect(area.xMin + attrib.ElementPadding, area.yMin, Mathf.Max(0f, area.width - attrib.ElementPadding), area.height); } } if (_drawElementAtBottom) { var lbl = TempElementLabel(element, index); SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry); if (prop != null) { SPEditorGUI.PropertyField(area, prop, lbl); } else { EditorGUI.LabelField(area, lbl); } } else { if (_internalDrawer != null) { _internalDrawer.OnGUI(area, element, label); } else { SPEditorGUI.DefaultPropertyField(area, element, label, false); } } if (GUI.enabled) { ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (label == null) { label = EditorHelper.TempContent(property.displayName); } if (!property.isArray) { if (_drawer != null) { _drawer.OnGUI(position, property, label); } else { SPEditorGUI.DefaultPropertyField(position, property, label); } } else { if (property.isExpanded) { var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); property.isExpanded = EditorGUI.Foldout(rect, property.isExpanded, label); EditorGUI.indentLevel++; rect = new Rect(rect.xMin, rect.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight); property.arraySize = Mathf.Max(0, EditorGUI.IntField(rect, "Size", property.arraySize)); var lbl = EditorHelper.TempContent(""); for (int i = 0; i < property.arraySize; i++) { var pchild = property.GetArrayElementAtIndex(i); lbl.text = pchild.displayName; if (_drawer != null) { var h = _drawer.GetPropertyHeight(pchild, lbl); rect = new Rect(rect.xMin, rect.yMax + 2f, rect.width, h); _drawer.OnGUI(rect, pchild, lbl); } else { var h = SPEditorGUI.GetDefaultPropertyHeight(pchild, lbl); rect = new Rect(rect.xMin, rect.yMax + 2f, rect.width, h); SPEditorGUI.DefaultPropertyField(rect, pchild, lbl); } } EditorGUI.indentLevel--; } else { property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var attrib = this.attribute as MinRangeAttribute; if (attrib != null && property.propertyType == SerializedPropertyType.Float) { property.floatValue = Mathf.Max(EditorGUI.FloatField(position, label, property.floatValue), attrib.Min); } else { SPEditorGUI.DefaultPropertyField(position, property, label); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (_supplier == null) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } var infos = _supplier.GetLayers(); if (infos == null || infos.Length == 0) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } position = EditorGUI.PrefixLabel(position, label); var names = (from info in infos select info.Name).Append("Custom...").ToArray(); int i = this.GetCurrentIndex(infos, property.intValue); if (i < 0) { i = infos.Length; } var r1 = new Rect(position.xMin, position.yMin, position.width * 0.7f, position.height); var r2 = new Rect(r1.xMax, r1.yMin, position.width - r1.width, r1.height); EditorGUI.BeginChangeCheck(); i = EditorGUI.Popup(r1, i, names); if (EditorGUI.EndChangeCheck()) { if (i == infos.Length) { property.intValue = (from info in infos select info.Layer).Max() + 1; } else { property.intValue = infos[i].Layer; } } EditorGUI.BeginChangeCheck(); int layer = EditorGUI.IntField(r2, property.intValue); if (EditorGUI.EndChangeCheck()) { property.intValue = layer; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { bool canShrink = this.attribute is DisplayFlatAttribute ? (this.attribute as DisplayFlatAttribute).CanShrinkAndExpand : false; bool cache = property.isExpanded; if (!canShrink) { property.isExpanded = true; } try { if (!property.hasChildren) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } if (canShrink) { cache = SPEditorGUI.PrefixFoldoutLabel(position, property.isExpanded, GUIContent.none); } if (property.isExpanded) { float h = SPEditorGUI.GetDefaultPropertyHeight(property, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight; var area = new Rect(position.x, position.yMax - h, position.width, h); var drawArea = new Rect(area.x, area.y + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD); GUI.BeginGroup(area, label, GUI.skin.box); GUI.EndGroup(); EditorGUI.indentLevel++; SPEditorGUI.FlatChildPropertyField(drawArea, property); EditorGUI.indentLevel--; } else { GUI.BeginGroup(position, label, GUI.skin.box); GUI.EndGroup(); } } catch (System.Exception ex) { throw ex; } finally { property.isExpanded = cache; } }
protected virtual void DrawElement(Rect area, SerializedProperty element, GUIContent label, int elementIndex) { if (_drawElementAtBottom) { SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry); if (prop != null) { SPEditorGUI.PropertyField(area, prop, label); } else { EditorGUI.LabelField(area, label); } } else { if (_internalDrawer != null) { _internalDrawer.OnGUI(area, element, label); } else if (ElementIsFlatChildField(element)) { //we don't draw this way if it's a built-in type from Unity if (_hideElementLabel) { //no label SPEditorGUI.FlatChildPropertyField(area, element); } else { //showing label var labelArea = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(labelArea, label); var childArea = new Rect(area.xMin, area.yMin + EditorGUIUtility.singleLineHeight + 1f, area.width, area.height - EditorGUIUtility.singleLineHeight); SPEditorGUI.FlatChildPropertyField(childArea, element); } } else { area = EditorGUI.PrefixLabel(area, label); SPEditorGUI.DefaultPropertyField(area, element, label, false); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var tp = this.fieldInfo.FieldType; if (TypeUtil.IsListType(tp)) { tp = TypeUtil.GetElementTypeOfListType(tp); } if (!tp.IsEnum) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } System.Enum e = property.GetEnumValue(tp); e = SPEditorGUI.EnumPopup(position, label, e); property.SetEnumValue(e); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var attrib = this.attribute as MaxRangeAttribute; switch (attrib != null ? property.propertyType : SerializedPropertyType.Generic) { case SerializedPropertyType.Float: property.floatValue = Mathf.Min(EditorGUI.FloatField(position, label, property.floatValue), attrib.Max); break; case SerializedPropertyType.Integer: property.intValue = (int)Mathf.Min(EditorGUI.IntField(position, label, property.intValue), attrib.Max); break; default: SPEditorGUI.DefaultPropertyField(position, property, label); break; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { switch (property.propertyType) { case SerializedPropertyType.Vector2: this.DrawVector2(position, property, label); break; case SerializedPropertyType.Vector3: this.DrawVector3(position, property, label); break; case SerializedPropertyType.Vector4: this.DrawVector4(position, property, label); break; default: SPEditorGUI.DefaultPropertyField(position, property, label); break; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var attrib = this.attribute as DefaultOrConfiguredAttribute; if (attrib == null) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } if (attrib.DrawAsDefault(EditorHelper.GetPropertyValue(property))) { var value = attrib.GetValueToDisplayAsDefault(); label.text += " (Default Value)"; EditorGUI.BeginChangeCheck(); value = SPEditorGUI.DefaultPropertyField(position, label, value, attrib.FieldType); if (EditorGUI.EndChangeCheck()) { EditorHelper.SetPropertyValue(property, value); } } else { var r0 = new Rect(position.xMin, position.yMin, Mathf.Max(0f, position.width - SPEditorGUI.X_BTN_WIDTH), position.height); SPEditorGUI.DefaultPropertyField(r0, property, label); var w = position.width = r0.width; if (w > 1f) { var r1 = new Rect(position.xMax - w, position.yMin, w, EditorGUIUtility.singleLineHeight); if (SPEditorGUI.XButton(r1, "Reset to default value.")) { EditorHelper.SetPropertyValue(property, attrib.GetDefaultValue()); } } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); EditorGUI.BeginProperty(position, label, property); var attr = this.attribute as EulerRotationInspectorAttribute; switch (property.propertyType) { case SerializedPropertyType.Quaternion: property.quaternionValue = ConvertUtil.ToQuaternion(EditorGUI.Vector4Field(position, label, ConvertUtil.ToVector4(property.quaternionValue))); break; case SerializedPropertyType.Vector2: property.vector2Value = EditorGUI.Vector2Field(position, label, property.vector2Value); break; case SerializedPropertyType.Vector3: property.vector3Value = EditorGUI.Vector3Field(position, label, property.vector3Value); break; case SerializedPropertyType.Vector4: property.vector4Value = EditorGUI.Vector3Field(position, label, property.vector4Value); break; default: SPEditorGUI.DefaultPropertyField(position, property, label); break; } EditorGUI.EndProperty(); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property.propertyType != SerializedPropertyType.String) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } var tr = GameObjectUtil.GetTransformFromSource(property.serializedObject.targetObject); if (tr == null) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } IAIController controller = tr.GetComponent <IAIController>(); while (controller == null && tr.parent != null) { tr = tr.parent; controller = tr.GetComponent <IAIController>(); } if (controller == null) { SPEditorGUI.DefaultPropertyField(position, property, label); return; } var names = (controller.Variables == null) ? new string[] {} : controller.Variables.Names.ToArray(); var guiNames = (from n in names select EditorHelper.TempContent(n)).Append(EditorHelper.TempContent("Custom...")).ToArray(); int index = names.IndexOf(property.stringValue); if (index < 0) { index = names.Length; } if (index == names.Length) { var fw = position.width - EditorGUIUtility.labelWidth; var wl = EditorGUIUtility.labelWidth + (fw / 4f); var wr = position.width - wl - 1f; var rl = new Rect(position.xMin, position.yMin, wl, EditorGUIUtility.singleLineHeight); var rr = new Rect(rl.xMax + 1f, rl.yMin, wr, EditorGUIUtility.singleLineHeight); index = EditorGUI.Popup(rl, label, index, guiNames); if (index >= 0 && index < names.Length) { property.stringValue = names[index]; } else { property.stringValue = EditorGUI.TextField(rr, property.stringValue); } } else { index = EditorGUI.Popup(position, label, index, guiNames); property.stringValue = (index >= 0 && index < names.Length) ? names[index] : null; } }
private void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused) { var element = _lst.serializedProperty.GetArrayElementAtIndex(index); if (element == null) { return; } //EditorGUI.PropertyField(area, element, GUIContent.none, false); var attrib = this.attribute as ReorderableArrayAttribute; GUIContent label = GUIContent.none; if (attrib != null) { if (attrib.ElementLabelFormatString != null) { label = EditorHelper.TempContent(string.Format(attrib.ElementLabelFormatString, index)); } if (attrib.ElementPadding > 0f) { area = new Rect(area.xMin + attrib.ElementPadding, area.yMin, Mathf.Max(0f, area.width - attrib.ElementPadding), area.height); } } if (_drawElementAtBottom) { var lbl = TempElementLabel(element, index); SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry); if (prop != null) { SPEditorGUI.PropertyField(area, prop, lbl); } else { EditorGUI.LabelField(area, lbl); } } else { if (_internalDrawer != null) { _internalDrawer.OnGUI(area, element, label); } else if (element.hasChildren && element.objectReferenceValue is MonoBehaviour) { //we don't draw this way if it's a built-in type from Unity var labelArea = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(labelArea, label); var childArea = new Rect(area.xMin, area.yMin + EditorGUIUtility.singleLineHeight + 1f, area.width, area.height - EditorGUIUtility.singleLineHeight); SPEditorGUI.FlatChildPropertyField(childArea, element); } else { SPEditorGUI.DefaultPropertyField(area, element, label, false); } } if (GUI.enabled) { ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label)) { return; } if (property.isArray) { if (this.CustomLabel != null) { label = this.CustomLabel; } else if (label != null) { label = EditorHelper.CloneContent(label); if (_showTooltipInHeader) { label.text = string.Format("{0} [{1:0}] - {2}", label.text, property.arraySize, (string.IsNullOrEmpty(label.tooltip) ? property.tooltip : label.tooltip)); } else { label.text = string.Format("{0} [{1:0}]", label.text, property.arraySize); } if (string.IsNullOrEmpty(label.tooltip)) { label.tooltip = property.tooltip; } } else { label = EditorHelper.TempContent(property.displayName, property.tooltip); } //const float WIDTH_FOLDOUT = 5f; var foldoutRect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); position = EditorGUI.IndentedRect(position); Rect listArea = position; if (_disallowFoldout) { listArea = new Rect(position.xMin, position.yMin, position.width, _lst.GetHeight()); this.StartOnGUI(property, label); //_lst.DoList(EditorGUI.IndentedRect(position)); _lst.DoList(listArea); this.EndOnGUI(property, label); } else { if (property.isExpanded) { listArea = new Rect(position.xMin, position.yMin, position.width, _lst.GetHeight()); this.StartOnGUI(property, label); property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none); //_lst.DoList(EditorGUI.IndentedRect(position)); _lst.DoList(listArea); this.EndOnGUI(property, label); } else { if (_removeBackgroundWhenCollapsed) { property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label); } else { property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none); //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label); ReorderableListHelper.DrawRetractedHeader(position, label); } } } this.DoDragAndDrop(property, listArea); if (property.isExpanded && _drawElementAtBottom && _lst.index >= 0 && _lst.index < property.arraySize) { var pchild = property.GetArrayElementAtIndex(_lst.index); var label2 = TempElementLabel(pchild, _lst.index); //(string.IsNullOrEmpty(_childPropertyAsLabel)) ? TempElementLabel(_lst.index) : GUIContent.none; pchild.isExpanded = true; float h; if (_internalDrawer != null) { h = _internalDrawer.GetPropertyHeight(pchild, label2) + BOTTOM_PAD + TOP_PAD; } else if (pchild.hasChildren) { h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight; } else { h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label2, true) + BOTTOM_PAD + TOP_PAD; } var area = new Rect(position.xMin, position.yMax - h, position.width, h); var drawArea = new Rect(area.xMin, area.yMin + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD); GUI.BeginGroup(area, label2, GUI.skin.box); GUI.EndGroup(); EditorGUI.indentLevel++; if (_internalDrawer != null) { _internalDrawer.OnGUI(drawArea, pchild, label2); } else if (pchild.hasChildren) { SPEditorGUI.FlatChildPropertyField(drawArea, pchild); } else { SPEditorGUI.DefaultPropertyField(drawArea, pchild, GUIContent.none, false); } EditorGUI.indentLevel--; } } else { SPEditorGUI.DefaultPropertyField(position, property, label, false); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label)) { return; } if (property.isArray) { if (_disallowFoldout) { this.StartOnGUI(property, label); //_lst.DoList(EditorGUI.IndentedRect(position)); _lst.DoList(position); this.EndOnGUI(property, label); } else { const float WIDTH_FOLDOUT = 5f; if (property.isExpanded) { this.StartOnGUI(property, label); property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none); //_lst.DoList(EditorGUI.IndentedRect(position)); _lst.DoList(position); this.EndOnGUI(property, label); } else { if (_removeBackgroundWhenCollapsed) { property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label); } else { property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none); //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label); ReorderableListHelper.DrawRetractedHeader(position, label); } } } if (_drawElementAtBottom && _lst.index >= 0 && _lst.index < property.arraySize) { var pchild = property.GetArrayElementAtIndex(_lst.index); var label2 = TempElementLabel(pchild, _lst.index); //(string.IsNullOrEmpty(_childPropertyAsLabel)) ? TempElementLabel(_lst.index) : GUIContent.none; pchild.isExpanded = true; float h; if (_internalDrawer != null) { h = _internalDrawer.GetPropertyHeight(pchild, label2) + BOTTOM_PAD; } else { h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label2, true) + BOTTOM_PAD; } var area = new Rect(position.x, position.yMax - h, position.width, h); GUI.BeginGroup(area, label2, GUI.skin.box); GUI.EndGroup(); if (_internalDrawer != null) { _internalDrawer.OnGUI(area, pchild, label2); } else { SPEditorGUI.DefaultPropertyField(area, pchild, GUIContent.none, true); } } } else { EditorGUI.PropertyField(position, property, label, false); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (!property.isArray) { EditorGUI.PropertyField(position, property, label, false); return; } if (property.arraySize == 0) { property.arraySize = 1; } if (property.arraySize == 1) { var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(0), label) : EditorGUIUtility.singleLineHeight; var propArea = new Rect(position.xMin, position.yMin, Mathf.Max(0f, position.width - BTN_WIDTH), elementHeight); var btnArea = new Rect(propArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight); if (_internalDrawer != null) { _internalDrawer.OnGUI(propArea, property.GetArrayElementAtIndex(0), label); } else { SPEditorGUI.DefaultPropertyField(propArea, property.GetArrayElementAtIndex(0), label); } if (GUI.Button(btnArea, _moreBtnLabel)) { property.arraySize = 2; } } else { var elementArea = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); //draw header var leftOverArea = EditorGUI.PrefixLabel(elementArea, label ?? GUIContent.none); var sizeArea = new Rect(Mathf.Max(leftOverArea.xMin, leftOverArea.xMax - BTN_WIDTH - SIZE_WIDTH), leftOverArea.yMin, Mathf.Min(SIZE_WIDTH, Mathf.Max(0f, leftOverArea.width - BTN_WIDTH)), EditorGUIUtility.singleLineHeight); var btnArea = new Rect(sizeArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight); property.arraySize = Mathf.Max(EditorGUI.IntField(sizeArea, property.arraySize), 1); if (GUI.Button(btnArea, _oneBtnLabel)) { property.arraySize = 1; } EditorGUI.indentLevel++; for (int i = 0; i < property.arraySize; i++) { var lbl = EditorHelper.TempContent("Element " + i.ToString()); var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(i), lbl) : EditorGUIUtility.singleLineHeight; elementArea = new Rect(position.xMin, elementArea.yMax, position.width, elementHeight); if (_internalDrawer != null) { _internalDrawer.OnGUI(elementArea, property.GetArrayElementAtIndex(i), lbl); } else { SPEditorGUI.DefaultPropertyField(elementArea, property.GetArrayElementAtIndex(i), lbl); } } EditorGUI.indentLevel--; } }