private void ApplyFrame(FGAnimationKeyFrame frame)
    {
        _mainLayer.sprite = frame.sprite;
        _currentStage     = frame.type;
        _currentKeyFrame  = frame;

        /*if (frame.type == FGAnimationStageType.ACTIVE)
         * {
         *  hitBoxActive = true;
         *  _activeHitBox = new Rect(frame.hitBox.position + _currentOffset, frame.hitBox.size);
         * }
         * else
         * {
         *  hitBoxActive = false;
         * }*/
    }
 //!
 public void ModifyFrameAtIndex(int indx, Sprite s, int fc, FGAnimationStageType t)
 {
     if (indx < frames.Length)
     {
         if (s != null)
         {
             frames[indx].sprite = s;
         }
         if (fc >= 0)
         {
             totalFrameCount        += (fc - frames[indx].frameCount);
             frames[indx].frameCount = fc;
             RecalculateFrameToKeyFrame();
         }
         if (t != FGAnimationStageType.NUM_TYPES)
         {
             frames[indx].type = t;
         }
     }
 }
    //!
    public void Play(string animationName)
    {
        if (_animations.ContainsKey(animationName) && animationName != _currentAnimation)
        {
            if (_animations[animationName].type == FGAnimationType.ONCE)
            {
                _currentState = AnimatorState.IN_ATTACK;
                _currentStage = FGAnimationStageType.STARTUP;
            }
            else
            {
                _currentState = AnimatorState.FREE;
            }

            for (int i = 0; i < _layerRenderers.Length; i++)
            {
                Vector2 rendererPosition = _layerRenderers[i].rectTransform.anchoredPosition;
                //_layerRenderers[i].rectTransform.anchoredPosition = rendererPosition + (_animations[animationName].positionOffset - _currentOffset);
                if (_reversed)
                {
                    _layerRenderers[i].rectTransform.localScale       = new Vector3(-1, 1, 1);
                    _layerRenderers[i].rectTransform.anchoredPosition = _animations[animationName].imageOffset * _layerRenderers[i].rectTransform.localScale;
                }
                else
                {
                    _layerRenderers[i].rectTransform.localScale       = new Vector3(1, 1, 1);
                    _layerRenderers[i].rectTransform.anchoredPosition = _animations[animationName].imageOffset;
                }

                _layerRenderers[i].rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _animations[animationName].imageSize.x);
                _layerRenderers[i].rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _animations[animationName].imageSize.y);
            }
            _currentOffset    = _animations[animationName].imageOffset - _originalOffset;
            _currentKeyFrame  = null;
            _animatorTime     = 0;
            _currentAnimation = animationName;
        }
    }
    public override void OnInspectorGUI()
    {
        //base.DrawDefaultInspector();
        GUILayout.BeginVertical();
        FGAnimation data = (FGAnimation)target;

        data.animName = EditorGUILayout.TextField("Animation name: ", data.animName) as string;
        data.type     = (FGAnimationType)EditorGUILayout.Popup("Animation play type: ", (int)data.type, new string[] { "Loop", "Once", "Bounce", "Reverse" });

        //data.positionOffset = (Vector2)EditorGUILayout.Vector2Field("Offset: ", data.positionOffset);

        data.imageOffset = (Vector2)EditorGUILayout.Vector2Field("Image Offset Position: ", data.imageOffset);
        data.imageSize   = (Vector2)EditorGUILayout.Vector2Field("Image Size: ", data.imageSize);

        if (data.type == FGAnimationType.ONCE)
        {
            data.nextAnimation = EditorGUILayout.TextField("Next animation to go to after this one completes: ", data.nextAnimation) as string;

            if (data.attackData == null)
            {
                data.attackData = new FGAttackData();
            }
            data.attackData.guard           = (Guard)EditorGUILayout.Popup("Guard Type: ", (int)data.attackData.guard, new string[] { "LOW", "MID", "HIGH" });
            data.attackData.frameAdvOnBlock = (int)EditorGUILayout.IntField("Frame adv on block: ", (int)data.attackData.frameAdvOnBlock);
            data.attackData.frameAdvOnHit   = (int)EditorGUILayout.IntField("Frame adv on hit: ", (int)data.attackData.frameAdvOnHit);
            data.attackData.damage          = (int)EditorGUILayout.IntField("Damage: ", (int)data.attackData.damage);
            data.attackData.attackVector    = (Vector2)EditorGUILayout.Vector2Field("Direction vector for attack pushback", data.attackData.attackVector);
        }

        //RenderGenerateToggle(ref data);

        //List<int> removeFrames = new List<int>();
        if (data.frames.Length <= 0)
        {
            GUILayout.Label("Create animation from sprite sheet?");
            spriteSheet = (Texture2D)EditorGUILayout.ObjectField(spriteSheet, typeof(Texture2D), true);

            indxBeg = (int)EditorGUILayout.IntField("Starting Index: ", indxBeg);
            indxEnd = (int)EditorGUILayout.IntField("Ending Index: ", indxEnd);

            if (GUILayout.Button("Generate"))
            {
                if (spriteSheet != null)
                {
                    BuildAnimation(spriteSheet.name, indxBeg, indxEnd);
                }
            }
        }
        else
        {
            for (int i = 0; i < data.frames.Length; i++)
            {
                GUILayout.BeginVertical();
                FGAnimationStageType stage = (FGAnimationStageType)EditorGUILayout.Popup("Stage in animation: ", (int)data.frames[i].type, new string[] { "Startup", "Active", "Recovery" });
                int    frameCount          = (int)EditorGUILayout.IntField("Frame count: ", data.frames[i].frameCount);
                Sprite sprite = (Sprite)EditorGUILayout.ObjectField(data.frames[i].sprite, typeof(Sprite), true);

                data.ModifyFrameAtIndex(i, sprite, frameCount, stage);

                if (stage == FGAnimationStageType.ACTIVE)
                {
                    if (data.frames[i].hitBox == null)
                    {
                        data.frames[i].hitBox = new Rect();
                    }

                    data.frames[i].hitBox = (Rect)EditorGUILayout.RectField(data.frames[i].hitBox);
                }


                GUILayout.EndVertical();

                /*GUILayout.BeginHorizontal();
                 * for (int j = 0; j < data.frames[i].frameCount; j++)
                 * {
                 *  if (sprite.texture)
                 *  {
                 *
                 *  }
                 * }
                 * GUILayout.EndHorizontal();*/
                if (GUILayout.Button("Remove Key"))
                {
                    data.RemoveFrame(i);
                    break;
                }
            }
        }

        if (GUILayout.Button("Add Key Frame"))
        {
            data.AddFrame(new FGAnimationKeyFrame());
        }

        ShowAnimationPreview();
        GUILayout.EndVertical();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            AssetDatabase.SaveAssets();
        }
    }