From a48e01b278c679bbfc785b93fbb1f8d31c5cc466 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Aug 2016 16:42:36 +0700 Subject: [PATCH] little attrs refactor --- .../Editor/SwfAnimationAssetEditor.cs | 10 +++++-- .../Internal/Editor/SwfPropertyDrawers.cs | 27 +++++++++++++++---- .../Scripts/Internal/SwfPropertyAttributes.cs | 3 +++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs index 4d96d82..4fa0e1f 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs @@ -117,8 +117,14 @@ namespace FlashTools.Internal { void DrawGUISettings() { GUI.enabled = false; - EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script")); - EditorGUILayout.PropertyField(serializedObject.FindProperty("Atlas")); + var script_prop = serializedObject.FindProperty("m_Script"); + if ( script_prop != null ) { + EditorGUILayout.PropertyField(script_prop); + } + var atlas_prop = serializedObject.FindProperty("Atlas"); + if ( atlas_prop != null ) { + EditorGUILayout.PropertyField(atlas_prop); + } GUI.enabled = true; _settingsFoldout = EditorGUILayout.Foldout(_settingsFoldout, "Settings"); if ( _settingsFoldout ) { diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs index bf9b02c..0c445b3 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs @@ -5,6 +5,23 @@ using System.Collections.Generic; namespace FlashTools.Internal.SwfEditorTools { + // + // SwfReadOnlyDrawer + // + + [CustomPropertyDrawer(typeof(SwfReadOnlyAttribute))] + public class SwfReadOnlyDrawer : PropertyDrawer { + + public override void OnGUI( + Rect position, SerializedProperty property, GUIContent label) + { + var last_gui_enabled = GUI.enabled; + GUI.enabled = false; + EditorGUI.PropertyField(position, property, label, true); + GUI.enabled = last_gui_enabled; + } + } + // // SwfSortingLayerDrawer // @@ -57,14 +74,14 @@ namespace FlashTools.Internal.SwfEditorTools { var all_sorting_layers = GetAllSortingLayers(); if ( property.propertyType == SerializedPropertyType.String ) { ValidateProperty(property); - var old_sorting_layer = property.stringValue; + var last_sorting_layer = property.stringValue; var sorting_layer_index = EditorGUI.Popup( position, label, all_sorting_layers.FindIndex(p => p == property.stringValue), all_sorting_layers.Select(p => new GUIContent(p)).ToArray()); property.stringValue = all_sorting_layers[sorting_layer_index]; - if ( old_sorting_layer != property.stringValue ) { + if ( last_sorting_layer != property.stringValue ) { property.serializedObject.ApplyModifiedProperties(); } } else { @@ -105,7 +122,7 @@ namespace FlashTools.Internal.SwfEditorTools { static void ValidateProperty(SerializedProperty property, bool need_pow2, int min_pow2, int max_pow2) { if ( property.propertyType == SerializedPropertyType.Integer ) { - var old_value = property.intValue; + var last_value = property.intValue; if ( need_pow2 && !Mathf.IsPowerOfTwo(property.intValue) ) { property.intValue = Mathf.ClosestPowerOfTwo(property.intValue); } @@ -113,7 +130,7 @@ namespace FlashTools.Internal.SwfEditorTools { property.intValue, GetPowerOfTwo(min_pow2), GetPowerOfTwo(max_pow2)); - if ( old_value != property.intValue ) { + if ( last_value != property.intValue ) { property.serializedObject.ApplyModifiedProperties(); } } @@ -132,7 +149,7 @@ namespace FlashTools.Internal.SwfEditorTools { var vnames = values.Select(p => new GUIContent(p.ToString())).ToArray(); EditorGUI.IntPopup(position, property, vnames, values, label); } else { - EditorGUI.PropertyField(position, property, label); + EditorGUI.PropertyField(position, property, label, true); } } else { EditorGUI.LabelField(position, label.text, "Use SwfPowerOfTwoIf with integer attribute."); diff --git a/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs b/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs index 0586a46..4734f41 100644 --- a/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs +++ b/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs @@ -1,6 +1,9 @@ using UnityEngine; namespace FlashTools.Internal { + public class SwfReadOnlyAttribute : PropertyAttribute { + } + public class SwfSortingLayerAttribute : PropertyAttribute { }