/// <inheritdoc /> public override bool DrawBody(Rect position) { HandleDrawHintIcon(position); DrawDragBarIfReorderable(); var guiChangedWas = GUI.changed; GUI.changed = false; bool guiChanged; bool mixedContent = MixedContent; const char valueDuringMixedContent = '\0'; var valueWas = mixedContent ? valueDuringMixedContent : Value; char setValue; DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, memberInfo == null ? false : memberInfo.MixedContent); { setValue = DrawControlVisuals(controlLastDrawPosition, valueWas); guiChanged = GUI.changed; } DrawerUtility.EndInputField(); if (guiChanged) { #if DEV_MODE && DEBUG_VALUE_CHANGED var e = Event.current; Debug.Log(StringUtils.ToColorizedString(ToString(), " DrawControlVisuals GUI.changed detected! valueWas=", valueWas, ", setValue=", setValue, " EditingTextField =", DrawGUI.EditingTextField, ", Event type=", e.type, ", rawType=", e.type, ", isKey=", e.isKey, ", isMouse=", e.isMouse, ", keyCode=", e.keyCode, ", character=", StringUtils.ToString(e.character))); #endif if (ReadOnly) { return(false); } if (!valueWas.Equals(setValue)) { #if DEV_MODE && DEBUG_VALUE_CHANGED Debug.Log(ToString() + " DrawControlVisuals changed value from " + valueWas + " to" + setValue); #endif Value = setValue; return(true); } } return(false); }
/// <inheritdoc /> public override bool DrawBody(Rect position) { HandleDrawHintIcon(position); DrawDragBarIfReorderable(); var guiChangedWas = GUI.changed; GUI.changed = false; bool changed; string valueWas = Value; string setValue; DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, MixedContent); { setValue = DrawControlVisuals(controlLastDrawPosition, valueWas); changed = GUI.changed; } DrawerUtility.EndInputField(); if (changed) { #if DEV_MODE && DEBUG_VALUE_CHANGED Debug.Log(ToString() + " DrawControlVisuals GUI.changed detected! EditingTextField=" + DrawGUI.EditingTextField); #endif // When MixedContent is true and GUI.changed becomes true during DrawControlVisuals, we assume // that the value has been changed by the user, even if valueWas equals the new value. This is because it is possible that // the user happens to enters a value that happens to match that of the passed cached value, in which case // if we only used an ValuesAreEqual, it would return false, and the values of all targets would not get unified. if (!ReadOnly && (MixedContent || !string.Equals(valueWas, setValue))) { #if DEV_MODE && DEBUG_VALUE_CHANGED Debug.Log(ToString() + " DrawControlVisuals changed value from " + StringUtils.ToString(setValue) + " to " + StringUtils.ToString(valueWas)); #endif Value = setValue; return(true); } } GUI.changed = guiChangedWas; return(false); }
/// <inheritdoc/> public sealed override bool DrawBody(Rect position) { HandleDrawHintIcon(position); DrawDragBarIfReorderable(); var valueWas = Value; var setValue = valueWas; if (HasNumberField) { DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, MixedContent); setValue = DrawNumberFieldVisuals(NumberFieldPosition, setValue); DrawerUtility.EndInputField(); } sliderID = GUIUtility.GetControlID(FocusType.Keyboard); DrawerUtility.BeginFocusableField(this, sliderID, ref focusSlider, MixedContent); { if (DrawGUI.EditingTextField) { DrawControlVisuals(SliderPosition, setValue); } else { setValue = DrawControlVisuals(SliderPosition, setValue); } } DrawerUtility.EndFocusableField(); if (!setValue.Equals(valueWas)) { Value = setValue; return(true); } return(false); }
/// <inheritdoc cref="IDrawer.Draw" /> public override bool Draw(Rect position) { #if SAFE_MODE || DEV_MODE var targets = memberInfo.UnityObjects; int targetCount = targets.Length; if (targetCount == 0) { #if DEV_MODE Debug.LogWarning(ToString() + ".Draw() - target count was zero, rebuilding drawer"); #endif InspectorUtility.ActiveInspector.RebuildDrawersIfTargetsChanged(); return(false); } if (targets.ContainsNullObjects()) { #if DEV_MODE Debug.LogWarning(ToString() + ".Draw() - target was null, rebuilding drawer"); #endif InspectorUtility.ActiveInspector.RebuildDrawersIfTargetsChanged(); return(false); } #endif var positionWithoutMargins = position; bool dirty = false; GenerateControlId(); if (Event.current.type == EventType.Layout) { OnLayoutEvent(position); } #if !DRAW_LABEL_RESIZE_CONTROL DrawGUI.Active.ColorRect(position, DrawGUI.Active.InspectorBackgroundColor); #endif position.height -= 2f; position.y += 1f; position.width -= DrawGUI.RightPadding; float labelWidthWas = EditorGUIUtility.labelWidth; float fieldWidthWas = EditorGUIUtility.fieldWidth; float leftPadding = DrawGUI.LeftPadding; int labelRightPadding = (int)(DrawGUI.MiddlePadding + DrawGUI.MiddlePadding); position.x += leftPadding; position.width -= leftPadding; //always use wide mode for properties because it works better with the prefix width control #if ALWAYS_USE_WIDEMODE bool wideModeWas = EditorGUIUtility.wideMode; EditorGUIUtility.wideMode = true; #endif EditorStyles.label.padding.right = labelRightPadding; GUILayout.BeginArea(positionWithoutMargins); { position.y -= positionWithoutMargins.y; position.x -= positionWithoutMargins.x; EditorGUI.BeginChangeCheck(); { DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, memberInfo == null ? false : memberInfo.MixedContent); { var serializedProperty = SerializedProperty; if (serializedProperty == null) { // NOTE: This can happen during Remove Component for some reason #if DEV_MODE Debug.LogError(ToString() + ".Draw - SerializedProperty was null (parent=" + StringUtils.ToString(parent) + ") so can't use EditorGUI.PropertyField"); #endif EditorGUI.PrefixLabel(position, label); } else { bool editingTextFieldWas; EventType eventType; KeyCode keyCode; CustomEditorUtility.BeginPropertyDrawer(out editingTextFieldWas, out eventType, out keyCode); { // fix needed or foldouts will be drawn at incorrect positions var leftMarginWas = EditorStyles.foldout.margin.left; EditorStyles.foldout.margin.left = -12; try { EditorGUI.PropertyField(position, serializedProperty, label, serializedProperty.isExpanded); } catch (Exception e) { if (ExitGUIUtility.ShouldRethrowException(e)) { EditorStyles.foldout.margin.left = leftMarginWas; throw; } #if DEV_MODE Debug.LogWarning(ToString() + " " + e); #endif } EditorStyles.foldout.margin.left = leftMarginWas; } CustomEditorUtility.EndPropertyDrawer(editingTextFieldWas, eventType, keyCode); bool editingTextFieldIs = EditorGUIUtility.editingTextField; if (editingTextFieldIs != editingTextFieldWas) { DrawGUI.EditingTextField = editingTextFieldIs; } } } DrawerUtility.EndInputField(); } if (EditorGUI.EndChangeCheck()) { GUI.changed = true; SerializedProperty.serializedObject.ApplyModifiedProperties(); dirty = true; } } GUILayout.EndArea(); #if ALWAYS_USE_WIDEMODE EditorGUIUtility.wideMode = wideModeWas; #endif EditorStyles.label.padding.right = 2; EditorGUIUtility.labelWidth = labelWidthWas; EditorGUIUtility.fieldWidth = fieldWidthWas; return(dirty); }
/// <inheritdoc/> public override bool DrawBody(Rect position) { HandleDrawHintIcon(position); DrawDragBarIfReorderable(); var guiChangedWas = GUI.changed; GUI.changed = false; bool guiChanged; bool mixedContent = MixedContent; var valueWas = mixedContent ? ValueDuringMixedContent : Value; TValue setValue; DrawerUtility.BeginInputField(this, controlId, ref editField, ref focusField, mixedContent); { setValue = DrawControlVisuals(position, valueWas); guiChanged = GUI.changed; } DrawerUtility.EndInputField(); if (guiChanged && !DraggingPrefix) // new test: disabled when dragging prefix { #if DEV_MODE && DEBUG_VALUE_CHANGED Debug.Log(StringUtils.ToColorizedString(ToString(), " DrawControlVisuals GUI.changed detected! EditingTextField=", DrawGUI.EditingTextField, ", Event type=", Event.current.type, ", rawType=", Event.current.type, ", isKey=", Event.current.isKey, ", isMouse=", Event.current.isMouse, ", keyCode=", Event.current.keyCode, ", character=", StringUtils.ToString(Event.current.character))); #endif if (ReadOnly) { return(false); } if (!ValuesAreEqual(setValue, valueWas)) { #if DEV_MODE && DEBUG_VALUE_CHANGED Debug.Log(ToString() + " DrawControlVisuals changed value from " + valueWas + " to " + setValue); #endif Value = setValue; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(!MixedContent); #endif } else if (mixedContent) { var e = Event.current; // Try to detect if GUI.changed was caused by value being changed. Currently this does not work with delayed fields, would need to add an unappliedValue. if (Event.current.type == EventType.Used && !'\0'.Equals(e.character) && !IsDelayedField) { #if DEV_MODE && DEBUG_VALUE_CHANGED Debug.Log(StringUtils.ToColorizedString(ToString(), " DrawControlVisuals changed value from Mixed to " + setValue + "? EditingTextField=", DrawGUI.EditingTextField, ", Event type=", e.type, ", rawType=", e.type, ", isKey=", e.isKey, ", isMouse=", e.isMouse, ", keyCode=", e.keyCode, ", character=", StringUtils.ToString(e.character))); #endif Value = setValue; } } return(true); } GUI.changed = guiChangedWas; return(false); }