From db8bc5e13ccaaa56cc1ac5e8b4ab21532352b2d6 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 28 Aug 2016 21:28:29 +0700 Subject: [PATCH] change property in instantiated prefab fix --- .../Editor/SwfAnimationControllerEditor.cs | 4 +++ .../Internal/Editor/SwfAnimationEditor.cs | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationControllerEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationControllerEditor.cs index 9768763..132b959 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationControllerEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationControllerEditor.cs @@ -37,10 +37,14 @@ namespace FlashTools.Internal { } public override void OnInspectorGUI() { + serializedObject.Update(); DrawDefaultInspector(); if ( Application.isPlaying ) { DrawAnimationControls(); } + if ( GUI.changed ) { + serializedObject.ApplyModifiedProperties(); + } } } } \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs index a008e48..d4967f0 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs @@ -6,14 +6,22 @@ namespace FlashTools.Internal { public class SwfAnimationEditor : Editor { SwfAnimation _animation = null; + SerializedProperty GetCurrentFrameProperty() { + var prop = serializedObject.FindProperty("_currentFrame"); + if ( prop == null ) { + throw new UnityException("SwfAnimationEditor. Not found current frame property"); + } + return prop; + } + void DrawCurrentFrame() { if ( _animation.frameCount > 1 ) { - var new_current_frame = EditorGUILayout.IntSlider( - "Frame", _animation.currentFrame, - 0, _animation.frameCount - 1); - if ( new_current_frame != _animation.currentFrame ) { - _animation.currentFrame = new_current_frame; - } + Undo.RecordObject(_animation, "Change SwfAnimation frame"); + EditorGUILayout.IntSlider( + GetCurrentFrameProperty(), + 0, + _animation.frameCount - 1, + "Frame"); } } @@ -23,19 +31,27 @@ namespace FlashTools.Internal { GUILayout.FlexibleSpace(); { if ( GUILayout.Button(new GUIContent("<<", "to begin frame")) ) { + Undo.RecordObject(_animation, "Change SwfAnimation frame"); _animation.ToBeginFrame(); + EditorUtility.SetDirty(_animation); } if ( GUILayout.Button(new GUIContent("<", "to prev frame")) ) { + Undo.RecordObject(_animation, "Change SwfAnimation frame"); _animation.ToPrevFrame(); + EditorUtility.SetDirty(_animation); } GUILayout.Label(string.Format( "{0}/{1}", _animation.currentFrame, _animation.frameCount)); if ( GUILayout.Button(new GUIContent(">", "to next frame")) ) { + Undo.RecordObject(_animation, "Change SwfAnimation frame"); _animation.ToNextFrame(); + EditorUtility.SetDirty(_animation); } if ( GUILayout.Button(new GUIContent(">>", "to end frame")) ) { + Undo.RecordObject(_animation, "Change SwfAnimation frame"); _animation.ToEndFrame(); + EditorUtility.SetDirty(_animation); } } GUILayout.FlexibleSpace();