feat: framed animator working with scriptable objects
This commit is contained in:
parent
339b62faf7
commit
5b60d9aa2c
144 changed files with 9496 additions and 110 deletions
33
Assets/Scripts/FramedAnimator/Animator.cs
Normal file
33
Assets/Scripts/FramedAnimator/Animator.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FramedAnimator {
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
public class Animator : MonoBehaviour {
|
||||
[SerializeField] private Animation animation;
|
||||
|
||||
private float _currentFrame;
|
||||
private int _renderingFrame;
|
||||
private int _limit;
|
||||
|
||||
private SpriteRenderer _renderer;
|
||||
|
||||
private void Awake() {
|
||||
_renderer = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if (_renderingFrame >= _limit)
|
||||
return;
|
||||
_currentFrame += Time.deltaTime * animation.FrameRate;
|
||||
|
||||
_renderingFrame = Mathf.Clamp(Mathf.FloorToInt(_currentFrame), 0, _limit);
|
||||
_renderer.sprite = animation.GetFrame(_renderingFrame);
|
||||
}
|
||||
|
||||
public void PlayUntil(float fraction) {
|
||||
_limit = Mathf.RoundToInt(animation.FrameCount * Mathf.Clamp(fraction, 0, 1));
|
||||
_limit = Mathf.Clamp(_limit, 0, animation.FrameCount - 1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue