feat: delay animation after spawning flower
This commit is contained in:
parent
3522a015f6
commit
bab2db51e5
2 changed files with 15 additions and 7 deletions
|
@ -7,13 +7,13 @@ namespace FramedAnimator {
|
||||||
public class Animator : MonoBehaviour {
|
public class Animator : MonoBehaviour {
|
||||||
[SerializeField] private new Animation animation;
|
[SerializeField] private new Animation animation;
|
||||||
public string CurrentAnimation => animation.name;
|
public string CurrentAnimation => animation.name;
|
||||||
private SpriteRenderer _renderer;
|
public SpriteRenderer Renderer { get; private set; }
|
||||||
|
|
||||||
public event Action<string> OnAnimationEnd;
|
public event Action<string> OnAnimationEnd;
|
||||||
private AnimatorModel _model;
|
private AnimatorModel _model;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
_renderer = GetComponent<SpriteRenderer>();
|
Renderer = GetComponent<SpriteRenderer>();
|
||||||
if(animation)
|
if(animation)
|
||||||
_model = new AnimatorModel(animation.FrameRate, animation.FrameCount);
|
_model = new AnimatorModel(animation.FrameRate, animation.FrameCount);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ namespace FramedAnimator {
|
||||||
|
|
||||||
private void UpdateAnimationFrame() {
|
private void UpdateAnimationFrame() {
|
||||||
_model.UpdateAnimationFrame(Time.deltaTime);
|
_model.UpdateAnimationFrame(Time.deltaTime);
|
||||||
_renderer.sprite = animation.GetFrame(_model.RenderingFrame);
|
Renderer.sprite = animation.GetFrame(_model.RenderingFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TryCallAnimationEnd() {
|
private void TryCallAnimationEnd() {
|
||||||
|
@ -41,7 +41,7 @@ namespace FramedAnimator {
|
||||||
public void ChangeAnimation(Animation anim) {
|
public void ChangeAnimation(Animation anim) {
|
||||||
_model = new AnimatorModel(anim.FrameRate, anim.FrameCount);
|
_model = new AnimatorModel(anim.FrameRate, anim.FrameCount);
|
||||||
animation = anim;
|
animation = anim;
|
||||||
_renderer.sprite = animation.GetFrame(0);
|
Renderer.sprite = animation.GetFrame(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayUntil(float fraction) {
|
public void PlayUntil(float fraction) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using Domain;
|
using Domain;
|
||||||
using FMODUnity;
|
using FMODUnity;
|
||||||
using Presenter;
|
using Presenter;
|
||||||
|
@ -20,7 +21,7 @@ namespace View.Scene {
|
||||||
private SpawnRose _spawnRose;
|
private SpawnRose _spawnRose;
|
||||||
private bool _firstUpdate = true;
|
private bool _firstUpdate = true;
|
||||||
|
|
||||||
public bool Growing { private set; get; } = true;
|
public bool Growing { private set; get; }
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
_score = FindObjectOfType<Dependencies>().Score;
|
_score = FindObjectOfType<Dependencies>().Score;
|
||||||
|
@ -41,8 +42,7 @@ namespace View.Scene {
|
||||||
|
|
||||||
if (animationName == "Rosa_End") {
|
if (animationName == "Rosa_End") {
|
||||||
_spawnRose.Execute();
|
_spawnRose.Execute();
|
||||||
animator.ChangeAnimation(startAnimation);
|
StartCoroutine(RestartCycle());
|
||||||
animator.PlayUntil(1f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animationName == "Rosa_Start") {
|
if (animationName == "Rosa_Start") {
|
||||||
|
@ -52,6 +52,14 @@ namespace View.Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerator RestartCycle() {
|
||||||
|
animator.Renderer.enabled = false;
|
||||||
|
yield return new WaitForSeconds(2f);
|
||||||
|
animator.Renderer.enabled = true;
|
||||||
|
animator.ChangeAnimation(startAnimation);
|
||||||
|
animator.PlayUntil(1f);
|
||||||
|
}
|
||||||
|
|
||||||
public void GrowStep() {
|
public void GrowStep() {
|
||||||
if (animator.CurrentAnimation == "Rosa_Grow") {
|
if (animator.CurrentAnimation == "Rosa_Grow") {
|
||||||
if (IsLastGrowState())
|
if (IsLastGrowState())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue