using System.Collections; using System.Collections.Generic; using UnityEngine; using UltraCombos; using UnityEngine.UI; public class SnowFlake : MonoBehaviour { [SerializeField] protected Animator _animator; public SnowFlakeBehaviour _snowFlakeBehaviour; protected const string End = "End"; protected const string Spwan = "Snowflake_Spawn"; public bool IsPlay { get; protected set; } public AudioSource AudioSource; private const float audioDelayTime = 0.5f; public OverlayVfx OverlayVfx; public RawImage VfxImg; [SerializeField] private DShowMoviePlayer _vfxVideo; protected void Awake() { _animator = GetComponent(); AudioSource = GetComponent(); VfxImg.enabled = false; } // Update is called once per frame protected void Update() { if(IsPlay) { CheckPlayEnd(); } if(_vfxVideo != null) { VfxImg.texture = _vfxVideo.Texture; } } public virtual void CheckPlayEnd() { if (_animator.GetCurrentAnimatorStateInfo(0).IsName(End)) { Reset(); } } public virtual void PlayAnimation() { _animator.SetTrigger("Play"); _animator.SetBool("Play",true); IsPlay = true; } public virtual void Trigger() { if (_animator.GetCurrentAnimatorStateInfo(0).IsName(Spwan) == false) return; if (_animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1) return; _animator.SetBool("Play", false); _animator.SetTrigger("Trigger"); if(_vfxVideo == null) OverlayVfx.Take(out _vfxVideo); StartCoroutine(WaitToDelay()); } IEnumerator WaitToDelay() { yield return new WaitForSeconds(audioDelayTime); AudioSource?.Play(); yield return new WaitForSeconds(0.5f); if (_vfxVideo!= null) { _vfxVideo.Play(); VfxImg.texture = _vfxVideo.Texture; VfxImg.enabled = true; } } public virtual void Reset() { _animator.SetBool("Play", false); _animator.SetTrigger("Reset"); _snowFlakeBehaviour.ResetFlake(); IsPlay = false; if(_vfxVideo != null) { OverlayVfx.Put(_vfxVideo); _vfxVideo = null; VfxImg.enabled = false; } } }