119 lines
2.6 KiB
C#
119 lines
2.6 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
|
|
{
|
|
//[Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
|
|
private bool fadeIn;
|
|
|
|
//[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
|
|
private bool fadeOut;
|
|
|
|
[Tooltip("The initial alpha value of the UI that is faded. Between 0 and 1 inclusive.")]
|
|
public float alphaValue;
|
|
|
|
[SerializeField]
|
|
private float fadeInTime;
|
|
|
|
[SerializeField]
|
|
private float fadeOutTime;
|
|
|
|
private Renderable fadeR;
|
|
|
|
public static SceneFadeInOut Instance { get; private set; }
|
|
|
|
protected override void awake()
|
|
{
|
|
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");
|
|
}
|
|
|
|
protected override void start()
|
|
{
|
|
CallFadeOut();
|
|
}
|
|
|
|
protected override void update()
|
|
{
|
|
if (fadeR != null)
|
|
{
|
|
if (fadeIn) //fading in
|
|
{
|
|
fadeOut = false;
|
|
if (fadeInTime == 0.0f)
|
|
{
|
|
alphaValue = 1.0f;
|
|
}
|
|
else
|
|
{
|
|
alphaValue += (1.0f / fadeInTime) * Time.DeltaTimeF;
|
|
}
|
|
if (alphaValue >= 1.0f) alphaValue = 1.0f;
|
|
}
|
|
|
|
if (fadeOut) //fading out
|
|
{
|
|
fadeIn = false;
|
|
if (fadeOutTime == 0.0f)
|
|
{
|
|
alphaValue = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
alphaValue -= (1.0f / fadeOutTime) * Time.DeltaTimeF;
|
|
}
|
|
if (alphaValue <= 0.0f) alphaValue = 0.0f;
|
|
}
|
|
|
|
fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
|
|
}
|
|
}
|
|
|
|
protected override void onDestroy()
|
|
{
|
|
if (Instance == this)
|
|
Instance = null;
|
|
}
|
|
|
|
public void CallFadeIn()
|
|
{
|
|
fadeIn = true;
|
|
fadeOut = false;
|
|
}
|
|
|
|
public void CallFadeOut()
|
|
{
|
|
fadeOut = true;
|
|
fadeIn = false;
|
|
}
|
|
|
|
public void CallFadeStop()
|
|
{
|
|
fadeOut = false;
|
|
fadeIn = false;
|
|
}
|
|
|
|
public bool FadeOutFinished()
|
|
{
|
|
return (alphaValue <= 0.0f);
|
|
}
|
|
|
|
public bool FadeInFinished()
|
|
{
|
|
return (alphaValue >= 1.0f);
|
|
}
|
|
}
|
|
}
|