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.

55 lines
1.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UltraCombos
{
public class ImageFader : MonoBehaviour
{
CanvasGroup canvas_group;
float fade_stamp;
AnimationCurve curve;
bool is_active = true;
const float fading = 0.3f;
const float eps = 0.5f / 255.0f;
private void Start()
{
canvas_group = GetComponent<CanvasGroup>();
if (canvas_group == null)
canvas_group = gameObject.AddComponent<CanvasGroup>();
canvas_group.alpha = 1.0f;
curve = AnimationCurve.EaseInOut(0, 0, 1, 1);
SetActive(false);
}
private void FixedUpdate()
{
float a = canvas_group.alpha;
float b = is_active ? 1 : 0;
if (Mathf.Abs(a - b) < eps)
{
canvas_group.alpha = b;
}
else
{
float t = Time.fixedDeltaTime * 8.0f;
canvas_group.alpha = Mathf.Lerp(a, b, t);
}
}
public void SetActive(bool value)
{
fade_stamp = Time.time;
is_active = canvas_group.blocksRaycasts = canvas_group.interactable = value;
}
}
}