diff --git a/.gitignore b/.gitignore index 9bd7280..35a5404 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ obj/* +Logs/* Temp/* Library/* diff --git a/Assets/FlashTools/Docs/CHANGELOG.md b/Assets/FlashTools/Docs/CHANGELOG.md index c5dd95b..e5c27e7 100644 --- a/Assets/FlashTools/Docs/CHANGELOG.md +++ b/Assets/FlashTools/Docs/CHANGELOG.md @@ -1,3 +1,6 @@ +###### Version 1.3.15 +* Fix preview leaks in the Editor mode + ###### Version 1.3.14 * Fix 2018.3.2f1 compilation diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs index a9e1728..624e8bc 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs @@ -11,7 +11,8 @@ using FTRuntime; namespace FTEditor.Editors { [CustomEditor(typeof(SwfClipAsset)), CanEditMultipleObjects] class SwfClipAssetEditor : Editor { - List _clips = new List(); + List _clips = new List(); + SwfClipAssetPreview _preview = null; static string GetClipPath(SwfClipAsset clip) { return clip @@ -159,11 +160,31 @@ namespace FTEditor.Editors { void DrawGUINotes() { EditorGUILayout.Separator(); EditorGUILayout.HelpBox( - "Masks and blends of animation may not be displayed correctly in preview window. " + + "Masks and blends of animation may not be displayed correctly in the preview window. " + "Instance animation to the scene, to see how it will look like the animation in the game.", MessageType.Info); } + // + // + // + + void SetupPreviews() { + ShutdownPreviews(); + _preview = new SwfClipAssetPreview(); + _preview.Initialize(targets + .OfType() + .Where(p => p) + .ToArray()); + } + + void ShutdownPreviews() { + if ( _preview != null ) { + _preview.Shutdown(); + _preview = null; + } + } + // --------------------------------------------------------------------- // // Messages @@ -172,6 +193,12 @@ namespace FTEditor.Editors { void OnEnable() { _clips = targets.OfType().ToList(); + SetupPreviews(); + } + + void OnDisable() { + ShutdownPreviews(); + _clips.Clear(); } public override void OnInspectorGUI() { @@ -188,7 +215,23 @@ namespace FTEditor.Editors { } public override bool RequiresConstantRepaint() { - return true; + return _clips.Count > 0; + } + + public override bool HasPreviewGUI() { + return _clips.Count > 0; + } + + public override void OnPreviewSettings() { + if ( _preview != null ) { + _preview.OnPreviewSettings(); + } + } + + public override void OnPreviewGUI(Rect r, GUIStyle background) { + if ( _preview != null ) { + _preview.OnPreviewGUI(r, background); + } } } } \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetPreview.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetPreview.cs index ca8b121..52b9397 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetPreview.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetPreview.cs @@ -6,7 +6,6 @@ using System.Linq; using FTRuntime; namespace FTEditor.Editors { - [CustomPreview(typeof(SwfClipAsset))] class SwfClipAssetPreview : ObjectPreview { int _sequence = 0; MaterialPropertyBlock _matPropBlock = null; @@ -33,15 +32,6 @@ namespace FTEditor.Editors { } } - int targetSequenceCount { - get { - var clip = target as SwfClipAsset; - return clip && clip.Sequences != null - ? clip.Sequences.Count - : 0; - } - } - SwfClipAsset.Frame targetFrame { get { var clip = target as SwfClipAsset; @@ -135,17 +125,17 @@ namespace FTEditor.Editors { // // --------------------------------------------------------------------- - public void SetCurrentSequence(string sequence_name) { + public void SetSequence(string sequence_name) { var clip = target as SwfClipAsset; _sequence = clip && clip.Sequences != null ? Mathf.Max(0, clip.Sequences.FindIndex(p => p.Name == sequence_name)) : 0; } - public void Shutdown() { - _matPropBlock.Clear(); - _previewUtils.Cleanup(); - } + public void Shutdown() { + _matPropBlock.Clear(); + _previewUtils.Cleanup(); + } // --------------------------------------------------------------------- // @@ -168,27 +158,35 @@ namespace FTEditor.Editors { } public override void OnPreviewSettings() { - var any_multi_sequences = m_Targets - .OfType() - .Any(p => p.Sequences != null && p.Sequences.Count > 1); - if ( any_multi_sequences && GUILayout.Button("<", EditorStyles.miniButton) ) { - --_sequence; + var clip = m_Targets.Length == 1 + ? m_Targets[0] as SwfClipAsset + : null; + + if ( !clip || clip.Sequences == null ) { + return; } - var sequence_names = m_Targets - .OfType() - .Select (p => GetSequenceForClip(p, _sequence)) - .Where (p => p != null && !string.IsNullOrEmpty(p.Name)) - .Select (p => p.Name) - .ToArray(); - var label_text = string.Empty; - for ( int i = 0, e = sequence_names.Length; i < e; ++i ) { - label_text += string.Format( - i > 0 ? ", {0}" : "{0}", - sequence_names[i]); + + if ( clip.Sequences.Count > 1 ) { + if ( GUILayout.Button("<", EditorStyles.miniButton) ) { + --_sequence; + if ( _sequence < 0 ) { + _sequence = clip.Sequences.Count - 1; + } + } } - GUILayout.Label(label_text, EditorStyles.whiteLabel); - if ( any_multi_sequences && GUILayout.Button(">", EditorStyles.miniButton) ) { - ++_sequence; + + var sequence = GetSequenceForClip(clip, _sequence); + if ( sequence != null && !string.IsNullOrEmpty(sequence.Name) ) { + GUILayout.Label(sequence.Name, EditorStyles.whiteLabel); + } + + if ( clip.Sequences.Count > 1 ) { + if ( GUILayout.Button(">", EditorStyles.miniButton) ) { + ++_sequence; + if ( _sequence >= clip.Sequences.Count ) { + _sequence = 0; + } + } } } diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs index 4f5c3d1..cc7d4b1 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs @@ -131,37 +131,41 @@ namespace FTEditor.Editors { } void SetupPreviews() { - ShutdownPreviews(); - foreach ( var clip in _clips.Where(p => !!p.clip) ) { - var preview = new SwfClipAssetPreview(); - preview.Initialize(new Object[]{clip.clip}); - _previews.Add(clip, preview); - } + ShutdownPreviews(); + _previews = targets + .OfType() + .Where(p => p.clip) + .ToDictionary(p => p, p => { + var preview = new SwfClipAssetPreview(); + preview.Initialize(new Object[] { p.clip }); + return preview; + }); } - void ShutdownPreviews() { - foreach ( var p in _previews ) { - p.Value.Shutdown(); - } - _previews.Clear(); - } + void ShutdownPreviews() { + foreach ( var p in _previews ) { + p.Value.Shutdown(); + } + _previews.Clear(); + } - // --------------------------------------------------------------------- - // - // Messages - // - // --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // + // Messages + // + // --------------------------------------------------------------------- - void OnEnable() { + void OnEnable() { _clips = targets.OfType().ToList(); SetupPreviews(); } - void OnDisable() { - ShutdownPreviews(); - } + void OnDisable() { + ShutdownPreviews(); + _clips.Clear(); + } - public override void OnInspectorGUI() { + public override void OnInspectorGUI() { serializedObject.Update(); DrawDefaultInspector(); DrawSequence(); @@ -173,11 +177,11 @@ namespace FTEditor.Editors { } public override bool RequiresConstantRepaint() { - return _previews.Count > 0; + return _clips.Count > 0; } public override bool HasPreviewGUI() { - return _previews.Count > 0; + return _clips.Count > 0; } public override void OnPreviewGUI(Rect r, GUIStyle background) { @@ -185,7 +189,7 @@ namespace FTEditor.Editors { SwfClipAssetPreview preview; var clip = target as SwfClip; if ( _previews.TryGetValue(clip, out preview) ) { - preview.SetCurrentSequence(clip.sequence); + preview.SetSequence(clip.sequence); preview.DrawPreview(r); } } diff --git a/ProjectStuff/FlashTools.org b/ProjectStuff/FlashTools.org index 7810b87..6c9f31d 100644 --- a/ProjectStuff/FlashTools.org +++ b/ProjectStuff/FlashTools.org @@ -71,6 +71,8 @@ https://gist.github.com/talecrafter/111ea3345911bd238f4998b4d5a04bf3 UNITY_UV_STARTS_AT_TOP UNITY_HALF_TEXEL_OFFSET ** TODO Версия 1.3.15 +*** Баги +**** DONE Утечка превью в редакторе *** Улучшения **** TODO Выводить в лог успешную конвертацию с контекстом **** TODO Триммить изображения из swf (adou.fla)