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.
146 lines
3.4 KiB
146 lines
3.4 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FlakeIcon : SnowFlake
|
|
{
|
|
|
|
public enum IconState
|
|
{
|
|
Spwan,
|
|
SpwanFinished,
|
|
Disappear,
|
|
DisappearFinished,
|
|
Video,
|
|
End,
|
|
Reset,
|
|
}
|
|
|
|
public IconState State;
|
|
public AnimationCurve SpawnCurve;
|
|
public AnimationCurve DisappearCurve;
|
|
public float SpwanSpeed = 1;
|
|
public float DisappearSpeed = 1;
|
|
private RawImage Img;
|
|
private RectTransform rectTransform;
|
|
public float FlakeWaitTime = 1;
|
|
|
|
private new void Awake()
|
|
{
|
|
base.Awake();
|
|
Img = GetComponent<RawImage>();
|
|
rectTransform = GetComponent<RectTransform>();
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (_animator.GetCurrentAnimatorStateInfo(0).IsName(End) && State == IconState.Video)
|
|
{
|
|
State = IconState.End;
|
|
StartCoroutine(EndFade());
|
|
}
|
|
|
|
}
|
|
|
|
IEnumerator EndFade()
|
|
{
|
|
float time = 1;
|
|
Color color = Img.color;
|
|
while (time > 0)
|
|
{
|
|
time = Mathf.Max(0, time - Time.deltaTime);
|
|
color.a = time;
|
|
Img.color = color;
|
|
yield return null;
|
|
}
|
|
Reset();
|
|
}
|
|
|
|
|
|
public override void PlayAnimation()
|
|
{
|
|
State = IconState.Spwan;
|
|
StartCoroutine(GoSpawn());
|
|
}
|
|
|
|
IEnumerator GoSpawn()
|
|
{
|
|
_animator.SetTrigger("Play");
|
|
rectTransform.sizeDelta = Vector2.one * _snowFlakeBehaviour.IconSize;
|
|
float time = 0;
|
|
float value = SpawnCurve.Evaluate(time);
|
|
|
|
rectTransform.localScale = Vector3.one * value;
|
|
var color = Img.color;
|
|
color.a = value;
|
|
Img.color = color;
|
|
while (time < 1)
|
|
{
|
|
time = Mathf.Min(1, time + SpwanSpeed * Time.deltaTime);
|
|
value = SpawnCurve.Evaluate(time);
|
|
rectTransform.localScale = Vector3.one * value;
|
|
color.a = value;
|
|
Img.color = color;
|
|
yield return null;
|
|
}
|
|
State = IconState.SpwanFinished;
|
|
}
|
|
|
|
public override void Trigger()
|
|
{
|
|
if (State != IconState.SpwanFinished)
|
|
return;
|
|
State = IconState.Disappear;
|
|
StartCoroutine(GoDisappear());
|
|
}
|
|
|
|
IEnumerator GoDisappear()
|
|
{
|
|
float time = 1;
|
|
float value = SpawnCurve.Evaluate(time);
|
|
|
|
rectTransform.localScale = Vector3.one * value;
|
|
var color = Img.color;
|
|
color.a = value;
|
|
Img.color = color;
|
|
while (time > 0)
|
|
{
|
|
time = Mathf.Max(0, time - DisappearSpeed * Time.deltaTime);
|
|
value = SpawnCurve.Evaluate(time);
|
|
rectTransform.localScale = Vector3.one * value;
|
|
color.a = value;
|
|
Img.color = color;
|
|
yield return null;
|
|
}
|
|
|
|
State = IconState.DisappearFinished;
|
|
rectTransform.sizeDelta = Vector2.one * _snowFlakeBehaviour.FlakeSize;
|
|
_animator.SetTrigger("Flake");
|
|
|
|
yield return null;
|
|
|
|
State = IconState.Video;
|
|
|
|
Img.color = Color.white;
|
|
rectTransform.localScale = Vector3.one;
|
|
|
|
yield return new WaitForSeconds(FlakeWaitTime);
|
|
}
|
|
|
|
public override void Reset()
|
|
{
|
|
State = IconState.Reset;
|
|
_snowFlakeBehaviour.ResetFlake();
|
|
_animator.SetTrigger("Play");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|