private void SetupAnimation() { _animator.CurrentAnimation = _animation; _animator.FrameIndex = 0; _renderer?.Flip(_animNode.ForceReverse); UpdateFrame(_animation.GetFrame(0)); UpdateSprite(); }
private void DrawWithCamera(Camera cam) { if (!cam) { return; } if (_animation == null || _sprite == null) { return; } if (_mesh == null) { _mesh = ProceduralMeshUtility.GenerateQuad(new Vector2(20.48f, 10.24f), new Vector2(0.5f, 0)); } if (_sprite != null) { DrawSprite(); return; } if (!_drawTimer.IsActive) { _frame++; if (_frame >= _animation.Frames.Length) { _frame = 0; } _drawTimer.StartNewTime(_animation.FrameTime * _animation.GetFrame(_frame).Length); } var sprite = _animation.GetSprite(_frame); var matBlock = new MaterialPropertyBlock(); matBlock.SetTexture(_shaderPropertyTexture, sprite.texture); matBlock.SetTexture(_shaderPropertyNormal, _animation.NormalMap); matBlock.SetFloat(_shaderPropertyEmissivePower, _animation.EmissiveMap != null ? 1 : 0); if (_animation.EmissiveMap != null) { matBlock.SetTexture(_shaderPropertyEmissive, _animation.EmissiveMap); } matBlock.SetColor(_shaderPropertyColor, Color.white); matBlock.SetVector(_shaderPropertyUv, SpriteRenderingSystem.GetUv(sprite)); Graphics.DrawMesh(_mesh, GetMatrix(), _mat, 0, null, 0, matBlock, ShadowCastingMode.On); }
private Sprite GetCurrentSprite() { if (_nextFrameTime < _currentTime) { _frame++; if (_frame >= _animation.LengthFrames) { _frame = 0; } _nextFrameTime = _currentTime + (_animation.FrameTime * _animation.GetFrame(_frame).Length); } return(_animation.GetSprite(_frame)); }