[unity] Fix multi-edit bug on flipX/flipY inspectors.

This commit is contained in:
pharan 2018-09-23 23:59:45 +08:00
parent 4044c81ace
commit 3e997a2765
3 changed files with 39 additions and 6 deletions

View File

@ -253,8 +253,8 @@ namespace Spine.Unity.Editor {
using (new SpineInspectorUtility.IndentScope()) {
using (new EditorGUILayout.HorizontalScope()) {
initialFlipX.boolValue = EditorGUILayout.ToggleLeft(initialFlipX.displayName, initialFlipX.boolValue, GUILayout.Width(120f));
initialFlipY.boolValue = EditorGUILayout.ToggleLeft(initialFlipY.displayName, initialFlipY.boolValue, GUILayout.Width(120f));
SpineInspectorUtility.ToggleLeftLayout(initialFlipX);
SpineInspectorUtility.ToggleLeftLayout(initialFlipY);
EditorGUILayout.Space();
}
@ -370,7 +370,6 @@ namespace Spine.Unity.Editor {
}
override public void OnInspectorGUI () {
//serializedObject.Update();
bool multi = serializedObject.isEditingMultipleObjects;
DrawInspectorGUI(multi);
if (serializedObject.ApplyModifiedProperties() || SpineInspectorUtility.UndoRedoPerformed(Event.current)) {

View File

@ -71,6 +71,40 @@ namespace Spine.Unity.Editor {
PropertyFieldWideLabel(property, label, width);
}
/// <summary>Multi-edit-compatible version of EditorGUILayout.ToggleLeft(SerializedProperty)</summary>
public static void ToggleLeftLayout (SerializedProperty property, GUIContent label = null, float width = 120f) {
if (label == null) label = SpineInspectorUtility.TempContent(property.displayName, tooltip: property.tooltip);
if (property.hasMultipleDifferentValues) {
bool previousShowMixedValue = EditorGUI.showMixedValue;
EditorGUI.showMixedValue = true;
bool clicked = EditorGUILayout.ToggleLeft(label, property.boolValue, GUILayout.Width(width));
if (clicked) property.boolValue = true; // Set all values to true when clicked.
EditorGUI.showMixedValue = previousShowMixedValue;
} else {
property.boolValue = EditorGUILayout.ToggleLeft(label, property.boolValue, GUILayout.Width(width));
}
}
/// <summary>Multi-edit-compatible version of EditorGUILayout.ToggleLeft(SerializedProperty)</summary>
public static void ToggleLeft (Rect rect, SerializedProperty property, GUIContent label = null) {
if (label == null) label = SpineInspectorUtility.TempContent(property.displayName, tooltip: property.tooltip);
if (property.hasMultipleDifferentValues) {
bool previousShowMixedValue = EditorGUI.showMixedValue;
EditorGUI.showMixedValue = true;
bool clicked = EditorGUI.ToggleLeft(rect, label, property.boolValue);
if (clicked) property.boolValue = true; // Set all values to true when clicked.
EditorGUI.showMixedValue = previousShowMixedValue;
} else {
property.boolValue = EditorGUI.ToggleLeft(rect, label, property.boolValue);
}
}
public static bool UndoRedoPerformed (UnityEngine.Event current) {
return current.type == EventType.ValidateCommand && current.commandName == "UndoRedoPerformed";
}

View File

@ -99,9 +99,9 @@ namespace Spine.Unity.Editor {
EditorGUI.PrefixLabel(rect, SpineInspectorUtility.TempContent("Initial Flip"));
rect.x += EditorGUIUtility.labelWidth;
rect.width = 30f;
initialFlipX.boolValue = EditorGUI.ToggleLeft(rect, SpineInspectorUtility.TempContent("X", tooltip:"initialFlipX"), initialFlipX.boolValue);
SpineInspectorUtility.ToggleLeft(rect, initialFlipX, SpineInspectorUtility.TempContent("X", tooltip: "initialFlipX"));
rect.x += 35f;
initialFlipY.boolValue = EditorGUI.ToggleLeft(rect, SpineInspectorUtility.TempContent("Y", tooltip:"initialFlipY"), initialFlipY.boolValue);
SpineInspectorUtility.ToggleLeft(rect, initialFlipY, SpineInspectorUtility.TempContent("Y", tooltip: "initialFlipY"));
}
EditorGUILayout.Space();