diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs new file mode 100644 index 0000000..911e3db --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs @@ -0,0 +1,22 @@ +using UnityEngine; +using UnityEditor; + +using System; + +namespace FlashTools.Internal { + public static class SwfEditorUtils { + public static void DoWithMixedValue(bool mixed, Action act) { + var last_show_mixed_value = EditorGUI.showMixedValue; + EditorGUI.showMixedValue = mixed; + act(); + EditorGUI.showMixedValue = last_show_mixed_value; + } + + public static void DoWithEnabledGUI(bool enabled, Action act) { + var last_gui_enabled = GUI.enabled; + GUI.enabled = enabled; + act(); + GUI.enabled = last_gui_enabled; + } + } +} \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs.meta b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs.meta new file mode 100644 index 0000000..10c3dec --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 80bbe5b795df64829b002ddb92fb7a37 +timeCreated: 1472455940 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfManagerEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfManagerEditor.cs index 6d29fad..1460116 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfManagerEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfManagerEditor.cs @@ -7,12 +7,11 @@ namespace FlashTools.Internal { SwfManager _manager = null; void DrawAnimationCount() { - var last_gui_enabled = GUI.enabled; - GUI.enabled = false; - EditorGUILayout.IntField( - "Animation count", - _manager.AllAnimationCount); - GUI.enabled = last_gui_enabled; + SwfEditorUtils.DoWithEnabledGUI(false, () => { + EditorGUILayout.IntField( + "Animation count", + _manager.AllAnimationCount); + }); } // --------------------------------------------------------------------- diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs index cf93a8d..1b2d406 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs @@ -110,36 +110,31 @@ namespace FlashTools.Internal.SwfEditorTools { } } - static void DoWithMixedValue(bool mixed, Action act) { - var last_show_mixed_value = EditorGUI.showMixedValue; - EditorGUI.showMixedValue = mixed; - act(); - EditorGUI.showMixedValue = last_show_mixed_value; - } - public override void OnGUI( Rect position, SerializedProperty property, GUIContent label) { if ( property.propertyType == SerializedPropertyType.String ) { ValidateProperty(property); - DoWithMixedValue(property.hasMultipleDifferentValues, () => { - var all_sorting_layers = GetAllSortingLayers(true); - var sorting_layer_index = EditorGUI.Popup( - position, - label, - property.hasMultipleDifferentValues - ? all_sorting_layers.FindIndex(p => string.IsNullOrEmpty(p)) - : all_sorting_layers.FindIndex(p => p == property.stringValue), - all_sorting_layers.Select(p => new GUIContent(p)).ToArray()); - var new_value = all_sorting_layers[sorting_layer_index]; - if ( !string.IsNullOrEmpty(new_value) ) { - if ( property.hasMultipleDifferentValues ) { - property.stringValue = string.Empty; + SwfEditorUtils.DoWithMixedValue( + property.hasMultipleDifferentValues, () => + { + var all_sorting_layers = GetAllSortingLayers(true); + var sorting_layer_index = EditorGUI.Popup( + position, + label, + property.hasMultipleDifferentValues + ? all_sorting_layers.FindIndex(p => string.IsNullOrEmpty(p)) + : all_sorting_layers.FindIndex(p => p == property.stringValue), + all_sorting_layers.Select(p => new GUIContent(p)).ToArray()); + var new_value = all_sorting_layers[sorting_layer_index]; + if ( !string.IsNullOrEmpty(new_value) ) { + if ( property.hasMultipleDifferentValues ) { + property.stringValue = string.Empty; + } + property.stringValue = new_value; + property.serializedObject.ApplyModifiedProperties(); } - property.stringValue = new_value; - property.serializedObject.ApplyModifiedProperties(); - } - }); + }); } else { EditorGUI.LabelField(position, label.text, "Use SwfSortingLayer with string attribute."); } @@ -194,13 +189,6 @@ namespace FlashTools.Internal.SwfEditorTools { } } - static void DoWithMixedValue(bool mixed, Action act) { - var last_show_mixed_value = EditorGUI.showMixedValue; - EditorGUI.showMixedValue = mixed; - act(); - EditorGUI.showMixedValue = last_show_mixed_value; - } - public override void OnGUI( Rect position, SerializedProperty property, GUIContent label) { @@ -209,15 +197,17 @@ namespace FlashTools.Internal.SwfEditorTools { var bool_prop = FindNextBoolProperty(property, attr.BoolProp); var need_pow2 = (bool_prop != null && (bool_prop.boolValue || bool_prop.hasMultipleDifferentValues)); ValidateProperty(property, need_pow2, attr.MinPow2, attr.MaxPow2); - DoWithMixedValue(property.hasMultipleDifferentValues, () => { - if ( need_pow2 ) { - var values = GenPowerOfTwoValues(attr.MinPow2, attr.MaxPow2); - var vnames = values.Select(p => new GUIContent(p.ToString())).ToArray(); - EditorGUI.IntPopup(position, property, vnames, values, label); - } else { - EditorGUI.PropertyField(position, property, label, true); - } - }); + SwfEditorUtils.DoWithMixedValue( + property.hasMultipleDifferentValues, () => + { + if ( need_pow2 ) { + var values = GenPowerOfTwoValues(attr.MinPow2, attr.MaxPow2); + var vnames = values.Select(p => new GUIContent(p.ToString())).ToArray(); + EditorGUI.IntPopup(position, property, vnames, values, label); + } else { + EditorGUI.PropertyField(position, property, label, true); + } + }); } else { EditorGUI.LabelField(position, label.text, "Use SwfPowerOfTwoIf with integer attribute."); } diff --git a/Assets/FlashTools/Scripts/SwfManager.cs b/Assets/FlashTools/Scripts/SwfManager.cs index 4f32de5..3d4108c 100644 --- a/Assets/FlashTools/Scripts/SwfManager.cs +++ b/Assets/FlashTools/Scripts/SwfManager.cs @@ -8,11 +8,6 @@ using UnityEditor; namespace FlashTools { [ExecuteInEditMode, DisallowMultipleComponent] public class SwfManager : MonoBehaviour { - // --------------------------------------------------------------------- - // - // Properties - // - // --------------------------------------------------------------------- HashSet _animations = new HashSet(); HashSet _controllers = new HashSet();