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
14
Assets/Scripts/FramedAnimator/Animation.cs
Normal file
14
Assets/Scripts/FramedAnimator/Animation.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace FramedAnimator {
|
||||
[CreateAssetMenu(menuName = "Framed Animation")]
|
||||
public class Animation : ScriptableObject {
|
||||
[SerializeField] private Sprite[] sprites;
|
||||
[SerializeField] private float frameRate;
|
||||
|
||||
public Sprite GetFrame(int frame) => sprites[frame];
|
||||
public int FrameCount => sprites.Length;
|
||||
|
||||
public float FrameRate => frameRate;
|
||||
}
|
||||
}
|
3
Assets/Scripts/FramedAnimator/Animation.cs.meta
Normal file
3
Assets/Scripts/FramedAnimator/Animation.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7e87fbf7a73a4ef496960eb0469f7e88
|
||||
timeCreated: 1713341980
|
|
@ -3,9 +3,8 @@ using UnityEngine;
|
|||
|
||||
namespace FramedAnimator {
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
public class FramedAnimator : MonoBehaviour {
|
||||
[SerializeField] private Sprite[] sprites;
|
||||
[SerializeField] private float frameRate;
|
||||
public class Animator : MonoBehaviour {
|
||||
[SerializeField] private Animation animation;
|
||||
|
||||
private float _currentFrame;
|
||||
private int _renderingFrame;
|
||||
|
@ -20,15 +19,15 @@ namespace FramedAnimator {
|
|||
private void Update() {
|
||||
if (_renderingFrame >= _limit)
|
||||
return;
|
||||
_currentFrame += Time.deltaTime * frameRate;
|
||||
_currentFrame += Time.deltaTime * animation.FrameRate;
|
||||
|
||||
_renderingFrame = Mathf.Clamp(Mathf.FloorToInt(_currentFrame), 0, _limit);
|
||||
_renderer.sprite = sprites[_renderingFrame];
|
||||
_renderer.sprite = animation.GetFrame(_renderingFrame);
|
||||
}
|
||||
|
||||
public void PlayUntil(float fraction) {
|
||||
_limit = Mathf.RoundToInt(sprites.Length * Mathf.Clamp(fraction, 0, 1));
|
||||
_limit = Mathf.Clamp(_limit, 0, sprites.Length - 1);
|
||||
_limit = Mathf.RoundToInt(animation.FrameCount * Mathf.Clamp(fraction, 0, 1));
|
||||
_limit = Mathf.Clamp(_limit, 0, animation.FrameCount - 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ using Presenter;
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Animator = FramedAnimator.Animator;
|
||||
|
||||
namespace View.UI {
|
||||
public class ExpressionInput : MonoBehaviour, IExpressionInput {
|
||||
|
@ -12,7 +13,7 @@ namespace View.UI {
|
|||
private ExpressionClick _click;
|
||||
private CustomInput _customInput;
|
||||
|
||||
[SerializeField] private FramedAnimator.FramedAnimator animator;
|
||||
[SerializeField] private Animator animator;
|
||||
|
||||
private void Start() {
|
||||
_click = FindObjectOfType<Dependencies>().ExpressionClick;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue