示例#1
0
 void DrawGUINotes()
 {
     if (_outdated)
     {
         SwfEditorUtils.DrawOutdatedGUINotes("SwfAsset", _assets);
     }
 }
示例#2
0
 void DrawGUINotes()
 {
     if (_outdated)
     {
         SwfEditorUtils.DrawOutdatedGUINotes("SwfClip", _clips);
     }
 }
 static void SwfAssetProcess(SwfAsset asset)
 {
     try {
         EditorUtility.SetDirty(asset);
         var asset_data = SwfEditorUtils.DecompressAsset <SwfAssetData>(asset.Data, progress => {
             _progressBar.UpdateProgress("decompress swf asset", progress);
         });
         asset.Atlas = LoadAssetAtlas(asset);
         if (asset.Atlas)
         {
             ConfigureAtlas(asset);
             ConfigureClips(asset, asset_data);
         }
         else
         {
             _progressBar.UpdateTitle(asset.name);
             var new_data = ConfigureBitmaps(asset, asset_data);
             asset.Data = SwfEditorUtils.CompressAsset(new_data, progress => {
                 _progressBar.UpdateProgress("compress swf asset", progress);
             });
         }
     } catch (Exception e) {
         Debug.LogErrorFormat(
             asset,
             "<b>[FlashTools]</b> Postprocess swf asset error: {0}\nPath: {1}",
             e.Message, AssetDatabase.GetAssetPath(asset));
         AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(asset));
     } finally {
         if (asset)
         {
             UpdateAssetClips(asset);
         }
         _progressBar.HideProgress();
     }
 }
示例#4
0
        void DrawSequence()
        {
            var all_sequences = GetAllSequences(true);

            if (all_sequences.Count > 0)
            {
                var sequence_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "_sequence");
                SwfEditorUtils.DoWithMixedValue(
                    sequence_prop.hasMultipleDifferentValues, () => {
                    var sequence_index = EditorGUILayout.Popup(
                        "Sequence",
                        sequence_prop.hasMultipleDifferentValues
                                                                ? all_sequences.FindIndex(p => string.IsNullOrEmpty(p))
                                                                : all_sequences.FindIndex(p => p == sequence_prop.stringValue),
                        all_sequences.ToArray());
                    if (sequence_index >= 0 && sequence_index < all_sequences.Count)
                    {
                        var new_sequence = all_sequences[sequence_index];
                        if (!string.IsNullOrEmpty(new_sequence))
                        {
                            if (sequence_prop.hasMultipleDifferentValues)
                            {
                                sequence_prop.stringValue = string.Empty;
                            }
                            sequence_prop.stringValue = new_sequence;
                            sequence_prop.serializedObject.ApplyModifiedProperties();
                        }
                    }
                });
            }
        }
示例#5
0
 static bool SafeLoadSwfAsset(string swf_path, string swf_hash, SwfAsset swf_asset)
 {
     try {
         _progressBar.UpdateTitle(Path.GetFileName(swf_path));
         var new_data = LoadSwfAssetData(swf_path);
         swf_asset.Data = SwfEditorUtils.CompressAsset(new_data, progress => {
             _progressBar.UpdateProgress("swf asset compression", progress);
         });
         swf_asset.Hash = swf_hash;
         if (swf_asset.Atlas)
         {
             AssetDatabase.DeleteAsset(
                 AssetDatabase.GetAssetPath(swf_asset.Atlas));
             swf_asset.Atlas = null;
         }
         EditorUtility.SetDirty(swf_asset);
         return(true);
     } catch (Exception e) {
         Debug.LogErrorFormat(
             AssetDatabase.LoadMainAssetAtPath(swf_path),
             "<b>[FlashTools]</b> Parsing swf error: {0}\nSwf path: {1}",
             e.Message, swf_path);
         return(false);
     } finally {
         _progressBar.HideProgress();
     }
 }
示例#6
0
 void DrawClipControls()
 {
     EditorGUILayout.Space();
     SwfEditorUtils.DoCenterHorizontalGUI(() => {
         if (GUILayout.Button(new GUIContent("<<", "to begin frame")))
         {
             AllClipsForeachWithUndo(p => p.ToBeginFrame());
         }
         if (GUILayout.Button(new GUIContent("<", "to prev frame")))
         {
             AllClipsForeachWithUndo(p => p.ToPrevFrame());
         }
         GUILayout.Label(string.Format(
                             "{0}/{1}",
                             GetClipsCurrentFrameForView(), GetClipsFrameCountForView()));
         if (GUILayout.Button(new GUIContent(">", "to next frame")))
         {
             AllClipsForeachWithUndo(p => p.ToNextFrame());
         }
         if (GUILayout.Button(new GUIContent(">>", "to end frame")))
         {
             AllClipsForeachWithUndo(p => p.ToEndFrame());
         }
     });
 }
示例#7
0
 void DrawGUINotes()
 {
     SwfEditorUtils.DrawMasksGUINotes();
     if (_outdated)
     {
         SwfEditorUtils.DrawOutdatedGUINotes("SwfClipAsset", _clips);
     }
 }
示例#8
0
 static SwfSettings GetSettingsHolder()
 {
     if (!_settingsHolder)
     {
         _settingsHolder = SwfEditorUtils.GetSettingsHolder();
     }
     return(_settingsHolder);
 }
示例#9
0
 void DrawCounts()
 {
     SwfEditorUtils.DoWithEnabledGUI(false, () => {
         EditorGUILayout.IntField(
             "Clip count",
             _manager.clipCount);
         EditorGUILayout.IntField(
             "Controller count",
             _manager.controllerCount);
     });
 }
示例#10
0
        //
        //
        //

        void DrawGUIFrameCount()
        {
            var counts      = _clips.Select(p => GetFrameCount(p));
            var mixed_value = counts.GroupBy(p => p).Count() > 1;

            SwfEditorUtils.DoWithEnabledGUI(false, () => {
                SwfEditorUtils.DoWithMixedValue(
                    mixed_value, () => {
                    EditorGUILayout.IntField("Frame count", counts.First());
                });
            });
        }
示例#11
0
 void DrawGUIControls()
 {
     SwfEditorUtils.DoHorizontalGUI(() => {
         if (GUILayout.Button("Create prefab"))
         {
             CreateAllClipsPrefabs();
         }
         if (GUILayout.Button("Instance to scene"))
         {
             CreateAllClipsOnScene();
         }
     });
 }
示例#12
0
 void DrawGUISequences()
 {
     SwfEditorUtils.DoWithEnabledGUI(false, () => {
         var sequences_prop = SwfEditorUtils.GetPropertyByName(
             serializedObject, "Sequences");
         if (sequences_prop.isArray)
         {
             SwfEditorUtils.DoWithMixedValue(
                 sequences_prop.hasMultipleDifferentValues, () => {
                 EditorGUILayout.IntField("Sequence count", sequences_prop.arraySize);
             });
         }
     });
 }
示例#13
0
        void DrawCurrentFrame()
        {
            var min_frame_count = GetMinClipsFrameCount();

            if (min_frame_count > 1)
            {
                EditorGUILayout.IntSlider(
                    SwfEditorUtils.GetPropertyByName(serializedObject, "_currentFrame"),
                    0,
                    min_frame_count - 1,
                    "Current frame");
                DrawClipControls();
            }
        }
示例#14
0
        void DrawGUISourceAsset()
        {
            var asset_guids = _clips.Select(p => p.AssetGUID);
            var mixed_value = asset_guids.GroupBy(p => p).Count() > 1;

            SwfEditorUtils.DoWithEnabledGUI(false, () => {
                SwfEditorUtils.DoWithMixedValue(
                    mixed_value, () => {
                    var source_asset = AssetDatabase.LoadAssetAtPath <SwfAsset>(
                        AssetDatabase.GUIDToAssetPath(asset_guids.First()));
                    EditorGUILayout.ObjectField(
                        "Source Asset", source_asset, typeof(SwfAsset), false);
                });
            });
        }
示例#15
0
        void DrawGroupControls()
        {
            var group_names = GetAllGroupNames();

            if (group_names.Count > 0)
            {
                _groupsFoldout = EditorGUILayout.Foldout(_groupsFoldout, "Groups");
                if (_groupsFoldout)
                {
                    foreach (var group_name in group_names)
                    {
                        SwfEditorUtils.DoWithEnabledGUI(false, () => {
                            EditorGUILayout.TextField("Name", group_name);
                        });
                        {
                            EditorGUI.BeginChangeCheck();
                            var new_rate_scale = EditorGUILayout.FloatField(
                                "Rate Scale", _manager.GetGroupRateScale(group_name));
                            if (EditorGUI.EndChangeCheck())
                            {
                                _manager.SetGroupRateScale(group_name, new_rate_scale);
                            }
                        }
                        {
                            EditorGUI.BeginChangeCheck();
                            var new_user_unscaled_dt = EditorGUILayout.Toggle(
                                "Use Unscaled Dt", _manager.IsGroupUseUnscaledDt(group_name));
                            if (EditorGUI.EndChangeCheck())
                            {
                                _manager.SetGroupUseUnscaledDt(group_name, new_user_unscaled_dt);
                            }
                        }
                        SwfEditorUtils.DoRightHorizontalGUI(() => {
                            if (_manager.IsGroupPaused(group_name) && GUILayout.Button("Resume"))
                            {
                                _manager.ResumeGroup(group_name);
                            }
                            if (_manager.IsGroupPlaying(group_name) && GUILayout.Button("Pause"))
                            {
                                _manager.PauseGroup(group_name);
                            }
                        });
                    }
                }
            }
        }
示例#16
0
        static void SwfFileProcess(string swf_path)
        {
            var swf_hash       = SwfEditorUtils.GetFileHashWithVersion(swf_path);
            var swf_asset_path = Path.ChangeExtension(swf_path, ".asset");

            SwfEditorUtils.LoadOrCreateAsset <SwfAsset>(swf_asset_path, (swf_asset, created) => {
                if (!string.IsNullOrEmpty(swf_asset.Hash) && swf_asset.Hash == swf_hash)
                {
                    return(true);
                }
                else if (created)
                {
                    var default_settings = SwfEditorUtils.GetSettingsHolder().Settings;
                    swf_asset.Settings   = default_settings;
                    swf_asset.Overridden = default_settings;
                }
                return(SafeLoadSwfAsset(swf_path, swf_hash, swf_asset));
            });
        }
示例#17
0
 void DrawClipControls()
 {
     SwfEditorUtils.DoRightHorizontalGUI(() => {
         if (GUILayout.Button("Stop"))
         {
             AllControllersForeach(ctrl => ctrl.Stop(ctrl.isStopped));
         }
         if (GUILayout.Button("Play"))
         {
             AllControllersForeach(ctrl => {
                 var rewind =
                     ctrl.isPlaying ||
                     (ctrl.clip && (
                          ctrl.clip.currentFrame == 0 ||
                          ctrl.clip.currentFrame == ctrl.clip.frameCount - 1));
                 ctrl.Play(rewind);
             });
         }
     });
 }
示例#18
0
 void DrawControls()
 {
     SwfEditorUtils.DoRightHorizontalGUI(() => {
         if (_manager.useUnscaledDt && GUILayout.Button("Use Scaled Dt"))
         {
             _manager.useUnscaledDt = false;
         }
         if (!_manager.useUnscaledDt && GUILayout.Button("Use Unscaled Dt"))
         {
             _manager.useUnscaledDt = true;
         }
         if (_manager.isPaused && GUILayout.Button("Resume"))
         {
             _manager.Resume();
         }
         if (_manager.isPlaying && GUILayout.Button("Pause"))
         {
             _manager.Pause();
         }
     });
 }
        static void ConfigureClip(SwfAsset asset, SwfAssetData data, SwfSymbolData symbol)
        {
            var asset_guid  = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset));
            var clip_assets = SwfEditorUtils.LoadAllAssetsDBByFilter <SwfClipAsset>("t:SwfClipAsset")
                              .Where(p => p.AssetGUID == asset_guid && p.Name == symbol.Name);

            if (clip_assets.Any())
            {
                foreach (var clip_asset in clip_assets)
                {
                    ConfigureClipAsset(clip_asset, asset, data, symbol);
                }
            }
            else
            {
                var asset_path      = AssetDatabase.GetAssetPath(asset);
                var clip_asset_path = Path.ChangeExtension(asset_path, symbol.Name + ".asset");
                SwfEditorUtils.LoadOrCreateAsset <SwfClipAsset>(clip_asset_path, (new_clip_asset, created) => {
                    ConfigureClipAsset(new_clip_asset, asset, data, symbol);
                    return(true);
                });
            }
        }
示例#20
0
        void DrawGUISettingsControls()
        {
            var prop = SwfEditorUtils.GetPropertyByName(serializedObject, "Overridden");

            if (prop.isExpanded)
            {
                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Reconvert"))
                    {
                        ApplyAllOverriddenSettings();
                    }
                    GUILayout.FlexibleSpace();
                    var default_settings = GetSettingsHolder().Settings;
                    SwfEditorUtils.DoWithEnabledGUI(
                        _assets.Any(p => !p.Overridden.CheckEquals(default_settings)), () => {
                        if (GUILayout.Button("Default"))
                        {
                            AllOverriddenSettingsToDefault();
                        }
                    });
                    SwfEditorUtils.DoWithEnabledGUI(
                        _assets.Any(p => !p.Overridden.CheckEquals(p.Settings)), () => {
                        if (GUILayout.Button("Revert"))
                        {
                            RevertAllOverriddenSettings();
                        }
                        if (GUILayout.Button("Apply"))
                        {
                            ApplyAllOverriddenSettings();
                        }
                    });
                }
                GUILayout.EndHorizontal();
            }
        }
        static SwfClipAsset.Frame BakeClipFrame(
            SwfAsset asset, SwfAssetData data, SwfFrameData frame)
        {
            List <uint>       baked_uvs       = new List <uint>();
            List <uint>       baked_mulcolors = new List <uint>();
            List <uint>       baked_addcolors = new List <uint>();
            List <Vector2>    baked_vertices  = new List <Vector2>();
            List <BakedGroup> baked_groups    = new List <BakedGroup>();
            List <Material>   baked_materials = new List <Material>();

            foreach (var inst in frame.Instances)
            {
                var bitmap = inst != null
                                        ? FindBitmapFromAssetData(data, inst.Bitmap)
                                        : null;

                while (bitmap != null && bitmap.Redirect > 0)
                {
                    bitmap = FindBitmapFromAssetData(data, bitmap.Redirect);
                }
                if (bitmap != null)
                {
                    var br = asset.Settings.BitmapTrimming
                                                ? bitmap.TrimmedRect
                                                : new SwfRectIntData(bitmap.RealWidth, bitmap.RealHeight);

                    var v0 = new Vector2(br.xMin, br.yMin);
                    var v1 = new Vector2(br.xMax, br.yMin);
                    var v2 = new Vector2(br.xMax, br.yMax);
                    var v3 = new Vector2(br.xMin, br.yMax);

                    var matrix =
                        Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f) / asset.Settings.PixelsPerUnit) *
                        inst.Matrix.ToUMatrix() *
                        Matrix4x4.Scale(new Vector3(1.0f / 20.0f, 1.0f / 20.0f, 1.0f));

                    baked_vertices.Add(matrix.MultiplyPoint3x4(v0));
                    baked_vertices.Add(matrix.MultiplyPoint3x4(v1));
                    baked_vertices.Add(matrix.MultiplyPoint3x4(v2));
                    baked_vertices.Add(matrix.MultiplyPoint3x4(v3));

                    var source_rect = bitmap.SourceRect;
                    baked_uvs.Add(SwfEditorUtils.PackUV(source_rect.xMin, source_rect.yMin));
                    baked_uvs.Add(SwfEditorUtils.PackUV(source_rect.xMax, source_rect.yMax));

                    uint mul_pack0, mul_pack1;
                    SwfEditorUtils.PackFColorToUInts(
                        inst.ColorTrans.mulColor.ToUVector4(),
                        out mul_pack0, out mul_pack1);
                    baked_mulcolors.Add(mul_pack0);
                    baked_mulcolors.Add(mul_pack1);

                    uint add_pack0, add_pack1;
                    SwfEditorUtils.PackFColorToUInts(
                        inst.ColorTrans.addColor.ToUVector4(),
                        out add_pack0, out add_pack1);
                    baked_addcolors.Add(add_pack0);
                    baked_addcolors.Add(add_pack1);

                    if (baked_groups.Count == 0 ||
                        baked_groups[baked_groups.Count - 1].Type != inst.Type ||
                        baked_groups[baked_groups.Count - 1].BlendMode != inst.BlendMode.type ||
                        baked_groups[baked_groups.Count - 1].ClipDepth != inst.ClipDepth)
                    {
                        baked_groups.Add(new BakedGroup {
                            Type          = inst.Type,
                            BlendMode     = inst.BlendMode.type,
                            ClipDepth     = inst.ClipDepth,
                            StartVertex   = baked_vertices.Count - 4,
                            TriangleCount = 0,
                            Material      = null
                        });
                    }

                    baked_groups.Last().TriangleCount += 6;
                }
            }

            for (var i = 0; i < baked_groups.Count; ++i)
            {
                var group = baked_groups[i];
                switch (group.Type)
                {
                case SwfInstanceData.Types.Mask:
                    group.Material = SwfMaterialCache.GetIncrMaskMaterial();
                    break;

                case SwfInstanceData.Types.Group:
                    group.Material = SwfMaterialCache.GetSimpleMaterial(group.BlendMode);
                    break;

                case SwfInstanceData.Types.Masked:
                    group.Material = SwfMaterialCache.GetMaskedMaterial(group.BlendMode, group.ClipDepth);
                    break;

                case SwfInstanceData.Types.MaskReset:
                    group.Material = SwfMaterialCache.GetDecrMaskMaterial();
                    break;

                default:
                    throw new UnityException(string.Format(
                                                 "SwfAssetPostprocessor. Incorrect instance type: {0}",
                                                 group.Type));
                }
                if (group.Material)
                {
                    baked_materials.Add(group.Material);
                }
                else
                {
                    throw new UnityException(string.Format(
                                                 "SwfAssetPostprocessor. Material for baked group ({0}) not found",
                                                 group.Type));
                }
            }

            var mesh_data = new SwfClipAsset.MeshData {
                SubMeshes = baked_groups
                            .Select(p => new SwfClipAsset.SubMeshData {
                    StartVertex = p.StartVertex,
                    IndexCount  = p.TriangleCount
                })
                            .ToArray(),
                Vertices  = baked_vertices.ToArray(),
                UVs       = baked_uvs.ToArray(),
                AddColors = baked_addcolors.ToArray(),
                MulColors = baked_mulcolors.ToArray()
            };

            return(new SwfClipAsset.Frame(
                       frame.Labels.ToArray(),
                       mesh_data,
                       baked_materials.ToArray()));
        }
示例#22
0
        private void DrawGUICreateClips()
        {
            SwfEditorUtils.DoHorizontalGUI(() => {
                if (GUILayout.Button("Create/Update All AnimationClips from sequences"))
                {
                    SwfClipAsset clip;
                    List <SwfClipAsset.Sequence> allSequences;
                    SwfClipAsset.Sequence sequence;
                    List <AnimationClip> allAnimationClips = new List <AnimationClip>();
                    AnimationClip animationClip;
                    int frameCount;
                    string sequenceName;
                    float frameRate;
                    AnimationEvent animationEvent;
                    AnimationEvent[] allAnimationEvents;
                    float timePerSprite;
                    string animFolder;
                    string animPath;

                    for (int i = _clips.Count - 1; i > -1; i--)
                    {
                        clip         = _clips[i];
                        frameRate    = clip.FrameRate;
                        allSequences = clip.Sequences;
                        animFolder   = Path.GetDirectoryName(AssetDatabase.GetAssetPath(clip)) + "/";

                        for (int j = allSequences.Count - 1; j > -1; j--)
                        {
                            sequence     = allSequences[j];
                            frameCount   = sequence.Frames.Count;
                            sequenceName = sequence.Name;

                            animPath = animFolder + sequenceName + ".anim";

                            allAnimationEvents = new AnimationEvent[frameCount];

                            animationClip = GetAnimationClipAt(animPath);

                            EditorUtility.SetDirty(animationClip);

                            animationClip.frameRate = frameRate;

                            timePerSprite = 1f / frameRate;

                            animationEvent = new AnimationEvent();
                            animationEvent.stringParameter = sequenceName;
                            animationEvent.time            = 0;
                            animationEvent.functionName    = "set_sequence";
                            allAnimationEvents[0]          = animationEvent;

                            for (int k = 1; k < frameCount; k++)
                            {
                                animationEvent = new AnimationEvent();
                                animationEvent.intParameter = k;
                                animationEvent.time         = timePerSprite * k;
                                animationEvent.functionName = "GotoAndStop";
                                allAnimationEvents[k]       = animationEvent;
                            }

                            AnimationUtility.SetAnimationEvents(animationClip, allAnimationEvents);
                            AssetDatabase.SaveAssets();
                            AssetDatabase.Refresh();
                        }
                    }
                }
            });
        }
示例#23
0
        // ---------------------------------------------------------------------
        //
        // Messages
        //
        // ---------------------------------------------------------------------

        void OnEnable()
        {
            _clips    = targets.OfType <SwfClip>().ToList();
            _outdated = SwfEditorUtils.CheckForOutdatedAsset(_clips);
            SetupPreviews();
        }
示例#24
0
        // ---------------------------------------------------------------------
        //
        // Messages
        //
        // ---------------------------------------------------------------------

        void OnEnable()
        {
            _assets   = targets.OfType <SwfAsset>().ToList();
            _outdated = SwfEditorUtils.CheckForOutdatedAsset(_assets);
        }