feat: Rose grow animation
This commit is contained in:
parent
f8a29f1501
commit
438b16fc6e
9 changed files with 186 additions and 4 deletions
|
@ -2,19 +2,19 @@
|
|||
public class Model {
|
||||
public int Score { private set; get; }
|
||||
|
||||
private readonly int _spawnRate;
|
||||
public readonly int SpawnRate;
|
||||
private bool _needsToSpawn;
|
||||
|
||||
public Model(int spawnRate) : this(0, spawnRate) { }
|
||||
|
||||
public Model(int score, int spawnRate) {
|
||||
Score = score;
|
||||
_spawnRate = spawnRate;
|
||||
SpawnRate = spawnRate;
|
||||
}
|
||||
|
||||
public void AddScore() {
|
||||
Score++;
|
||||
if (Score % _spawnRate == 0)
|
||||
if (Score % SpawnRate == 0)
|
||||
_needsToSpawn = true;
|
||||
}
|
||||
|
||||
|
|
8
Assets/Scripts/FramedAnimator.meta
Normal file
8
Assets/Scripts/FramedAnimator.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d81a90acdb9fe6e4a87e77d9d47f5042
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/FramedAnimator/FramedAnimator.cs
Normal file
34
Assets/Scripts/FramedAnimator/FramedAnimator.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FramedAnimator {
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
public class FramedAnimator : MonoBehaviour {
|
||||
[SerializeField] private Sprite[] sprites;
|
||||
[SerializeField] private float frameRate;
|
||||
|
||||
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 * frameRate;
|
||||
|
||||
_renderingFrame = Mathf.Clamp(Mathf.FloorToInt(_currentFrame), 0, _limit);
|
||||
_renderer.sprite = sprites[_renderingFrame];
|
||||
}
|
||||
|
||||
public void PlayUntil(float fraction) {
|
||||
_limit = Mathf.RoundToInt(sprites.Length * Mathf.Clamp(fraction, 0, 1));
|
||||
_limit = Mathf.Clamp(_limit, 0, sprites.Length - 1);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/FramedAnimator/FramedAnimator.cs.meta
Normal file
3
Assets/Scripts/FramedAnimator/FramedAnimator.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 944498bf314d45ceb21a77b6ec4b0cfb
|
||||
timeCreated: 1713199370
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "SantJordi.FramedAnimator"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 246088dd927065946b1746223fef2142
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -6,7 +6,8 @@
|
|||
"GUID:d9011953b32919841a6c357880a50fb3",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:1220ccfff01d26041a9bb8cd7ae584af",
|
||||
"GUID:58f2f98b0cec4e74998cb65ad59190b4"
|
||||
"GUID:58f2f98b0cec4e74998cb65ad59190b4",
|
||||
"GUID:246088dd927065946b1746223fef2142"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
@ -3,14 +3,21 @@ using Domain.Input;
|
|||
using Presenter;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace View.UI {
|
||||
public class ExpressionInput : MonoBehaviour, IExpressionInput {
|
||||
[SerializeField] private TMP_Text text;
|
||||
|
||||
private ExpressionClick _click;
|
||||
private CustomInput _customInput;
|
||||
private Model _model;
|
||||
|
||||
[SerializeField] private FramedAnimator.FramedAnimator animator;
|
||||
|
||||
private void Start() {
|
||||
_model = FindObjectOfType<Dependencies>().Model;
|
||||
|
||||
_click = FindObjectOfType<Dependencies>().ExpressionClick;
|
||||
_customInput = FindObjectOfType<Dependencies>().CustomInput;
|
||||
}
|
||||
|
@ -43,6 +50,9 @@ namespace View.UI {
|
|||
}
|
||||
|
||||
public void UpdateView(int score) {
|
||||
int frameDifference = score % _model.SpawnRate;
|
||||
animator.PlayUntil(frameDifference / (float)_model.SpawnRate);
|
||||
|
||||
text.text = score.ToString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue