예제 #1
0
        // This is just short for GetAnimation(...).CreateInstance();
        public static SpriteAnimationInstance CreateAnimationInstance(SpriteAnimationType animType)
        {
            SpriteAnimationData     anim   = GetAnimation(animType);
            SpriteAnimationInstance result = anim.CreateInstance();

            return(result);
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            GUILayout.BeginVertical();
            GUILayout.Space(8);

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("打开动画编辑器", GUILayout.MinWidth(120)))
            {
                SpriteAnimationData gen = (SpriteAnimationData)target;
                if (gen.name != defaultSpriteAnimationName)
                {
                    EditorUtility.DisplayDialog("提示", "请修改预设名" + defaultSpriteAnimationName + "再操作", "Ok");
                }
                else
                {
                    SpriteAnimationEditorPopup v = EditorWindow.GetWindow(typeof(SpriteAnimationEditorPopup), false, "动画编辑器") as SpriteAnimationEditorPopup;

                    v.SetGenerator(gen);
                    v.Show();
                }
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            GUILayout.Space(8);
        }
예제 #3
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            GUILayout.BeginVertical();
            GUILayout.Space(8);

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("打开动画编辑器", GUILayout.MinWidth(120)))
            {
                SpriteAnimationData gen = (SpriteAnimationData)target;

                SpriteAnimationEditorPopup v = EditorWindow.GetWindow(typeof(SpriteAnimationEditorPopup), false, "动画编辑器") as SpriteAnimationEditorPopup;

                v.SetGenerator(gen);
                v.Show();
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            GUILayout.Space(8);
        }
        public void addAnimation(string anim, params int[] frames)
        {
            var sad = new SpriteAnimationData();

            sad.name   = anim;
            sad.frames = frames;
            _animations.Add(sad);
        }
예제 #5
0
 private void OnEnable()
 {
     if (IsAwakePlay)
     {
         _index            = 0;
         _currentAnimation = null;
         PlayDefaultAnim();
     }
 }
예제 #6
0
        private void AnimationControlButtons(Dictionary <string, SpriteAnimationData> anims)
        {
            Vector2 winSize = ImGui.GetWindowSize();

            ImGui.SetCursorPosY(winSize.Y - ImGui.GetFrameHeightWithSpacing() - (ImGui.GetTextLineHeightWithSpacing() - ImGui.GetTextLineHeight()));
            if (ImGui.Button("Add Animation"))
            {
                const string newName    = "NewAnim";
                string       newNameCur = newName;
                var          loops      = 1;
                while (anims.ContainsKey(newNameCur))
                {
                    newNameCur = $"{newName} ({loops})";
                    loops++;
                }

                var newAnim = new SpriteAnimationData(newNameCur, 0);
                anims.Add(newNameCur, newAnim);
                _selectedAnimation = newNameCur;
                _controller.SetAnimation(_selectedAnimation);
            }

            ImGui.SameLine();
            if (ImGui.Button("Remove Selected") && anims.Count != 1)
            {
                anims.Remove(_selectedAnimation);
                _selectedAnimation = anims.First().Key;
                _controller.SetAnimation(_selectedAnimation);
                UnsavedChanges();
            }

            ImGui.SameLine();
            if (ImGui.Button("Rename Selected"))
            {
                var newName = new StringInputModalWindow(s =>
                {
                    string ogS = s;
                    var loops  = 1;
                    while (anims.ContainsKey(s))
                    {
                        s = $"{ogS} ({loops})";
                        loops++;
                    }

                    SpriteAnimationData selNode = anims[_selectedAnimation];
                    selNode.Name = s;
                    anims.Remove(_selectedAnimation);
                    _selectedAnimation = s;
                    anims.Add(s, selNode);
                    UnsavedChanges();
                },
                                                         $"New name for {_selectedAnimation}");
                _toolsRoot.AddChild(newName);
            }

            ImGui.EndChild();
        }
예제 #7
0
 public void SetGenerator(SpriteAnimationData spriteAnimationData)
 {
     this._spriteAnimationData = spriteAnimationData;
     allAction = new List <SpriteAnimationData.ActionData>();
     for (int i = 0; i < spriteAnimationData.ActionList.Count(); i++)
     {
         allAction.Add(spriteAnimationData.ActionList[i]);
     }
     dir = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(spriteAnimationData)) + "/";
 }
예제 #8
0
 public void Play(string name, bool isLoop, float speed = 1)
 {
     if (_currentAnimation != null && _currentAnimation.Key == name)
     {
         return;
     }
     _time             = 0;
     _speed            = speed;
     _currentAnimation = Animations.Find(o => o.Key == name);
     _isLoop           = isLoop;
     _index            = 0;
 }
예제 #9
0
        public static void CreateSpriteCollection(string prefabName)
        {
            string path = GameEditorUtility.CreateNewPrefab(prefabName);

            if (path.Length != 0)
            {
                SpriteAnimationData spriteAnimationData = ScriptableObject.CreateInstance <SpriteAnimationData>();
                spriteAnimationData.version = SpriteAnimationData.CURRENT_VERSION;
                SetAtlas(path, spriteAnimationData);
                AssetDatabase.CreateAsset(spriteAnimationData, path);
                //创建后拾取
                Selection.activeObject = AssetDatabase.LoadAssetAtPath(path, typeof(SpriteAnimationData));
            }
        }
 public void setAnimation(string anim)
 {
     _currentFrame = -1;
     for (var i = 0; i < _animations.Count; i++)
     {
         if (_animations[i].name == anim)
         {
             _currentAnimation = _animations[i];
             _currentFrame     = 0;
             frame             = _animations[i].frames[0];
             _timer            = _fps;
             break;
         }
     }
 }
        private static void SetAtlas(string path, SpriteAnimationData spriteAnimationData)
        {
            DirectoryInfo info = new DirectoryInfo(Path.GetDirectoryName(path));

            FileInfo[] files = info.GetFiles();
            foreach (FileInfo file in files)
            {
                if (file.FullName.EndsWith("prefab")) //only prefab
                {
                    string          fullPath           = getAssetPath(file.FullName);
                    SpriteAtlasData objSpriteAtlasData = AssetDatabase.LoadAssetAtPath(fullPath, typeof(SpriteAtlasData)) as SpriteAtlasData;
                    if (objSpriteAtlasData != null)
                    {
                        spriteAnimationData.SpriteAtlasData = objSpriteAtlasData;
                    }
                }
            }
        }
예제 #12
0
        public static SpriteAnimationData CreateAnimation(Texture2D atlas, ref SpriteAnimationConfig config)
        {
            SpriteAnimationData result = null;

            if (config.TileCount > 0 || config.TileDim.X > 0 || config.TileDim.Y > 0)
            {
                result = new SpriteAnimationData()
                {
                    Config = config
                };
                result.Frames.Capacity = config.TileCount;
                int numCols = atlas.Width / config.TileDim.X;
                int numRows = atlas.Height / config.TileDim.Y;
                result.TileSheet = atlas;
                int spriteIndex = 0;
                for (int row = 0; row < numRows; row++)
                {
                    for (int col = 0; col < numCols; col++, spriteIndex++)
                    {
                        if (spriteIndex >= config.TileCount)
                        {
                            goto DONE_LABEL;
                        }

                        SpriteAnimationFrame frame = new SpriteAnimationFrame
                        {
                            Offset = new Point(col, row) * config.TileDim
                        };
                        result.Frames.Add(frame);
                    }
                }

                DONE_LABEL :;
            }

            return(result);
        }
예제 #13
0
        static SpriteAnimationData GetAnimationData(UnityEngine.Object tk2dSpriteAnimation)
        {
            if (tk2dSpriteAnimation == null)
            {
                throw new NullReferenceException("Sprite Animation Data is null");
            }
            var type = tk2dSpriteAnimation.GetType();

            if (type != SpriteAnimationType)
            {
                throw new Exception("The data is not of the type tk2dSpriteAnimation");
            }

            SpriteAnimationData animationData = new SpriteAnimationData();

            var clipsArray = GetField <Array>(SpriteAnimationType, tk2dSpriteAnimation, "clips");

            animationData.Clips = new ClipData[clipsArray.GetLength(0)];

            for (int i = 0; i < clipsArray.GetLength(0); i++)
            {
                var clipRaw  = clipsArray.GetValue(i);
                var clipType = clipRaw.GetType();

                var newClip = new ClipData
                {
                    Name      = GetField <string>(clipType, clipRaw, "name"),
                    FPS       = GetField <float>(clipType, clipRaw, "fps"),
                    LoopStart = GetField <int>(clipType, clipRaw, "loopStart")
                };


                var wrapEnumRaw = clipType.GetField("wrapMode").GetValue(clipRaw);
                var rawEnumType = wrapEnumRaw.GetType();

                newClip.WrapMode = (WrapMode)Enum.Parse(typeof(WrapMode), Enum.GetName(rawEnumType, wrapEnumRaw));


                var framesArray = GetField <Array>(clipType, clipRaw, "frames");

                newClip.Frames = new FrameData[framesArray.GetLength(0)];

                for (int j = 0; j < framesArray.GetLength(0); j++)
                {
                    var frameRaw  = framesArray.GetValue(j);
                    var frameType = frameRaw.GetType();

                    var frame = new FrameData
                    {
                        SpriteID            = GetField <int>(frameType, frameRaw, "spriteId"),
                        SpriteCollectionRaw = GetField <UnityEngine.Object>(frameType, frameRaw, "spriteCollection")
                    };

                    newClip.Frames[j] = frame;
                }

                /*if (newClip.Name == "Roar Loop")
                 * {
                 *      Debug.Log("Clip Name 1 - " + newClip.Name);
                 *      Debug.Log("FPS 1 - " + newClip.FPS);
                 *      Debug.Log("Frame Count 1 = " + newClip.Frames.GetLength(0));
                 *      foreach (var frame in newClip.Frames)
                 *      {
                 *              Debug.Log("Frame = " + frame.SpriteID);
                 *      }
                 * }*/


                animationData.Clips[i] = newClip;
            }

            return(animationData);
        }
예제 #14
0
        public static SpriteAnimationData GetAnimation(SpriteAnimationType animType)
        {
            Debug.Assert(_content != null, "Not initialized.");
            SpriteAnimationData result = _known[(int)animType];

            if (result == null)
            {
                const float owliverHotspotY = 170.0f;

                SpriteAnimationConfig config = SpriteAnimationConfig.Default;

                switch (animType)
                {
                case SpriteAnimationType.Owliver_Idle_Stick_Left:
                {
                    config.TileSheetName = "owliver_idle_front_left_spritesheet";
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(125, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Idle_Stick_Right:
                {
                    config.TileSheetName = "owliver_idle_front_left_spritesheet";
                    config.SpriteEffects = SpriteEffects.FlipHorizontally;
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(129, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Walk_Stick_Left:
                {
                    config.TileSheetName = "owliver_walk_front_left_spritesheet";
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(125, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Walk_Stick_Right:
                {
                    config.TileSheetName = "owliver_walk_front_left_spritesheet";
                    config.SpriteEffects = SpriteEffects.FlipHorizontally;
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(129, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Attack_Stick_Left:
                {
                    config.TileSheetName  = "owliver_attack_spritesheet";
                    config.Scale          = Global.OwliverScale;
                    config.Hotspot        = new Vector2(169, owliverHotspotY);
                    config.TileCount      = 5;
                    config.PingPong       = false;
                    config.NumLoopsToPlay = 1;
                }
                break;

                case SpriteAnimationType.Owliver_Attack_Stick_Right:
                {
                    config.TileSheetName  = "owliver_attack_spritesheet";
                    config.SpriteEffects  = SpriteEffects.FlipHorizontally;
                    config.Scale          = Global.OwliverScale;
                    config.Hotspot        = new Vector2(86, owliverHotspotY);
                    config.TileCount      = 5;
                    config.PingPong       = false;
                    config.NumLoopsToPlay = 1;
                }
                break;

                case SpriteAnimationType.Owliver_Idle_FishingRod_Left:
                {
                    config.TileSheetName = "owliver_idle_fishingrod_spritesheet";
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(125, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Idle_FishingRod_Right:
                {
                    config.TileSheetName = "owliver_idle_fishingrod_spritesheet";
                    config.SpriteEffects = SpriteEffects.FlipHorizontally;
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(129, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Walk_FishingRod_Left:
                {
                    config.TileSheetName = "owliver_walk_fishingrod_spritesheet";
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(125, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Walk_FishingRod_Right:
                {
                    config.TileSheetName = "owliver_walk_fishingrod_spritesheet";
                    config.SpriteEffects = SpriteEffects.FlipHorizontally;
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(129, owliverHotspotY);
                }
                break;

                case SpriteAnimationType.Owliver_Attack_FishingRod_Left:
                {
                    config.TileSheetName  = "owliver_attack_fishingrod_spritesheet";
                    config.Scale          = Global.OwliverScale;
                    config.Hotspot        = new Vector2(169, owliverHotspotY);
                    config.TileCount      = 5;
                    config.PingPong       = false;
                    config.NumLoopsToPlay = 1;
                }
                break;

                case SpriteAnimationType.Owliver_Attack_FishingRod_Right:
                {
                    config.TileSheetName  = "owliver_attack_fishingrod_spritesheet";
                    config.SpriteEffects  = SpriteEffects.FlipHorizontally;
                    config.Scale          = Global.OwliverScale;
                    config.Hotspot        = new Vector2(86, owliverHotspotY);
                    config.TileCount      = 5;
                    config.PingPong       = false;
                    config.NumLoopsToPlay = 1;
                }
                break;

                case SpriteAnimationType.Slurp_Idle_Left:
                {
                    config.TileSheetName = "slurp_spritesheet";
                    config.TileCount     = 7;
                    config.TileDim       = new Point(210, 270);
                    config.Hotspot       = 0.5f * config.TileDim.ToVector2();
                    config.Scale         = Global.SlurpScale;
                }
                break;

                case SpriteAnimationType.Slurp_Idle_Right:
                {
                    config.SpriteEffects = SpriteEffects.FlipHorizontally;
                }
                    goto case SpriteAnimationType.Slurp_Idle_Left;

                case SpriteAnimationType.Singer_Idle_Left:
                {
                    // TODO(manu)
                    config.TileSheetName  = "slurp_spritesheet";
                    config.TileCount      = 7;
                    config.TileDim        = new Point(210, 270);
                    config.Hotspot        = 0.5f * config.TileDim.ToVector2();
                    config.Scale          = Global.SingerScale;
                    config.SpriteEffects |= SpriteEffects.FlipVertically;
                }
                break;

                case SpriteAnimationType.Singer_Idle_Right:
                {
                    config.SpriteEffects |= SpriteEffects.FlipHorizontally;
                }
                    goto case SpriteAnimationType.Singer_Idle_Left;

                case SpriteAnimationType.Shopkeeper_Idle_Front:
                {
                    config.TileSheetName = "shopkeeper_spritesheet";
                    config.Scale         = Global.OwliverScale;
                    config.Hotspot       = new Vector2(137, 236);
                }
                break;

                case SpriteAnimationType.Shop:
                {
                    config.TileSheetName = "shop_spritesheet";
                    config.TileDim       = new Point(512);
                    config.Hotspot       = new Vector2(261, 415);
                }
                break;

                case SpriteAnimationType.PriceTag_20:
                {
                    config.TileSheetName = "pricetag_20_spritesheet";
                    config.TileDim       = new Point(128);
                    config.Hotspot       = new Vector2(61, 100);
                }
                break;

                case SpriteAnimationType.PriceTag_100:
                {
                    config.TileSheetName = "pricetag_100_spritesheet";
                    config.TileDim       = new Point(128);
                    config.Hotspot       = new Vector2(61, 100);
                }
                break;

                case SpriteAnimationType.Gate_Closed:
                {
                    config.TileSheetName = "gate_spritesheet";
                    config.TileDim       = new Point(1024);
                    config.Hotspot       = new Vector2(560);
                }
                break;

                case SpriteAnimationType.Gate_Open:
                {
                    config.TileSheetName = "gate_open_spritesheet";
                    config.TileDim       = new Point(1024);
                    config.Hotspot       = new Vector2(560);
                }
                break;

                case SpriteAnimationType.Tankton_Idle_Left:
                {
                    config.SpriteEffects = SpriteEffects.FlipHorizontally;
                }
                    goto case SpriteAnimationType.Tankton_Idle_Right;

                case SpriteAnimationType.Tankton_Idle_Right:
                {
                    config.TileSheetName    = "boss_spritesheet";
                    config.TileDim          = new Point(512);
                    config.Hotspot          = new Vector2(256, 450);
                    config.Scale            = Global.TanktonScale;
                    config.PingPong         = false;
                    config.SecondsPerFrame *= 2;
                }
                break;

                case SpriteAnimationType.Fir_Idle:
                {
                    config.TileSheetName = "fir_spritesheet";
                    config.Hotspot       = new Vector2(136, 235);
                }
                break;

                case SpriteAnimationType.FirAlt_Idle:
                {
                    config.TileSheetName = "fir_spritesheet";
                    config.Hotspot       = new Vector2(128, 17);
                }
                break;

                case SpriteAnimationType.Conifer_Idle:
                {
                    config.TileSheetName = "conifer_spritesheet";
                    config.Hotspot       = new Vector2(134, 233);
                }
                break;

                case SpriteAnimationType.ConiferAlt_Idle:
                {
                    config.TileSheetName = "conifer_spritesheet";
                    config.Hotspot       = new Vector2(135, 18);
                }
                break;

                case SpriteAnimationType.Oak_Idle:
                {
                    config.TileSheetName = "oak_spritesheet";
                    config.Hotspot       = new Vector2(126, 224);
                }
                break;

                case SpriteAnimationType.Orange_Idle:
                {
                    config.TileSheetName = "orange_spritesheet";
                    config.Hotspot       = new Vector2(127, 227);
                }
                break;

                case SpriteAnimationType.Bush_Idle:
                {
                    config.TileSheetName = "bush_spritesheet";
                    config.Hotspot       = new Vector2(130, 212);
                }
                break;

                case SpriteAnimationType.Key_Gold:
                {
                    config.TileSheetName = "key_spritesheet";
                    config.TileDim       = new Point(128);
                    config.Hotspot       = 0.5f * config.TileDim.ToVector2();
                    config.Scale         = new Vector2(0.5f);
                }
                break;

                case SpriteAnimationType.Bonbon_Gold:
                {
                    config.TileSheetName = "bonbon_gold";
                    config.TileDim       = new Point(64);
                    config.Hotspot       = new Vector2(32);
                }
                break;

                case SpriteAnimationType.Bonbon_Red:
                {
                    config.TileSheetName = "bonbon_red";
                    config.TileDim       = new Point(64);
                    config.Hotspot       = new Vector2(32);
                }
                break;

                case SpriteAnimationType.FruitBowl:
                {
                    config.TileSheetName = "fruitbowl_spritesheet";
                    config.TileDim       = new Point(128);
                    config.Hotspot       = new Vector2(62, 82);
                }
                break;

                case SpriteAnimationType.Stick_Left:
                {
                    config.TileSheetName = "stick_spritesheet";
                    config.TileDim       = new Point(128);
                    config.Hotspot       = new Vector2(94, 92);
                }
                break;

                case SpriteAnimationType.FishingRod_Left:
                {
                    config.TileSheetName = "fishingrod_spritesheet";
                    config.TileDim       = new Point(128);
                    config.Hotspot       = new Vector2(106, 104);
                }
                break;

                case SpriteAnimationType.Cross:
                {
                    config.TileSheetName = "cross";
                    config.TileDim       = new Point(64);
                    config.Hotspot       = new Vector2(32);
                    config.Scale         = new Vector2(0.5f);
                }
                break;

                case SpriteAnimationType.Digit0:
                case SpriteAnimationType.Digit1:
                case SpriteAnimationType.Digit2:
                case SpriteAnimationType.Digit3:
                case SpriteAnimationType.Digit4:
                case SpriteAnimationType.Digit5:
                case SpriteAnimationType.Digit6:
                case SpriteAnimationType.Digit7:
                case SpriteAnimationType.Digit8:
                case SpriteAnimationType.Digit9:
                {
                    int digit = animType - SpriteAnimationType.Digit0;
                    config.TileSheetName = $"digits/{digit}";
                    config.TileDim       = new Point(64);
                    config.Hotspot       = new Vector2(32);

                    config.Scale = new Vector2(0.5f);
                    // TODO(manu): Remove this once we have all digits.
                    if (digit > 2)
                    {
                        config.TileSheetName = $"cross";
                    }
                }
                break;

                case SpriteAnimationType.OwlHealthIcon:
                {
                    config.TileSheetName = "health_icon_spritesheet";
                    config.TileDim       = new Point(128);
                    config.Hotspot       = 0.5f * config.TileDim.ToVector2();
                    config.Scale         = new Vector2(0.5f);
                }
                break;

                default: throw new ArgumentException("Unknown sprite animation type.");
                }

                if (config.TileSheetName != null)
                {
                    result = CreateAnimation(ref config);
                    _known[(int)animType] = result;
                }
            }

            return(result);
        }
예제 #15
0
        protected override void RenderImGui()
        {
            base.RenderImGui();
            float halfScreenWidth = Engine.Renderer.CurrentTarget.Size.X / 2f - 10; // Remove space between the two panels.

            if (_currentAsset == null)
            {
                ImGui.Text("No file loaded. Click 'New' to start!");
                return;
            }

            AnimatedSprite currentFileContext = _currentAsset.Content !;

            ImGui.BeginChild("Left", new Vector2(halfScreenWidth, -1), true, ImGuiWindowFlags.HorizontalScrollbar);

            if (currentFileContext.AssetFile == null)
            {
                ImGui.TextColored(new Vector4(1, 0, 0, 1), "No spritesheet texture set!");
                if (ImGui.Button("Set Grid Texture"))
                {
                    CreateNewFromTexture(true, currentFileContext);
                }
                ImGui.SameLine();
                if (ImGui.Button("Set Unordered Texture"))
                {
                    CreateNewFromTexture(false, currentFileContext);
                }
            }
            else
            {
                ImGui.Text($"Texture: {currentFileContext.AssetFile ?? "None"}");

                if (currentFileContext.Animations != null)
                {
                    ImGui.Text("Animations:");
                    ImGui.BeginChild("Animations", new Vector2(-1, 200), true, ImGuiWindowFlags.NoScrollbar);

                    Dictionary <string, SpriteAnimationData> anims = currentFileContext.Animations;
                    AnimationsList(anims);
                    AnimationControlButtons(anims);

                    if (_selectedAnimation != null && anims.ContainsKey(_selectedAnimation))
                    {
                        SpriteAnimationData selAnim = anims[_selectedAnimation];
                        ImGui.Text($"{selAnim.Name}:");
                        AnimationFrameEditor(anims);
                    }

                    ImGui.EndChild();
                }
            }

            ImGui.EndChild();

            ImGui.SameLine();

            ImGui.BeginChild("Right", new Vector2(halfScreenWidth, -1), true);
            ImGui.BeginTabBar("TabBar");

            if (ImGui.BeginTabItem("Frame Order"))
            {
                FrameOrderTab();
                ImGui.EndTabItem();
            }

            if (ImGui.BeginTabItem("Frame Anchors"))
            {
                FrameAnchorTab();
                ImGui.EndTabItem();
            }

            if (ImGui.BeginTabItem("Animation Preview"))
            {
                AnimationPreviewTab();
                ImGui.EndTabItem();
            }

            ImGui.EndTabBar();
            ImGui.EndChild();
        }
예제 #16
0
        private void AnimationFrameEditor(Dictionary <string, SpriteAnimationData> anims)
        {
            AnimatedSprite      currentFileContext = _currentAsset !.Content !;
            SpriteAnimationData selAnim            = anims[_selectedAnimation];

            ImGui.BeginChild("Animation", new Vector2(-1, -1), true);
            ImGui.Text("Frames: (Drag and Drop to rearrange)");

            SpriteAnimationFrameSource frameSource = currentFileContext.FrameSource;

            _draggedFrame = EditorHelpers.DragAndDropList(selAnim.FrameIndices, _draggedFrame, true);
            if (selAnim.FrameIndices.Length == 0)
            {
                EditorHelpers.ButtonSizedHole("");
            }

            ImGui.PushItemWidth(150);
            if (ImGui.InputInt("", ref _addFrameInput))
            {
                _addFrameInput = Maths.Clamp(_addFrameInput, 0, frameSource.GetFrameCount() - 1);
            }
            ImGui.SameLine();
            if (ImGui.Button("Add Frame"))
            {
                selAnim.FrameIndices = selAnim.FrameIndices.AddToArray(_addFrameInput);
                if (_addFrameInput < frameSource.GetFrameCount() - 2)
                {
                    _addFrameInput++;
                }
                _controller.Reset();
                UnsavedChanges();
            }

            ImGui.SameLine();
            ImGui.Button("Remove (Drop Here)");
            if (ImGui.BeginDragDropTarget())
            {
                ImGuiPayloadPtr dataPtr = ImGui.AcceptDragDropPayload("UNUSED");
                unsafe
                {
                    if ((IntPtr)dataPtr.NativePtr != IntPtr.Zero && dataPtr.IsDelivery())
                    {
                        int[] indices = selAnim.FrameIndices;
                        for (int i = _draggedFrame; i < indices.Length - 1; i++)
                        {
                            indices[i] = indices[i + 1];
                        }

                        Array.Resize(ref selAnim.FrameIndices, selAnim.FrameIndices.Length - 1);
                        _controller.Reset();
                        _draggedFrame = -1;
                        UnsavedChanges();
                    }
                }

                ImGui.EndDragDropTarget();
            }

            ImGui.PushItemWidth(150);
            ImGui.Text("Duration");
            ImGui.SameLine();
            if (ImGui.InputInt("###DurInput", ref selAnim.TimeBetweenFrames))
            {
                _controller.Reset();
                UnsavedChanges();
            }

            ImGui.SameLine();
            if (selAnim.FrameIndices.Length > 0)
            {
                ImGui.Text($"Total Duration: {selAnim.TimeBetweenFrames * selAnim.FrameIndices.Length}");
            }

            var loopType = (int)selAnim.LoopType;

            if (ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType)))))
            {
                selAnim.LoopType = (AnimationLoopType)loopType;
                _controller.Reset();
                UnsavedChanges();
            }
        }