2023-03-03 16:46:54 +08:00
|
|
|
using SHADE;
|
2023-03-02 16:26:49 +08:00
|
|
|
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);
|
|
|
|
GameObject.Parent.SetActive(false);
|
|
|
|
//alphaValue = fadeR.Material.GetProperty<float>("data.alpha");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void start()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-03-02 15:47:00 +08:00
|
|
|
alphaValue = 1.0f;
|
|
|
|
//GameObject.Parent.SetActive(false);
|
2023-03-02 16:26:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fadeOut) //fading out
|
|
|
|
{
|
|
|
|
fadeIn = false;
|
|
|
|
if (fadeOutTime == 0.0f)
|
|
|
|
{
|
|
|
|
alphaValue = 0.0f;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
alphaValue -= (1.0f / fadeOutTime) * Time.DeltaTimeF;
|
|
|
|
}
|
|
|
|
if (alphaValue <= 0.0f)
|
|
|
|
{
|
2023-03-02 15:47:00 +08:00
|
|
|
alphaValue = 0.0f;
|
|
|
|
//This line is to be added so that (because the fade in and out item is usually the front-most UI element)
|
|
|
|
//the fade in and out UI element does not block functionality of other UI elements
|
|
|
|
GameObject.Parent.SetActive(false);
|
2023-03-02 16:26:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void onDestroy()
|
|
|
|
{
|
|
|
|
if (Instance == this)
|
|
|
|
Instance = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CallFadeIn()
|
|
|
|
{
|
|
|
|
fadeIn = true;
|
|
|
|
fadeOut = false;
|
|
|
|
GameObject.Parent.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CallFadeOut()
|
|
|
|
{
|
|
|
|
fadeOut = true;
|
|
|
|
fadeIn = false;
|
|
|
|
GameObject.Parent.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CallFadeStop()
|
|
|
|
{
|
|
|
|
fadeOut = false;
|
|
|
|
fadeIn = false;
|
|
|
|
GameObject.Parent.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool FadeOutFinished()
|
|
|
|
{
|
|
|
|
return (alphaValue <= 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool FadeInFinished()
|
|
|
|
{
|
|
|
|
return (alphaValue >= 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|