SHADE_Y3/Assets/Scripts/UI/SC_SceneFadeInOut.cs

78 lines
1.9 KiB
C#
Raw Normal View History

2023-02-27 15:28:05 +08:00
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.UI
{
public class SceneFadeInOut : Script
{
2023-02-28 06:49:40 +08:00
[Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
2023-02-27 15:28:05 +08:00
public bool fadeIn;
2023-02-28 06:49:40 +08:00
[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
2023-02-27 15:28:05 +08:00
public bool fadeOut;
2023-02-28 06:49:40 +08:00
[Tooltip("The alpha value of the UI that is faded. Between 0 and 1 inclusive.")]
2023-02-27 15:28:05 +08:00
public float alphaValue;
[SerializeField]
private float fadeInRate;
[SerializeField]
private float fadeOutRate;
private Renderable fadeR;
2023-02-28 06:49:40 +08:00
public static SceneFadeInOut Instance { get; private set; }
2023-02-27 15:28:05 +08:00
protected override void awake()
{
2023-02-28 06:49:40 +08:00
if (Instance != null && Instance != this)
RemoveScript<SceneFadeInOut>();
else
Instance = this;
fadeR = GameObject.GetComponent<Renderable>();
fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
//alphaValue = fadeR.Material.GetProperty<float>("data.alpha");
2023-02-27 15:28:05 +08:00
}
protected override void start()
{
}
protected override void update()
{
if (fadeR != null)
{
if (fadeIn) //fading in
{
2023-02-28 06:49:40 +08:00
fadeOut = false;
2023-02-27 15:28:05 +08:00
alphaValue += fadeInRate * Time.DeltaTimeF;
if (alphaValue >= 1.0f) alphaValue = 1.0f;
}
if (fadeOut) //fading out
{
2023-02-28 06:49:40 +08:00
fadeIn = false;
2023-02-27 15:28:05 +08:00
alphaValue -= fadeOutRate * Time.DeltaTimeF;
if (alphaValue <= 0.0f) alphaValue = 0.0f;
}
fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
}
}
2023-02-28 06:49:40 +08:00
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
2023-02-27 15:28:05 +08:00
}
}