Beispiel #1
0
 private void AnimationStateChangeEListener(AnimationStateChnage state)
 {
     if (state.Equals(AnimationStateChnage.End) && spriteAni != null)
     {
         spriteAni.spriteRendere.color  = Color.white;
         spriteAni.spriteRendere.sprite = null;
         //
         SpriteAnimations.transform.parent      = ObjParent;
         SpriteAnimations.transform.position    = Vector3.zero;
         SpriteAnimations.transform.eulerAngles = Vector3.zero;
         SpriteAnimations.SetActive(false);
     }
 }
Beispiel #2
0
        // Update is called once per frame
        void Update()
        {
            if (status != AnimationState.Play || _curAni == null || aniIndex.Equals(-1))
            {
                //MyDebug.Log("Animation return ST: " + status + ", aniIndex: " + aniIndex + ", isNull: " + (_curAni == null));
                return;
            }
            _timeMoved += ((_curAni.IsIgnoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime) * _speed);

            _hold = (1f / _curAni.FPS);
            if (_timeMoved >= _hold)
            {
                switch (_curAni.AType)
                {
                case AnimationType.Once:
                    //MyDebug.Log("Animation Frame Changed");
                    _index++;
                    if (runWith.Equals(RunWith.Sprite))
                    {
                        //MyDebug.Log("Animation Sprite Change");
                        _index = Mathf.Clamp(_index, 0, _curAni.Sprites.Count);
                        if (_index >= _curAni.Sprites.Count)
                        {
                            _index = _curAni.Sprites.Count - 1;
                            Stop();
                            OnAnimationStateChange(AnimationStateChnage.End);
                            return;
                        }
                    }
                    else if (runWith.Equals(RunWith.Texture2D))
                    {
                        _index = Mathf.Clamp(_index, 0, _curAni.Textures.Count);
                        if (_index >= _curAni.Textures.Count)
                        {
                            _index = _curAni.Textures.Count - 1;
                            Stop();
                            OnAnimationStateChange(AnimationStateChnage.End);
                            return;
                        }
                    }
                    break;

                case AnimationType.Loop:
                    _index++;
                    if (runWith.Equals(RunWith.Sprite))
                    {
                        if (_index >= _curAni.Sprites.Count)
                        {
                            OnAnimationStateChange(AnimationStateChnage.LoopStartAgain);
                            _index = 0;
                        }
                    }
                    else if (runWith.Equals(RunWith.Texture2D))
                    {
                        if (_index >= _curAni.Textures.Count)
                        {
                            OnAnimationStateChange(AnimationStateChnage.LoopStartAgain);
                            _index = 0;
                        }
                    }
                    break;

                case AnimationType.PingPong:
                    _index += _direction;
                    if (runWith.Equals(RunWith.Sprite) && _index >= (_curAni.Sprites.Count - 1))
                    {
                        _direction = -1;
                        OnAnimationStateChange(AnimationStateChnage.PingPongChange);
                    }
                    else if (runWith.Equals(RunWith.Texture2D) && _index >= (_curAni.Textures.Count - 1))
                    {
                        _direction = -1;
                        OnAnimationStateChange(AnimationStateChnage.PingPongChange);
                    }
                    if (_index <= 0)
                    {
                        _direction = 1;
                        OnAnimationStateChange(AnimationStateChnage.PingPongChange);
                    }
                    break;
                }
                _timeMoved = 0;
                if (!_lstAnimationStateChnage.Equals(AnimationStateChnage.Playing))
                {
                    OnAnimationStateChange(AnimationStateChnage.Playing);
                }
                SetFrame();
            }
        }