diff --git a/Assets/FlashTools/Examples/Animations/Tests.meta b/Assets/FlashTools/Examples/Animations/Tests.meta new file mode 100644 index 0000000..39e21e3 --- /dev/null +++ b/Assets/FlashTools/Examples/Animations/Tests.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8fab275383abb42759b0d204d3c0a1bd +folderAsset: yes +timeCreated: 1456856160 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Examples/Animations/Tests/0_keyframes.fla b/Assets/FlashTools/Examples/Animations/Tests/0_keyframes.fla new file mode 100644 index 0000000..c8a3ea3 Binary files /dev/null and b/Assets/FlashTools/Examples/Animations/Tests/0_keyframes.fla differ diff --git a/Assets/FlashTools/Examples/Animations/Tests/0_keyframes.fla.meta b/Assets/FlashTools/Examples/Animations/Tests/0_keyframes.fla.meta new file mode 100644 index 0000000..755ddc8 --- /dev/null +++ b/Assets/FlashTools/Examples/Animations/Tests/0_keyframes.fla.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d6d16b21e25284375a23eb3459645da6 +timeCreated: 1456856160 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Examples/Animations/anim01.fla b/Assets/FlashTools/Examples/Animations/anim01.fla index b0e366c..fd82b53 100644 Binary files a/Assets/FlashTools/Examples/Animations/anim01.fla and b/Assets/FlashTools/Examples/Animations/anim01.fla differ diff --git a/Assets/FlashTools/Scripts/FlashAnim.cs b/Assets/FlashTools/Scripts/FlashAnim.cs index 5c34fa7..18aaab4 100644 --- a/Assets/FlashTools/Scripts/FlashAnim.cs +++ b/Assets/FlashTools/Scripts/FlashAnim.cs @@ -1,15 +1,20 @@ using UnityEngine; using System.Collections.Generic; +#if UNITY_EDITOR +using UnityEditor; +#endif + namespace FlashTools { [ExecuteInEditMode] [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class FlashAnim : MonoBehaviour { public FlashAnimAsset Asset = null; - int _current_frame = 0; - float _frame_timer = 0.0f; - float _current_z = 0.0f; + int _current_frame = 0; + int _current_symbol = -1; + float _frame_timer = 0.0f; + float _current_z = 0.0f; List _uvs = new List(); List _vertices = new List(); @@ -27,6 +32,20 @@ namespace FlashTools { public void GoToFrame(int frame) { } + public int currentFrame { + get { return _current_frame; } + set { + _current_frame = Mathf.Clamp(value, 0, frameCount - 1); + } + } + + public int currentSymbol { + get { return _current_symbol; } + set { + _current_symbol = value; + } + } + public int frameCount { get { int frames = 0; @@ -42,8 +61,11 @@ namespace FlashTools { } FlashAnimSymbolData GetCurrentSymbol() { - //return Asset.Data.Library.Symbols[0]; - return Asset.Data.Stage; + if ( currentSymbol >= 0 && currentSymbol < Asset.Data.Library.Symbols.Count ) { + return Asset.Data.Library.Symbols[currentSymbol]; + } else { + return Asset.Data.Stage; + } } int GetNumFrameByNum(FlashAnimLayerData layer, int num) { @@ -120,14 +142,19 @@ namespace FlashTools { void RenderSymbol(FlashAnimSymbolData symbol, int frame_num, Matrix4x4 matix) { for ( var i = 0; i < symbol.Layers.Count; ++i ) { var layer = symbol.Layers[i]; - if ( layer.LayerType != FlashAnimLayerType.Mask ) { + if ( layer.LayerType != FlashAnimLayerType.Guide && + layer.LayerType != FlashAnimLayerType.Mask && + layer.LayerType != FlashAnimLayerType.Folder ) + { var frame = GetFrameByNum(layer, frame_num); if ( frame != null ) { for ( var j = 0; j < frame.Elems.Count; ++j ) { var elem = frame.Elems[j]; if ( elem.Instance != null ) { RenderInstance( - elem.Instance, frame_num, matix * elem.Matrix); + elem.Instance, + elem.Instance.FirstFrame, + matix * elem.Matrix); } } } @@ -135,6 +162,12 @@ namespace FlashTools { } } + void MartDirtySelf() { + #if UNITY_EDITOR + EditorUtility.SetDirty(this); + #endif + } + // ------------------------------------------------------------------------ // // Messages diff --git a/Assets/FlashTools/Scripts/FlashAnimAsset.cs b/Assets/FlashTools/Scripts/FlashAnimAsset.cs index 396a908..c24f1ea 100644 --- a/Assets/FlashTools/Scripts/FlashAnimAsset.cs +++ b/Assets/FlashTools/Scripts/FlashAnimAsset.cs @@ -19,6 +19,12 @@ namespace FlashTools { Erase } + public enum FlashAnimLoopingMode { + Loop, + PlayOnce, + SingleFrame + } + public enum FlashAnimLayerType { Normal, Guide, @@ -28,22 +34,11 @@ namespace FlashTools { Folder } - public enum FlashAnimLoopingType { - Loop, - PlayOnce, - SingleFrame - } - public enum FlashAnimInstType { Bitmap, Symbol } - public enum FlashAnimInstSymbolType { - Graphic, - MovieClip - } - [System.Serializable] public class FlashAnimBitmapData { public string Id = string.Empty; @@ -59,13 +54,12 @@ namespace FlashTools { [System.Serializable] public class FlashAnimInstData { - public FlashAnimInstType Type = FlashAnimInstType.Bitmap; - public FlashAnimInstSymbolType SymbolType = FlashAnimInstSymbolType.Graphic; - public FlashAnimBlendMode BlendMode = FlashAnimBlendMode.Normal; - public string Asset = string.Empty; - public bool Visible = true; - public FlashAnimLoopingType LoopingType = FlashAnimLoopingType.SingleFrame; - public int LoopingFirstFrame = 0; + public FlashAnimInstType Type = FlashAnimInstType.Bitmap; + public FlashAnimBlendMode BlendMode = FlashAnimBlendMode.Normal; + public string Asset = string.Empty; + public bool Visible = true; + public int FirstFrame = 0; + public FlashAnimLoopingMode LoopingMode = FlashAnimLoopingMode.SingleFrame; } [System.Serializable] @@ -108,7 +102,7 @@ namespace FlashTools { } public class FlashAnimAsset : ScriptableObject { - //[HideInInspector] + [HideInInspector] public FlashAnimData Data = new FlashAnimData(); public Texture2D Atlas = null; public int MaxAtlasSize = 1024; diff --git a/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimEditor.cs index a0dfcdc..8a9e796 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimEditor.cs @@ -1,10 +1,11 @@ using UnityEngine; using UnityEditor; +using System.Linq; namespace FlashTools.Internal { [CustomEditor(typeof(FlashAnim))] public class FlashAnimEditor : Editor { - //FlashAnim _anim = null; + FlashAnim _anim = null; // ------------------------------------------------------------------------ // @@ -13,11 +14,27 @@ namespace FlashTools.Internal { // ------------------------------------------------------------------------ void OnEnable() { - //_anim = target as FlashAnim; + _anim = target as FlashAnim; } public override void OnInspectorGUI() { DrawDefaultInspector(); + if ( _anim.Asset ) { + var new_current_frame = EditorGUILayout.IntSlider( + "Frame", + _anim.currentFrame, 0, _anim.frameCount - 1); + if ( new_current_frame != _anim.currentFrame ) { + _anim.currentFrame = new_current_frame; + } + + var symbols = _anim.Asset.Data.Library.Symbols.Select(p => p.Id).ToArray(); + var new_current_symbol = EditorGUILayout.Popup( + "Symbol", + _anim.currentSymbol, symbols); + if ( new_current_symbol != _anim.currentSymbol ) { + _anim.currentSymbol = new_current_symbol; + } + } } } } \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimFtaPostprocessor.cs b/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimFtaPostprocessor.cs index afdb38c..d6460c4 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimFtaPostprocessor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/FlashAnimFtaPostprocessor.cs @@ -116,18 +116,14 @@ namespace FlashTools.Internal { } static void LoadFlashAnimInstFromFtaElemElem(XElement elem_elem, FlashAnimElemData data) { - var inst_elem = elem_elem.Element("instance"); - var instance = new FlashAnimInstData(); - instance.Type = SafeLoadEnumFromElemAttr(inst_elem, "type" , instance.Type); - instance.SymbolType = SafeLoadEnumFromElemAttr(inst_elem, "symbol_type", instance.SymbolType); - instance.BlendMode = SafeLoadEnumFromElemAttr(inst_elem, "blend_mode" , instance.BlendMode); - instance.Asset = SafeLoadStrFromElemAttr (inst_elem, "asset" , instance.Asset); - instance.Visible = SafeLoadBoolFromElemAttr(inst_elem, "visible" , instance.Visible); - var looping_elem = inst_elem.Element("looping"); - if ( looping_elem != null ) { - instance.LoopingType = SafeLoadEnumFromElemAttr(looping_elem, "type" , instance.LoopingType); - instance.LoopingFirstFrame = SafeLoadIntFromElemAttr (looping_elem, "first_frame", instance.LoopingFirstFrame); - } + var inst_elem = elem_elem.Element("instance"); + var instance = new FlashAnimInstData(); + instance.Type = SafeLoadEnumFromElemAttr(inst_elem, "type" , instance.Type); + instance.BlendMode = SafeLoadEnumFromElemAttr(inst_elem, "blend_mode" , instance.BlendMode); + instance.Asset = SafeLoadStrFromElemAttr (inst_elem, "asset" , instance.Asset); + instance.Visible = SafeLoadBoolFromElemAttr(inst_elem, "visible" , instance.Visible); + instance.FirstFrame = SafeLoadIntFromElemAttr (inst_elem, "first_frame" , instance.FirstFrame); + instance.LoopingMode = SafeLoadEnumFromElemAttr(inst_elem, "looping_mode", instance.LoopingMode); data.Instance = instance; } diff --git a/Tools/FlashExport.jsfl b/Tools/FlashExport.jsfl deleted file mode 100644 index aea60b1..0000000 --- a/Tools/FlashExport.jsfl +++ /dev/null @@ -1,339 +0,0 @@ - -var g_export_path = ""; -var g_library_path = ""; -var g_current_doc = null; -fl.showIdleMessage(false); -Main(); - -function Main() -{ - var documents = fl.documents; - if ( documents && documents.length ) - { - fl.saveAll(); - fl.outputPanel.clear(); - - for ( var i = 0; i < documents.length; ++i ) - { - g_current_doc = documents[i]; - ExportDocument(); - fl.closeDocument(g_current_doc, false); - }; - - alert("-= Process Complete =-"); - } -} - -function ExportDocument() -{ - var document_path = g_current_doc.path; - var last_slash = document_path.lastIndexOf("/"); - var last_dot = document_path.lastIndexOf("."); - - // g_export_path - var export_folder = document_path.substr(0, last_slash) + "/../" + document_path.substr(last_slash, last_dot-last_slash) + "_export/"; - g_export_path = FLfile.platformPathToURI(export_folder); - - // g_library_path - var library_folder = document_path.substr(0, last_slash) + "/LIBRARY/"; - g_library_path = FLfile.platformPathToURI(library_folder); - - // create export folder - FLfile.remove(g_export_path); - FLfile.createFolder(g_export_path); - - // run - ExportLibrary(g_export_path + "Library.xml"); -} - -function PrintNormal( text ) -{ - fl.outputPanel.trace(text); -} - -function PrintWarning( text ) -{ - fl.outputPanel.trace("-= PROCESS WARNING =-\n -- " + text); -} - -function ToRad( deg ) -{ - return deg * Math.PI / 180; -} - -function ExitEditMode() -{ - for ( var i = 0; i < 100; ++i ) - g_current_doc.exitEditMode(); -} - -function ExportLibrary( file ) -{ - ExitEditMode(); - - var doc = g_current_doc; - var library = doc.library; - var temp_layer = doc.getTimeline().addNewLayer("bme_temp_export_layer"); - var file_str = "\n" - - for ( var i = 0; i < library.items.length; ++i ) - { - var item = library.items[i]; - - if ( item.itemType == "folder" ) - { - // create folder - var path = g_export_path + item.name; - FLfile.createFolder(path); - } - else - { - if ( item.itemType == "bitmap" ) - { - file_str += - "\t\n"; - - // copy bitmap to export - FLfile.copy(g_library_path + item.name, g_export_path + item.name); - } - else if ( item.itemType == "movie clip" || item.itemType == "graphic" || item.itemType == "component" ) - { - file_str += - "\t 0 ) - { - var sel = doc.selection[0]; - if ( sel.parameters && sel.parameters.length > 0 ) - { - is_parameters = true; - file_str += ">\n"; - file_str = ExportParameters(sel.parameters, file_str, "\t\t"); - } - } - - if ( is_parameters ) - file_str += "\t\n"; - else - file_str += "/>\n"; - - // export item timeline - - library.editItem(item.name); - ExportTimeline(g_export_path + item.name + ".xml") - ExitEditMode(); - } - else - { - PrintWarning("Unsupported library type(" + item.itemType + ")"); - } - } - } - - FLfile.write(file, file_str + "", "append"); - doc.getTimeline().deleteLayer(); -} - -function ExportTimeline( file ) -{ - var doc_timeline = g_current_doc.getTimeline(); - - // [2:-] for disable dublicate single frame - if ( doc_timeline.frameCount > 1 ) - { - doc_timeline.selectAllFrames(); - doc_timeline.convertToKeyframes(); - } - - var doc_frames = doc_timeline.frameCount; - var doc_framerate = g_current_doc.frameRate; - - var file_str = "= 0; --i ) - { - var doc_layer = doc_timeline.layers[i]; - if ( !doc_layer || !doc_layer.visible ) - continue; - - file_str = ExportLayer(doc_layer, i, file_str, "\t") - } - - FLfile.write(file, file_str + "", "append" ); -} - -function ExportLayer( layer, index, file_str, prefix ) -{ - file_str += prefix + "\n"; - - for ( var i = 0; i < layer.frameCount; ++i ) - { - var frame = layer.frames[i]; - if ( !frame || i != frame.startFrame ) - continue; - - file_str = ExportFrame(frame, i, file_str, prefix + "\t"); - } - - return file_str + prefix + "\n"; -} - -function ExportFrame( frame, index, file_str, prefix ) -{ - file_str += prefix + "\n"; -} - -function ExportElement( element, index, file_str, prefix ) -{ - file_str += prefix + "\n"; -} - -function ExportInstance( instance, file_str, prefix ) -{ - // -------------------------------- - // parameters - // -------------------------------- - - if ( instance.parameters && instance.parameters.length > 0 ) - { - file_str = ExportParameters(instance.parameters, file_str, prefix); - } - - // -------------------------------- - // transform - // -------------------------------- - - file_str += prefix + " 0.01 ) - PrintWarning("Skew transformation unsupported! Element type(" + instance.libraryItem.name + ")"); - - var rotation = "'" + ToRad(instance.skewX) + "'"; - file_str += " rotation=" + rotation; - } - else - { - var rotation = "'" + ToRad(instance.rotation) + "'"; - file_str += " rotation=" + rotation; - } - - // -------------------------------- - // color - // -------------------------------- - - if ( instance.colorAlphaPercent ) - { - var alpha = "'" + instance.colorAlphaPercent / 100 + "'"; - file_str += " alpha=" + alpha; - } - - // -------------------------------- - // blend - // -------------------------------- - - if ( instance.blendMode ) - { - var blend = "'ALPHA'"; - if ( instance.blendMode == "normal" ) blend = "'ALPHA'"; - else if ( instance.blendMode == "add" ) blend = "'ADD'"; - else if ( instance.blendMode == "multiply" ) blend = "'MULTIPLY'"; - else PrintWarning("Unsupported blend mode(" + instance.blendMode + ")"); - - file_str += " blend=" + blend; - } - - return file_str + "/>\n"; -} - -function ExportParameters( params, file_str, prefix ) -{ - file_str += prefix + "\n"; - - for ( var i = 0; i < params.length; ++i ) - { - var param = params[i]; - - if ( param.valueType == "Number" || param.valueType == "Boolean" || param.valueType == "String" ) - { - var name = "'" + param.name + "'"; - var value = "'" + param.value + "'"; - var type = "'" + param.valueType + "'"; - - if ( param.valueType == "Number" ) - value = value.replace(",", "."); - - file_str += prefix + "\t\n"; -} diff --git a/Tools/FlashExport2.jsfl b/Tools/FlashExport2.jsfl index 4e3d846..d6931f3 100644 --- a/Tools/FlashExport2.jsfl +++ b/Tools/FlashExport2.jsfl @@ -828,33 +828,21 @@ if (typeof Object.create != 'function') { SymbolInst.prototype = Object.create(ElementInst.prototype); - SymbolInst.prototype.get_symbol_type = function () { - var symbol_type = this.inst.symbolType; - if ( symbol_type == "movie clip" ) { - return "movieclip"; - } else if ( symbol_type == "graphic" ) { - return "graphic"; - } else { - throw "Unsupported symbol type ({0})!" - .format(symbol_type); - } - }; - - SymbolInst.prototype.get_looping_type = function () { + SymbolInst.prototype.get_looping_mode = function () { var looping_type = this.inst.loop !== undefined ? this.inst.loop : "single frame"; if ( looping_type == "loop" ) { return "loop"; } else if ( looping_type == "play once" ) { return "playonce"; } else if ( looping_type == "single frame" ) { - return "single frame"; + return "singleframe"; } else { throw "Unsupported looping type ({0})!" .format(looping_type); } }; - SymbolInst.prototype.get_looping_first_frame = function () { + SymbolInst.prototype.get_first_frame = function () { return this.inst.firstFrame !== undefined ? this.inst.firstFrame : 0; }; @@ -862,14 +850,12 @@ if (typeof Object.create != 'function') { ft.type_assert(xml_node, XmlNode); var instance_node = ElementInst.prototype.export_description.call(this, xml_node) .child("instance") - .attr("type" , "symbol") - .attr("symbol_type", this.get_symbol_type()) - .attr("asset" , this.uniqueIds.get_string_id(this.inst.libraryItem.name)) - .attr("visible" , this.inst.visible) - .attr("blend_mode" , this.inst.blendMode); - instance_node.child("looping") - .attr("type" , this.get_looping_type()) - .attr("first_frame", this.get_looping_first_frame()); + .attr("type" , "symbol") + .attr("asset" , this.uniqueIds.get_string_id(this.inst.libraryItem.name)) + .attr("visible" , this.inst.visible) + .attr("blend_mode" , this.inst.blendMode) + .attr("first_frame" , this.get_first_frame()) + .attr("looping_mode", this.get_looping_mode()); /* \TODO export color mode if (this.inst.colorMode !== "none") {