64 lines
1.4 KiB
C#
64 lines
1.4 KiB
C#
|
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
|
|||
|
{
|
|||
|
[SerializeField]
|
|||
|
private GameObject fadeUI;
|
|||
|
|
|||
|
[Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading")]
|
|||
|
public bool fadeIn;
|
|||
|
|
|||
|
[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading")]
|
|||
|
public bool fadeOut;
|
|||
|
|
|||
|
[Tooltip("The alpha value of the UI that is faded")]
|
|||
|
public float alphaValue;
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private float fadeInRate;
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private float fadeOutRate;
|
|||
|
|
|||
|
private Renderable fadeR;
|
|||
|
|
|||
|
protected override void awake()
|
|||
|
{
|
|||
|
fadeR = fadeUI.GetComponent<Renderable>();
|
|||
|
alphaValue = fadeR.Material.GetProperty<float>("data.alpha");
|
|||
|
}
|
|||
|
|
|||
|
protected override void start()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
protected override void update()
|
|||
|
{
|
|||
|
if (fadeR != null)
|
|||
|
{
|
|||
|
if (fadeIn) //fading in
|
|||
|
{
|
|||
|
alphaValue += fadeInRate * Time.DeltaTimeF;
|
|||
|
if (alphaValue >= 1.0f) alphaValue = 1.0f;
|
|||
|
}
|
|||
|
|
|||
|
if (fadeOut) //fading out
|
|||
|
{
|
|||
|
alphaValue -= fadeOutRate * Time.DeltaTimeF;
|
|||
|
if (alphaValue <= 0.0f) alphaValue = 0.0f;
|
|||
|
}
|
|||
|
|
|||
|
fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|