Exemplo n.º 1
0
        private void DrawFrame()
        {
            // --------------------------------------------------------------------------------
            // Draw the current frame
            // --------------------------------------------------------------------------------
            if (_currentFrame < 0 || _currentFrame >= _animationData.spriteSource.Length)
            {
                throw new Exception($"animation {_animationData.name} (startFrameIndex [{_animationData.GetRange().x}]/lastFrameIndex [{_animationData.GetRange().y}]) out of range  [{_animationData.spriteSource.Length}]!");
            }

            TargetRenderer.sprite = _animationData.spriteSource[_currentFrame];

            if (_animationData.updateColliderSize)
            {
                UpdateCollider();
            }

            // --------------------------------------------------------------------------------
            // Play sfx (concrete frame)
            // --------------------------------------------------------------------------------
            if (!_animationData.perFrame && _animationData.concreteFrame != 0 && _animationData.concreteFrame == _currentFrame && _animationData.sfx != SoundList.None)
            {
                SystemFacade.Sounds.PlaySfx(_animationData.sfx);
            }

            // --------------------------------------------------------------------------------
            // Play sfx (per frame)
            // --------------------------------------------------------------------------------
            if (_animationData.perFrame && _animationData.sfx != SoundList.None)
            {
                SystemFacade.Sounds.PlaySfx(_animationData.sfx);
            }
        }
Exemplo n.º 2
0
        public void PLay(AnimationData inData)
        {
            if (_animationData == inData)
            {
                throw new Exception($"Animation Data must be not null !");
            }

            _animationData = inData;
            _currentFrame  = _animationData.GetRange().x;
            _frameDuration = _animationData.duration / _animationData.spriteSource.Length;
            _timeCounter   = 0f;

            DrawFrame();

            // --------------------------------------------------------------------------------
            // Play sfx (per loop)
            // --------------------------------------------------------------------------------
            if (!_animationData.perFrame && _animationData.concreteFrame == 0 && _animationData.sfx != SoundList.None)
            {
                SystemFacade.Sounds.PlaySfx(_animationData.sfx);
            }

            _isRun = true;
            OnPlayEvent?.Invoke(this._animationData);
        }