diff --git a/Assets/FlashTools/Examples/Scenes/Scene00.unity b/Assets/FlashTools/Examples/Scenes/Scene00.unity index c4e037f..3619cf5 100644 --- a/Assets/FlashTools/Examples/Scenes/Scene00.unity +++ b/Assets/FlashTools/Examples/Scenes/Scene00.unity @@ -145,7 +145,7 @@ Camera: far clip plane: 1000 field of view: 60 orthographic: 1 - orthographic size: 2.37 + orthographic size: 3 m_Depth: 0 m_CullingMask: serializedVersion: 2 diff --git a/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta b/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta index 32b9594..659fed8 100644 --- a/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta +++ b/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: cda4fb87dc8624946bdaed871b60f0b8 -timeCreated: 1471787769 +timeCreated: 1471847086 licenseType: Free NativeFormatImporter: userData: diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs index d0fed91..f267a82 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs @@ -1,29 +1,56 @@ using UnityEngine; -using UnityEngine.Rendering; using UnityEditor; -using System; using System.IO; namespace FlashTools.Internal { [CustomEditor(typeof(SwfAnimationAsset))] public class SwfAnimationAssetEditor : Editor { - SwfAnimationAsset _asset = null; + SwfAnimationAsset _asset = null; + bool _settingsFoldout = false; - void Reconvert() { + void OverriddenSettingsToDefault() { + if ( _asset ) { + _asset.Overridden = SwfConverterSettings.GetDefaultSettings(); + } + } + + void RevertOverriddenSettings() { + if ( _asset ) { + _asset.Overridden = _asset.Settings; + } + } + + void ApplyOverriddenSettings() { + if ( _asset ) { + _asset.Settings = _asset.Overridden; + } + ReconvertAnimation(); + } + + void ReconvertAnimation() { if ( _asset && _asset.Atlas ) { AssetDatabase.DeleteAsset( AssetDatabase.GetAssetPath(_asset.Atlas)); _asset.Atlas = null; } - if ( !_asset.OverrideSettings ) { - _asset.OverriddenSettings = - SwfConverterSettings.LoadOrCreate().DefaultSettings; - } AssetDatabase.ImportAsset( GetSwfPath(), ImportAssetOptions.ForceUpdate); } + void ShowUnappliedDialog() { + var title = + "Unapplied swf animation settings"; + var message = string.Format( + "Unapplied swf animation settings for '{0}'", + GetAssetPath()); + if ( EditorUtility.DisplayDialog(title, message, "Apply", "Revert") ) { + ApplyOverriddenSettings(); + } else { + RevertOverriddenSettings(); + } + } + GameObject CreateAnimationGO() { if ( _asset ) { var anim_go = new GameObject(_asset.name); @@ -37,17 +64,19 @@ namespace FlashTools.Internal { void CreateAnimationPrefab() { var anim_go = CreateAnimationGO(); - var prefab_path = GetPrefabPath(); - if ( anim_go && !string.IsNullOrEmpty(prefab_path) ) { - var prefab = AssetDatabase.LoadMainAssetAtPath(prefab_path); - if ( !prefab ) { - prefab = PrefabUtility.CreateEmptyPrefab(prefab_path); + if ( anim_go ) { + var prefab_path = GetPrefabPath(); + if ( !string.IsNullOrEmpty(prefab_path) ) { + var prefab = AssetDatabase.LoadMainAssetAtPath(prefab_path); + if ( !prefab ) { + prefab = PrefabUtility.CreateEmptyPrefab(prefab_path); + } + PrefabUtility.ReplacePrefab( + anim_go, + prefab, + ReplacePrefabOptions.ConnectToPrefab); } - PrefabUtility.ReplacePrefab( - anim_go, - prefab, - ReplacePrefabOptions.ConnectToPrefab); - Undo.RegisterCreatedObjectUndo(anim_go, "Create SwfAnimation"); + DestroyImmediate(anim_go); } } @@ -78,10 +107,41 @@ namespace FlashTools.Internal { : Path.ChangeExtension(asset_path, ".prefab"); } - void DrawGUIControls() { - if ( GUILayout.Button("Reconvert") ) { - Reconvert(); + void DrawGUISettings() { + GUI.enabled = false; + EditorGUILayout.PropertyField(serializedObject.FindProperty("Atlas")); + GUI.enabled = true; + _settingsFoldout = EditorGUILayout.Foldout(_settingsFoldout, "Settings"); + if ( _settingsFoldout ) { + var it = serializedObject.FindProperty("Overridden"); + while ( it.NextVisible(true) ) { + EditorGUILayout.PropertyField(it); + } + DrawGUISettingsControls(); } + } + + void DrawGUISettingsControls() { + GUILayout.BeginHorizontal(); + { + GUI.enabled = !_asset.Overridden.Equal(SwfConverterSettings.GetDefaultSettings()); + if ( GUILayout.Button("Default") ) { + OverriddenSettingsToDefault(); + } + GUI.enabled = !_asset.Overridden.Equal(_asset.Settings); + if ( GUILayout.Button("Revert") ) { + RevertOverriddenSettings(); + } + GUI.enabled = !_asset.Overridden.Equal(_asset.Settings); + if ( GUILayout.Button("Apply") ) { + ApplyOverriddenSettings(); + } + GUI.enabled = true; + } + GUILayout.EndHorizontal(); + } + + void DrawGUIAnimation() { GUILayout.BeginHorizontal(); { if ( GUILayout.Button("Create animation prefab") ) { @@ -94,24 +154,6 @@ namespace FlashTools.Internal { GUILayout.EndHorizontal(); } - void DrawGUIProperties() { - serializedObject.Update(); - EditorGUILayout.PropertyField(serializedObject.FindProperty("Atlas")); - EditorGUILayout.PropertyField(serializedObject.FindProperty("OverrideSettings")); - if ( _asset.OverrideSettings ) { - EditorGUILayout.PropertyField( - serializedObject.FindProperty("OverriddenSettings"), true); - } else { - GUI.enabled = false; - var so = new SerializedObject(SwfConverterSettings.LoadOrCreate()); - EditorGUILayout.PropertyField(so.FindProperty("DefaultSettings"), true); - GUI.enabled = true; - } - if ( GUI.changed ) { - serializedObject.ApplyModifiedProperties(); - } - } - // ------------------------------------------------------------------------ // // Messages @@ -119,12 +161,23 @@ namespace FlashTools.Internal { // ------------------------------------------------------------------------ void OnEnable() { - _asset = target as SwfAnimationAsset; + _asset = target as SwfAnimationAsset; + _settingsFoldout = _asset && !_asset.Settings.Equal(SwfConverterSettings.GetDefaultSettings()); + } + + void OnDisable() { + if ( _asset && !_asset.Settings.Equal(_asset.Overridden) ) { + ShowUnappliedDialog(); + } } public override void OnInspectorGUI() { - DrawGUIProperties(); - DrawGUIControls(); + serializedObject.Update(); + DrawGUISettings(); + DrawGUIAnimation(); + if ( GUI.changed ) { + serializedObject.ApplyModifiedProperties(); + } } } } \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs index 44680e5..7ca60c5 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs @@ -51,10 +51,10 @@ namespace FlashTools.Internal { .ToArray(); atlas_importer.textureType = TextureImporterType.Sprite; atlas_importer.spriteImportMode = SpriteImportMode.Multiple; - atlas_importer.spritePixelsPerUnit = asset.OverriddenSettings.PixelsPerUnit; - atlas_importer.mipmapEnabled = asset.OverriddenSettings.GenerateMipMaps; - atlas_importer.filterMode = asset.OverriddenSettings.AtlasFilterMode; - atlas_importer.textureFormat = asset.OverriddenSettings.AtlasImporterFormat; + atlas_importer.spritePixelsPerUnit = asset.Settings.PixelsPerUnit; + atlas_importer.mipmapEnabled = asset.Settings.GenerateMipMaps; + atlas_importer.filterMode = asset.Settings.AtlasFilterMode; + atlas_importer.textureFormat = asset.Settings.AtlasImporterFormat; AssetDatabase.ImportAsset( GetAtlasPath(asset_path), ImportAssetOptions.ForceUpdate); diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs index 60bb5d4..f51130c 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs @@ -187,8 +187,8 @@ namespace FlashTools.Internal { var atlas = new Texture2D(0, 0, TextureFormat.ARGB32, false); var atlas_rects = atlas.PackTextures( textures, - asset.OverriddenSettings.AtlasPadding, - asset.OverriddenSettings.MaxAtlasSize); + asset.Settings.AtlasPadding, + asset.Settings.MaxAtlasSize); File.WriteAllBytes( GetAtlasPath(swf_asset), diff --git a/Assets/FlashTools/Scripts/SwfAnimation.cs b/Assets/FlashTools/Scripts/SwfAnimation.cs index 78d28dc..bb668a1 100644 --- a/Assets/FlashTools/Scripts/SwfAnimation.cs +++ b/Assets/FlashTools/Scripts/SwfAnimation.cs @@ -110,9 +110,9 @@ namespace FlashTools { var matrix = Matrix4x4.Scale(new Vector3( - 1.0f / Asset.OverriddenSettings.PixelsPerUnit, - -1.0f / Asset.OverriddenSettings.PixelsPerUnit, - 1.0f / Asset.OverriddenSettings.PixelsPerUnit)) * inst.Matrix; + 1.0f / Asset.Settings.PixelsPerUnit, + -1.0f / Asset.Settings.PixelsPerUnit, + 1.0f / Asset.Settings.PixelsPerUnit)) * inst.Matrix; _vertices.Add(matrix.MultiplyPoint3x4(v0)); _vertices.Add(matrix.MultiplyPoint3x4(v1)); diff --git a/Assets/FlashTools/Scripts/SwfAnimationAsset.cs b/Assets/FlashTools/Scripts/SwfAnimationAsset.cs index 718488a..8dc7d69 100644 --- a/Assets/FlashTools/Scripts/SwfAnimationAsset.cs +++ b/Assets/FlashTools/Scripts/SwfAnimationAsset.cs @@ -41,45 +41,45 @@ namespace FlashTools { [System.Serializable] public class SwfAnimationInstanceData { - public SwfAnimationInstanceType Type = SwfAnimationInstanceType.Group; - public ushort ClipDepth = 0; - public ushort Bitmap = 0; - public Matrix4x4 Matrix = Matrix4x4.identity; - public SwfAnimationColorTransform ColorTransform = SwfAnimationColorTransform.identity; + public SwfAnimationInstanceType Type = SwfAnimationInstanceType.Group; + public ushort ClipDepth = 0; + public ushort Bitmap = 0; + public Matrix4x4 Matrix = Matrix4x4.identity; + public SwfAnimationColorTransform ColorTransform = SwfAnimationColorTransform.identity; } [System.Serializable] public class SwfAnimationFrameData { - public string Name = string.Empty; - public List Instances = new List(); + public string Name = string.Empty; + public List Instances = new List(); } [System.Serializable] public class SwfAnimationBitmapData { - public int Id = 0; - public Vector2 RealSize = Vector2.zero; - public Rect SourceRect = new Rect(); + public int Id = 0; + public Vector2 RealSize = Vector2.zero; + public Rect SourceRect = new Rect(); } [System.Serializable] public class SwfAnimationData { - public float FrameRate = 0.0f; - public List Frames = new List(); - public List Bitmaps = new List(); + public float FrameRate = 0.0f; + public List Frames = new List(); + public List Bitmaps = new List(); } public class SwfAnimationAsset : ScriptableObject { - public SwfAnimationData Data = new SwfAnimationData(); - public Texture2D Atlas = null; - public bool OverrideSettings = false; - public SwfConverterSettings.Settings OverriddenSettings = new SwfConverterSettings.Settings(); + public SwfAnimationData Data; + public Texture2D Atlas; + public SwfConverterSettings.Settings Settings; + public SwfConverterSettings.Settings Overridden; #if UNITY_EDITOR void Reset() { - Data = new SwfAnimationData(); - Atlas = null; - OverrideSettings = false; - OverriddenSettings = SwfConverterSettings.LoadOrCreate().DefaultSettings; + Data = new SwfAnimationData(); + Atlas = null; + Settings = SwfConverterSettings.GetDefaultSettings(); + Overridden = SwfConverterSettings.GetDefaultSettings(); } #endif } diff --git a/Assets/FlashTools/Scripts/SwfConverterSettings.cs b/Assets/FlashTools/Scripts/SwfConverterSettings.cs index 35c77e9..1d7c53f 100644 --- a/Assets/FlashTools/Scripts/SwfConverterSettings.cs +++ b/Assets/FlashTools/Scripts/SwfConverterSettings.cs @@ -17,24 +17,38 @@ namespace FlashTools { public FilterMode AtlasFilterMode; public TextureImporterFormat AtlasImporterFormat; - public void Reset() { - MaxAtlasSize = 1024; - AtlasPadding = 1; - PixelsPerUnit = 100; - AtlasPowerOfTwo = false; - GenerateMipMaps = true; - AtlasFilterMode = FilterMode.Bilinear; - AtlasImporterFormat = TextureImporterFormat.AutomaticTruecolor; + public bool Equal(Settings other) { + return + MaxAtlasSize == other.MaxAtlasSize && + AtlasPadding == other.AtlasPadding && + PixelsPerUnit == other.PixelsPerUnit && + AtlasPowerOfTwo == other.AtlasPowerOfTwo && + GenerateMipMaps == other.GenerateMipMaps && + AtlasFilterMode == other.AtlasFilterMode && + AtlasImporterFormat == other.AtlasImporterFormat; + } + + public static Settings identity { + get { + return new Settings{ + MaxAtlasSize = 1024, + AtlasPadding = 1, + PixelsPerUnit = 100, + AtlasPowerOfTwo = false, + GenerateMipMaps = true, + AtlasFilterMode = FilterMode.Bilinear, + AtlasImporterFormat = TextureImporterFormat.AutomaticTruecolor}; + } } } public Settings DefaultSettings; #if UNITY_EDITOR void Reset() { - DefaultSettings.Reset(); + DefaultSettings = Settings.identity; } - public static SwfConverterSettings LoadOrCreate() { + public static SwfConverterSettings.Settings GetDefaultSettings() { var settings_path = GetSettingsPath(); var settings = AssetDatabase.LoadAssetAtPath(settings_path); if ( !settings ) { @@ -43,7 +57,7 @@ namespace FlashTools { AssetDatabase.CreateAsset(settings, settings_path); AssetDatabase.SaveAssets(); } - return settings; + return settings.DefaultSettings; } static void CreateAssetDatabaseFolders(string path) { diff --git a/unityflash.userprefs b/unityflash.userprefs index 6113abf..811db81 100644 --- a/unityflash.userprefs +++ b/unityflash.userprefs @@ -1,8 +1,9 @@  - + - + +