feat: End animation working
This commit is contained in:
parent
e74c68082e
commit
be7d37c6d4
70 changed files with 138 additions and 73 deletions
|
@ -4,6 +4,7 @@ using Presenter;
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Animation = FramedAnimator.Animation;
|
||||
using Animator = FramedAnimator.Animator;
|
||||
|
||||
namespace View.UI {
|
||||
|
@ -12,12 +13,33 @@ namespace View.UI {
|
|||
|
||||
private ExpressionClick _click;
|
||||
private CustomInput _customInput;
|
||||
private Score _score;
|
||||
|
||||
private bool _firstUpdate = true;
|
||||
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private Animation growAnimation;
|
||||
[SerializeField] private Animation endAnimation;
|
||||
|
||||
private void Start() {
|
||||
_click = FindObjectOfType<Dependencies>().ExpressionClick;
|
||||
_customInput = FindObjectOfType<Dependencies>().CustomInput;
|
||||
_score = FindObjectOfType<Dependencies>().Score;
|
||||
|
||||
animator.OnAnimationEnd += AnimationEnded;
|
||||
}
|
||||
|
||||
private void AnimationEnded(string animationName) {
|
||||
if (animationName == "Rosa_Grow") {
|
||||
animator.ChangeAnimation(endAnimation);
|
||||
animator.PlayUntil(1f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (animationName == "Rosa_End") {
|
||||
animator.ChangeAnimation(growAnimation);
|
||||
animator.PlayUntil(_score.GrowPercentage);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
|
@ -25,8 +47,22 @@ namespace View.UI {
|
|||
}
|
||||
|
||||
public void UpdateView(int score, float growPercentage) {
|
||||
animator.PlayUntil(growPercentage);
|
||||
if (animator.CurrentAnimation == "Rosa_Grow") {
|
||||
animator.PlayUntil(IsLastGrowState(score, growPercentage) ? 1f : growPercentage);
|
||||
}
|
||||
text.text = score.ToString();
|
||||
_firstUpdate = false;
|
||||
}
|
||||
|
||||
private bool IsLastGrowState(int score, float growPercentage) {
|
||||
if (growPercentage != 0)
|
||||
return false;
|
||||
bool isLastFrame = score % (_score.GrowIterations * _score.SpawnRate) == 0;
|
||||
if (!isLastFrame)
|
||||
return false;
|
||||
if (_firstUpdate)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckInput() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue