Implemented Fade In To and Fade Out From Black Scene Transitions #378

Merged
mushgunAX merged 10 commits from scenetransitions into main 2023-03-01 17:55:28 +08:00
11 changed files with 97 additions and 47 deletions
Showing only changes of commit 1f5cfd36f7 - Show all commits

View File

@ -5323,8 +5323,6 @@
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
fadeIn: false
fadeOut: true
alphaValue: 1
fadeInRate: 2
fadeOutRate: 2
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -13331,8 +13331,6 @@
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
fadeIn: false
fadeOut: true
alphaValue: 1
fadeInRate: 2
fadeOutRate: 2
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -163,8 +163,6 @@
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
fadeIn: false
fadeOut: true
alphaValue: 1
fadeInRate: 2
fadeOutRate: 2
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -1121,8 +1121,6 @@
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
fadeIn: false
fadeOut: true
alphaValue: 1
fadeInRate: 2
fadeOutRate: 2
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -163,8 +163,6 @@
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
fadeIn: false
fadeOut: true
alphaValue: 1
fadeInRate: 2
fadeOutRate: 2
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -12,7 +12,7 @@ namespace SHADE_Scripting.Audio
public static Dictionary<string, AudioClipHandler> audioClipHandlers = new Dictionary<string, AudioClipHandler>();
//Functions here, maybe
public static void stopAllSounds(bool fadeOut)
public static void StopAllSounds(bool fadeOut)
{
foreach (KeyValuePair<string, AudioClipHandler> h in audioClipHandlers)
{
@ -20,7 +20,7 @@ namespace SHADE_Scripting.Audio
}
}
public static void pauseAllSounds(bool pause)
public static void PauseAllSounds(bool pause)
{
foreach (KeyValuePair<string, AudioClipHandler> h in audioClipHandlers)
{

View File

@ -1,5 +1,6 @@
using SHADE;
using SHADE_Scripting.Audio;
using SHADE_Scripting.UI;
using System;
using System.Collections.Generic;
@ -43,6 +44,10 @@ public class GameManager : Script
public bool itemShatter { get; set; }
//For scene transitions
private bool goingToWin;
private bool goingToLose;
protected override void awake()
{
if (Instance != null && Instance != this)
@ -61,11 +66,13 @@ public class GameManager : Script
AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win");
AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
goingToWin = false;
goingToLose = false;
}
protected override void start()
{
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
@ -113,21 +120,34 @@ public class GameManager : Script
//multiplierText.GetComponent<Transform>().LocalScale = Vector3.Zero;
}
if ((timer > 0 && totalItemCount <= 0 && !itemShatter) || Input.GetKeyDown(Input.KeyCode.F1))
if (!goingToLose && ((timer > 0 && totalItemCount <= 0 && !itemShatter) || Input.GetKeyDown(Input.KeyCode.F1)))
{
currGameState = GameState.WIN;
AudioHandler.stopAllSounds(false);
AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["BGMWin"].Play();
SceneManager.ChangeScene(winScene);
goingToWin = true;
SceneFadeInOut.Instance.CallFadeIn();
}
else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2))
else if(!goingToWin && (timer < 0 || Input.GetKeyDown(Input.KeyCode.F2)))
{
currGameState = GameState.LOSE;
AudioHandler.stopAllSounds(false);
AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["BGMLose"].Play();
goingToLose = true;
SceneFadeInOut.Instance.CallFadeIn();
}
}
//Handling transitions
if (SceneFadeInOut.Instance.FadeInFinished())
{
if (goingToWin)
{
SceneManager.ChangeScene(winScene);
}
if (goingToLose)
{
SceneManager.ChangeScene(loseScene);
}
}
}

View File

@ -29,8 +29,7 @@ public class ChangeSceneButton : Script
Audio.StopAllSounds();
SceneFadeInOut.Instance.fadeOut = false;
SceneFadeInOut.Instance.fadeIn = true;
SceneFadeInOut.Instance.CallFadeIn();
clickedFlag = true;
}
});
@ -43,7 +42,7 @@ public class ChangeSceneButton : Script
}
protected override void update()
{
if (clickedFlag && sceneID != 0 && SceneFadeInOut.Instance.alphaValue >= 1.0f)
if (clickedFlag && sceneID != 0 && SceneFadeInOut.Instance.FadeInFinished())
{
SceneManager.ChangeScene(sceneID);
}

View File

@ -23,7 +23,7 @@ public class EndScene : Script
{
//Audio.PlaySFXOnce2D("event:/UI/success");
//Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(mainGameScene);
}
@ -37,7 +37,7 @@ public class EndScene : Script
{
//Audio.PlaySFXOnce2D("event:/UI/success");
//Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(mainMainScene);
}

View File

@ -39,7 +39,7 @@ public class PauseMenu : Script
if (GameManager.Instance.GamePause)
{
GameManager.Instance.GamePause = false;
AudioHandler.pauseAllSounds(false);
AudioHandler.PauseAllSounds(false);
if (gamePauseText)
gamePauseText.GetComponent<TextRenderable>().Enabled = false;
if (canvas)
@ -89,7 +89,7 @@ public class PauseMenu : Script
if (Input.GetKeyDown(Input.KeyCode.Escape) && !GameManager.Instance.GamePause)
{
GameManager.Instance.GamePause = true;
AudioHandler.pauseAllSounds(true);
AudioHandler.PauseAllSounds(true);
if (gamePauseText)
gamePauseText.GetComponent<TextRenderable>().Enabled = true;
if (canvas)

View File

@ -9,20 +9,20 @@ 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")]
public bool fadeIn;
//[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")]
public bool fadeOut;
//[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
private bool fadeOut;
[Tooltip("The alpha value of the UI that is faded. Between 0 and 1 inclusive.")]
[Tooltip("The initial alpha value of the UI that is faded. Between 0 and 1 inclusive.")]
public float alphaValue;
[SerializeField]
private float fadeInRate;
private float fadeInTime;
[SerializeField]
private float fadeOutRate;
private float fadeOutTime;
private Renderable fadeR;
@ -42,7 +42,7 @@ namespace SHADE_Scripting.UI
protected override void start()
{
CallFadeOut();
}
protected override void update()
@ -52,14 +52,28 @@ namespace SHADE_Scripting.UI
if (fadeIn) //fading in
{
fadeOut = false;
alphaValue += fadeInRate * Time.DeltaTimeF;
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;
alphaValue -= fadeOutRate * Time.DeltaTimeF;
if (fadeOutTime == 0.0f)
{
alphaValue = 0.0f;
}
else
{
alphaValue -= (1.0f / fadeOutTime) * Time.DeltaTimeF;
}
if (alphaValue <= 0.0f) alphaValue = 0.0f;
}
@ -73,5 +87,32 @@ namespace SHADE_Scripting.UI
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);
}
}
}