You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.9 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SnowFlakeLogo : SnowFlake
{
[AutoUI] public float AppearTime = 3;
[SerializeField] private float _appearTimer;
public const string DisnyLogo = "DisnyLogo";
private RawImage _image;
// Start is called before the first frame update
new void Awake()
{
base.Awake();
_image = GetComponent<RawImage>();
}
// Update is called once per frame
new void Update()
{
base.Update();
if (IsPlay)
CheckLogoTime();
}
void CheckLogoTime()
{
var infoState = _animator.GetCurrentAnimatorStateInfo(0);
if (infoState.normalizedTime < 1)
return;
if(infoState.IsName(DisnyLogo))
{
_appearTimer -= Time.deltaTime;
if(_appearTimer < 0 && FadeOut == null && _image.color.a == 1)
{
FadeOut = StartCoroutine(Fade(0));
}
}
}
public override void CheckPlayEnd()
{
if (_animator.GetCurrentAnimatorStateInfo(0).IsName(End))
{
Reset();
}
}
public override void PlayAnimation()
{
base.PlayAnimation();
_appearTimer = AppearTime;
StartCoroutine(Fade(1));
//_image.color = Color.white;
_image.enabled = true;
}
Coroutine FadeOut;
IEnumerator Fade(float target)
{
float value = _image.color.a;
Color color = _image.color;
while(value != target)
{
value += target > value ? Time.deltaTime: -Time.deltaTime;
value = Mathf.Clamp(value, 0, 1);
color.a = value;
_image.color = color;
yield return null;
}
if (target == 0)
{
_image.texture = null;
FadeOut = null;
_animator.SetTrigger("Fade");
}
}
}