From 2161b3843215021e9b9abfa5999438a8f6427762 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 22 Mar 2019 13:52:30 +0700 Subject: [PATCH] Add warning notes about outdated assets --- Assets/FlashTools/Docs/CHANGELOG.md | 1 + .../Editor/FTEditor/Editors/SwfAssetEditor.cs | 11 +- .../FTEditor/Editors/SwfClipAssetEditor.cs | 15 +-- .../Editor/FTEditor/Editors/SwfClipEditor.cs | 9 ++ .../Scripts/Editor/FTEditor/SwfEditorUtils.cs | 119 ++++++++++++++++++ ProjectStuff/FlashTools.org | 2 +- 6 files changed, 148 insertions(+), 9 deletions(-) diff --git a/Assets/FlashTools/Docs/CHANGELOG.md b/Assets/FlashTools/Docs/CHANGELOG.md index b4af9dc..895295d 100644 --- a/Assets/FlashTools/Docs/CHANGELOG.md +++ b/Assets/FlashTools/Docs/CHANGELOG.md @@ -1,6 +1,7 @@ ###### Version 1.3.15 * Add bitmap trimming * Fix preview leaks in the Editor mode +* Add warning notes about outdated assets ###### Version 1.3.14 * Fix 2018.3.2f1 compilation diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfAssetEditor.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfAssetEditor.cs index 6a1194f..37f0a61 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfAssetEditor.cs @@ -10,7 +10,8 @@ using FTRuntime; namespace FTEditor.Editors { [CustomEditor(typeof(SwfAsset)), CanEditMultipleObjects] class SwfAssetEditor : Editor { - List _assets = new List(); + bool _outdated = false; + List _assets = new List(); // // @@ -129,6 +130,12 @@ namespace FTEditor.Editors { } } + void DrawGUINotes() { + if ( _outdated ) { + SwfEditorUtils.DrawOutdatedGUINotes("SwfAsset", _assets); + } + } + // --------------------------------------------------------------------- // // Messages @@ -137,6 +144,7 @@ namespace FTEditor.Editors { void OnEnable() { _assets = targets.OfType().ToList(); + _outdated = SwfEditorUtils.CheckForOutdatedAsset(_assets); } void OnDisable() { @@ -147,6 +155,7 @@ namespace FTEditor.Editors { serializedObject.Update(); DrawDefaultInspector(); DrawGUISettingsControls(); + DrawGUINotes(); if ( GUI.changed ) { serializedObject.ApplyModifiedProperties(); } diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs index 624e8bc..cf36777 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs @@ -11,8 +11,9 @@ using FTRuntime; namespace FTEditor.Editors { [CustomEditor(typeof(SwfClipAsset)), CanEditMultipleObjects] class SwfClipAssetEditor : Editor { - List _clips = new List(); - SwfClipAssetPreview _preview = null; + bool _outdated = false; + List _clips = new List(); + SwfClipAssetPreview _preview = null; static string GetClipPath(SwfClipAsset clip) { return clip @@ -158,11 +159,10 @@ namespace FTEditor.Editors { } void DrawGUINotes() { - EditorGUILayout.Separator(); - EditorGUILayout.HelpBox( - "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); + SwfEditorUtils.DrawMasksGUINotes(); + if ( _outdated ) { + SwfEditorUtils.DrawOutdatedGUINotes("SwfClipAsset", _clips); + } } // @@ -193,6 +193,7 @@ namespace FTEditor.Editors { void OnEnable() { _clips = targets.OfType().ToList(); + _outdated = SwfEditorUtils.CheckForOutdatedAsset(_clips); SetupPreviews(); } diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs index cc7d4b1..eb405ca 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipEditor.cs @@ -9,6 +9,7 @@ using FTRuntime; namespace FTEditor.Editors { [CustomEditor(typeof(SwfClip)), CanEditMultipleObjects] class SwfClipEditor : Editor { + bool _outdated = false; List _clips = new List(); Dictionary _previews = new Dictionary(); @@ -71,6 +72,12 @@ namespace FTEditor.Editors { return result; } + void DrawGUINotes() { + if ( _outdated ) { + SwfEditorUtils.DrawOutdatedGUINotes("SwfClip", _clips); + } + } + void DrawSequence() { var all_sequences = GetAllSequences(true); if ( all_sequences.Count > 0 ) { @@ -157,6 +164,7 @@ namespace FTEditor.Editors { void OnEnable() { _clips = targets.OfType().ToList(); + _outdated = SwfEditorUtils.CheckForOutdatedAsset(_clips); SetupPreviews(); } @@ -167,6 +175,7 @@ namespace FTEditor.Editors { public override void OnInspectorGUI() { serializedObject.Update(); + DrawGUINotes(); DrawDefaultInspector(); DrawSequence(); DrawCurrentFrame(); diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/SwfEditorUtils.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/SwfEditorUtils.cs index 99c3aa9..e181fbf 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/SwfEditorUtils.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/SwfEditorUtils.cs @@ -3,6 +3,7 @@ using UnityEditor; using System.IO; using System.Linq; +using System.Collections.Generic; using System.Security.Cryptography; using System.Runtime.Serialization.Formatters.Binary; @@ -307,6 +308,13 @@ namespace FTEditor { GetFileHash(path), SwfVersion.AsString); } + static string GetVersionFromFileHashWithVersion(string hash) { + var index = hash.LastIndexOf('='); + return index != -1 + ? hash.Substring(index + 1) + : string.Empty; + } + static string GetFileHash(string path) { try { using ( var sha256 = SHA256.Create() ) { @@ -321,6 +329,117 @@ namespace FTEditor { } } + // --------------------------------------------------------------------- + // + // Outdated assets + // + // --------------------------------------------------------------------- + + public static bool CheckForOutdatedAsset(SwfClip clip) { + return clip + && CheckForOutdatedAsset(clip.clip); + } + + public static bool CheckForOutdatedAsset(SwfClipAsset clip_asset) { + return clip_asset + && CheckForOutdatedAsset(AssetDatabase.LoadAssetAtPath( + AssetDatabase.GUIDToAssetPath(clip_asset.AssetGUID))); + } + + public static bool CheckForOutdatedAsset(SwfAsset asset) { + return asset + && GetVersionFromFileHashWithVersion(asset.Hash) != SwfVersion.AsString; + } + + public static bool CheckForOutdatedAsset(IEnumerable clips) { + var iter = clips.GetEnumerator(); + while ( iter.MoveNext() ) { + if ( CheckForOutdatedAsset(iter.Current) ) { + return true; + } + } + return false; + } + + public static bool CheckForOutdatedAsset(IEnumerable clip_assets) { + var iter = clip_assets.GetEnumerator(); + while ( iter.MoveNext() ) { + if ( CheckForOutdatedAsset(iter.Current) ) { + return true; + } + } + return false; + } + + public static bool CheckForOutdatedAsset(IEnumerable assets) { + var iter = assets.GetEnumerator(); + while ( iter.MoveNext() ) { + if ( CheckForOutdatedAsset(iter.Current) ) { + return true; + } + } + return false; + } + + // --------------------------------------------------------------------- + // + // GUI notes + // + // --------------------------------------------------------------------- + + public static void DrawMasksGUINotes() { + EditorGUILayout.Separator(); + EditorGUILayout.HelpBox( + "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); + } + + public static void DrawOutdatedGUINotes(string target, IEnumerable clips) { + DrawOutdatedGUINotes(target, clips + .Select(p => p ? p.clip : null)); + } + + public static void DrawOutdatedGUINotes(string target, IEnumerable clips) { + DrawOutdatedGUINotes(target, clips + .Select(p => { + return p + ? AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(p.AssetGUID)) + : null; + })); + } + + public static void DrawOutdatedGUINotes(string target, IEnumerable assets) { + var asset_count = assets.Count(p => p); + if ( asset_count == 1 ) { + var asset = assets.FirstOrDefault(p => p); + if ( asset ) { + var asset_version = GetVersionFromFileHashWithVersion(asset.Hash); + if ( asset_version != SwfVersion.AsString ) { + EditorGUILayout.Separator(); + EditorGUILayout.HelpBox(string.Format( + "The {0} was created in the {1} version of Flash Animation Toolset, and it's outdated.\n" + + "Please, reimport the source .swf file. It's may be essential to correctness working.\n" + + "You can do it in Tools/FlashTools menu.", + target, asset_version), + MessageType.Error); + } + } + } else if ( asset_count > 1 ) { + var any_outdated = assets + .Any(p => GetVersionFromFileHashWithVersion(p.Hash) != SwfVersion.AsString); + if ( any_outdated ) { + EditorGUILayout.Separator(); + EditorGUILayout.HelpBox(string.Format( + "Some {0} is outdated.\n" + + "Please, reimport the source .swf files. It's may be essential to correctness working.\n" + + "You can do it in Tools/FlashTools menu.", + target), + MessageType.Error); + } + } + } + // --------------------------------------------------------------------- // // Menu diff --git a/ProjectStuff/FlashTools.org b/ProjectStuff/FlashTools.org index 1161b49..2b6a02f 100644 --- a/ProjectStuff/FlashTools.org +++ b/ProjectStuff/FlashTools.org @@ -75,7 +75,7 @@ UNITY_HALF_TEXEL_OFFSET **** DONE Утечка превью в редакторе *** Улучшения **** TODO Выводить в лог успешную конвертацию с контекстом -**** TODO Добавить версию в SwfAsset +**** DONE Предупреждения о устаревших ассетах **** TODO Опциональный тримминг **** DONE Триммить изображения из swf (adou.fla) ** DONE Версия 1.3.14