Ejemplo n.º 1
0
    public FGAnimationKeyFrame LoopAnimationPlay(FGAnimation animation, double dt)
    {
        bool reset = animatorTimer >= animation.duration;

        if (reset)
        {
            animatorTimer -= animation.duration;
        }

        float adjustedTime = (float)animatorTimer;

        if (animation.type == FGAnimationType.REVERSE)
        {
            adjustedTime = animation.duration - adjustedTime;
        }

        currentFrame = AnimationPlayer.GetCurrentFrame(animation, adjustedTime);
        FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame);

        animatorTimer += dt;

        if (keyFrame != null)
        {
            ApplyFrame(keyFrame);
        }


        if (_currentKeyFrame != null)
        {
            return(_currentKeyFrame);
        }
        return(animation.frames[0]);
    }
    void ShowAnimationPreview()
    {
        FGAnimation data = (FGAnimation)target;

        if (data.frames.Length > 0)
        {
            if (spriteToShow != null)
            {
                if (spriteToShow.type == FGAnimationStageType.ACTIVE)
                {
                    Texture2D sprite = GenerateTextureFromSprite(spriteToShow.sprite);
                    AddRectToTexture(ref sprite, spriteToShow.hitBox, Color.red);
                    GUILayout.Label(sprite);
                }
                else
                {
                    GUILayout.Label(GenerateTextureFromSprite(spriteToShow.sprite));
                }
            }
        }
        if (play)
        {
            if (GUILayout.Button("Stop"))
            {
                play = false;
                if (anim != null)
                {
                    anim.Reset();
                }
            }
        }
        else
        {
            if (GUILayout.Button("Play"))
            {
                play = true;
                if (anim != null)
                {
                    anim.Reset();
                }
            }

            if (GUILayout.Button("Move To Next Frame"))
            {
                anim.NextFrame((FGAnimation)target);
                spriteToShow = anim.GetCurrent();
            }
            if (GUILayout.Button("Back To Last Frame"))
            {
                anim.LastFrame((FGAnimation)target);
                spriteToShow = anim.GetCurrent();
            }
        }

        if (anim != null)
        {
            GUILayout.Label(new GUIContent("Frame number: " + anim.GetCurrentFrame().ToString()));
        }
    }
Ejemplo n.º 3
0
 //!
 public void AddFrame(FGAnimationKeyFrame frame)
 {
     FGAnimHelper.AddFrame(ref frames);
     frames[frames.Length - 1] = frame;
     for (int i = 0; i < frame.frameCount; i++)
     {
         _frameToKeyFrame.Add(frames.Length - 1);
     }
     totalFrameCount += frame.frameCount;
 }
    void OnEnable()
    {
        EditorAnimator anim = new EditorAnimator();
        FGAnimation    data = (FGAnimation)target;

        play  = false;
        _time = EditorApplication.timeSinceStartup;
        if (data.frames.Length > 0)
        {
            spriteToShow = data.frames[0];
        }
        EditorApplication.update += Update;
    }
Ejemplo n.º 5
0
    //!
    public void UpdateAnimator(float dt)
    {
        bool reset = _animatorTime >= _animations[_currentAnimation].duration;
        bool bounceAnimationReverse = false;

        //check what type of animation we're dealing with
        switch (_animations[_currentAnimation].type)
        {
        case FGAnimationType.BOUNCE:
        case FGAnimationType.LOOP:
            if (reset)
            {
                _animatorTime -= _animations[_currentAnimation].duration;
            }
            break;

        case FGAnimationType.REVERSE:
        case FGAnimationType.ONCE:
            if (reset)
            {
                if (_animations[_currentAnimation].nextAnimation != "")
                {
                    Play(_animations[_currentAnimation].nextAnimation);
                }
                else
                {
                    Play(_defaultAnimation);
                }
            }
            break;
        }

        FGAnimation current      = _animations[_currentAnimation];
        float       adjustedTime = _animatorTime;

        if (current.type == FGAnimationType.REVERSE)
        {
            adjustedTime = current.duration - adjustedTime;
        }

        int currFrame = AnimationPlayer.GetCurrentFrame(_animations[_currentAnimation], adjustedTime);
        FGAnimationKeyFrame keyFrame = _animations[_currentAnimation].GetKeyFrame(currFrame);

        if (_currentKeyFrame != keyFrame)
        {
            ApplyFrame(keyFrame);
        }

        //at end of update, update animator's time
        _animatorTime += dt;
    }
Ejemplo n.º 6
0
    public void LastFrame(FGAnimation animation)
    {
        if ((currentFrame - 1) < 0)
        {
            currentFrame = animation.totalFrameCount - 1;
        }
        else
        {
            currentFrame--;
        }
        FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame);

        ApplyFrame(keyFrame);
    }
Ejemplo n.º 7
0
    public void NextFrame(FGAnimation animation)
    {
        if (animation.totalFrameCount == (currentFrame + 1))
        {
            currentFrame = 0;
        }
        else
        {
            currentFrame++;
        }
        FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame);

        ApplyFrame(keyFrame);
    }
    private void Awake()
    {
        if (anim == null)
        {
            anim = new EditorAnimator();
        }
        FGAnimation data = (FGAnimation)target;

        play  = false;
        _time = EditorApplication.timeSinceStartup;
        if (data.frames.Length > 0)
        {
            spriteToShow = data.frames[0];
        }
    }
Ejemplo n.º 9
0
    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;
         * }*/
    }
Ejemplo n.º 10
0
 public static void AddFrame(ref FGAnimationKeyFrame[] frameList)
 {
     if (frameList == null)
     {
         frameList = new FGAnimationKeyFrame[1];
     }
     else
     {
         FGAnimationKeyFrame[] cpy = new FGAnimationKeyFrame[frameList.Length + 1];
         for (int i = 0; i < frameList.Length; i++)
         {
             cpy[i] = frameList[i];
         }
         frameList = cpy;
     }
     frameList[frameList.Length - 1] = new FGAnimationKeyFrame();
 }
 void Update()
 {
     if (play)
     {
         double currTime = EditorApplication.timeSinceStartup;
         if ((currTime - _time) >= FGAnimationKeyFrame.FrameTime * 2)
         {
             if (anim == null)
             {
                 anim = new EditorAnimator();
             }
             spriteToShow = anim.LoopAnimationPlay((FGAnimation)target, (currTime - _time));
             //call animator update here
             _time = currTime;
             Repaint();
         }
     }
 }
Ejemplo n.º 12
0
 public static void RemoveFrame(ref FGAnimationKeyFrame[] frameList, int index)
 {
     if (frameList != null && index < frameList.Length)
     {
         FGAnimationKeyFrame[] cpy = new FGAnimationKeyFrame[frameList.Length - 1];
         for (int i = 0; i < frameList.Length; i++)
         {
             if (i < index)
             {
                 cpy[i] = frameList[i];
             }
             else if (i > index)
             {
                 cpy[i - 1] = frameList[i];
             }
         }
         frameList = cpy;
     }
 }
Ejemplo n.º 13
0
    //!
    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;
        }
    }
Ejemplo n.º 14
0
 private void ApplyFrame(FGAnimationKeyFrame frame)
 {
     _currentKeyFrame = frame;
 }
Ejemplo n.º 15
0
 public EditorAnimator()
 {
     animatorTimer    = 0;
     _currentKeyFrame = null;
 }
Ejemplo n.º 16
0
 public FGAnimation()
 {
     frames = new FGAnimationKeyFrame[0];
     //positionOffset = Vector2.zero;
 }