implementing in progress

This commit is contained in:
mushgunAX 2023-02-28 06:49:40 +08:00
parent c328672286
commit b3ec2fb4df
2 changed files with 41 additions and 11 deletions

View File

@ -1,10 +1,19 @@
using System; using System;
using System.Reflection.Metadata.Ecma335;
using SHADE; using SHADE;
using SHADE_Scripting.UI;
public class ChangeSceneButton : Script public class ChangeSceneButton : Script
{ {
public uint sceneID = 0; 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() protected override void start()
{ {
@ -17,8 +26,12 @@ public class ChangeSceneButton : Script
if (sceneID != 0) if (sceneID != 0)
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); Audio.PlaySFXOnce2D("event:/UI/success");
SceneManager.ChangeScene(sceneID);
Audio.StopAllSounds(); Audio.StopAllSounds();
SceneFadeInOut.Instance.fadeOut = false;
SceneFadeInOut.Instance.fadeIn = true;
clickedFlag = true;
} }
}); });
} }
@ -30,6 +43,9 @@ public class ChangeSceneButton : Script
} }
protected override void update() protected override void update()
{ {
if (clickedFlag && sceneID != 0 && SceneFadeInOut.Instance.alphaValue >= 1.0f)
{
SceneManager.ChangeScene(sceneID);
}
} }
} }

View File

@ -9,16 +9,13 @@ namespace SHADE_Scripting.UI
{ {
public class SceneFadeInOut : Script public class SceneFadeInOut : Script
{ {
[SerializeField] [Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
private GameObject fadeUI;
[Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading")]
public bool 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; 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; public float alphaValue;
[SerializeField] [SerializeField]
@ -29,10 +26,18 @@ namespace SHADE_Scripting.UI
private Renderable fadeR; private Renderable fadeR;
public static SceneFadeInOut Instance { get; private set; }
protected override void awake() protected override void awake()
{ {
fadeR = fadeUI.GetComponent<Renderable>(); if (Instance != null && Instance != this)
alphaValue = fadeR.Material.GetProperty<float>("data.alpha"); 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() protected override void start()
@ -46,12 +51,14 @@ namespace SHADE_Scripting.UI
{ {
if (fadeIn) //fading in if (fadeIn) //fading in
{ {
fadeOut = false;
alphaValue += fadeInRate * Time.DeltaTimeF; alphaValue += fadeInRate * Time.DeltaTimeF;
if (alphaValue >= 1.0f) alphaValue = 1.0f; if (alphaValue >= 1.0f) alphaValue = 1.0f;
} }
if (fadeOut) //fading out if (fadeOut) //fading out
{ {
fadeIn = false;
alphaValue -= fadeOutRate * Time.DeltaTimeF; alphaValue -= fadeOutRate * Time.DeltaTimeF;
if (alphaValue <= 0.0f) alphaValue = 0.0f; if (alphaValue <= 0.0f) alphaValue = 0.0f;
} }
@ -59,5 +66,12 @@ namespace SHADE_Scripting.UI
fadeR.Material.SetProperty<float>("data.alpha", alphaValue); fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
} }
} }
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
} }
} }