Implemented Fade In To and Fade Out From Black Scene Transitions #378
|
@ -1,10 +1,19 @@
|
|||
using System;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using SHADE;
|
||||
using SHADE_Scripting.UI;
|
||||
|
||||
public class ChangeSceneButton : Script
|
||||
{
|
||||
public uint sceneID = 0;
|
||||
|
||||
|
||||
//Whether the scene changing button has been clicked
|
||||
private bool clickedFlag;
|
||||
|
||||
protected override void awake()
|
||||
{
|
||||
clickedFlag = false;
|
||||
}
|
||||
|
||||
protected override void start()
|
||||
{
|
||||
|
@ -17,8 +26,12 @@ public class ChangeSceneButton : Script
|
|||
if (sceneID != 0)
|
||||
{
|
||||
Audio.PlaySFXOnce2D("event:/UI/success");
|
||||
SceneManager.ChangeScene(sceneID);
|
||||
|
||||
Audio.StopAllSounds();
|
||||
|
||||
SceneFadeInOut.Instance.fadeOut = false;
|
||||
SceneFadeInOut.Instance.fadeIn = true;
|
||||
clickedFlag = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -30,6 +43,9 @@ public class ChangeSceneButton : Script
|
|||
}
|
||||
protected override void update()
|
||||
{
|
||||
|
||||
if (clickedFlag && sceneID != 0 && SceneFadeInOut.Instance.alphaValue >= 1.0f)
|
||||
{
|
||||
SceneManager.ChangeScene(sceneID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,13 @@ 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")]
|
||||
[Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
|
||||
public bool fadeIn;
|
||||
|
||||
[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading")]
|
||||
[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
|
||||
public bool fadeOut;
|
||||
|
||||
[Tooltip("The alpha value of the UI that is faded")]
|
||||
[Tooltip("The alpha value of the UI that is faded. Between 0 and 1 inclusive.")]
|
||||
public float alphaValue;
|
||||
|
||||
[SerializeField]
|
||||
|
@ -29,10 +26,18 @@ namespace SHADE_Scripting.UI
|
|||
|
||||
private Renderable fadeR;
|
||||
|
||||
public static SceneFadeInOut Instance { get; private set; }
|
||||
|
||||
protected override void awake()
|
||||
{
|
||||
fadeR = fadeUI.GetComponent<Renderable>();
|
||||
alphaValue = fadeR.Material.GetProperty<float>("data.alpha");
|
||||
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()
|
||||
|
@ -46,12 +51,14 @@ namespace SHADE_Scripting.UI
|
|||
{
|
||||
if (fadeIn) //fading in
|
||||
{
|
||||
fadeOut = false;
|
||||
alphaValue += fadeInRate * Time.DeltaTimeF;
|
||||
if (alphaValue >= 1.0f) alphaValue = 1.0f;
|
||||
}
|
||||
|
||||
if (fadeOut) //fading out
|
||||
{
|
||||
fadeIn = false;
|
||||
alphaValue -= fadeOutRate * Time.DeltaTimeF;
|
||||
if (alphaValue <= 0.0f) alphaValue = 0.0f;
|
||||
}
|
||||
|
@ -59,5 +66,12 @@ namespace SHADE_Scripting.UI
|
|||
fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void onDestroy()
|
||||
{
|
||||
if (Instance == this)
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue