Scene transitions done

This commit is contained in:
mushgunAX 2023-03-01 17:36:02 +08:00
parent a65735e0b3
commit 1f5cfd36f7
11 changed files with 97 additions and 47 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio; using SHADE_Scripting.Audio;
using SHADE_Scripting.UI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -43,6 +44,10 @@ public class GameManager : Script
public bool itemShatter { get; set; } public bool itemShatter { get; set; }
//For scene transitions
private bool goingToWin;
private bool goingToLose;
protected override void awake() protected override void awake()
{ {
if (Instance != null && Instance != this) 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["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win");
AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose"); AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
goingToWin = false;
goingToLose = false;
} }
protected override void start() protected override void start()
{ {
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive"); AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["BGMAdaptive"].Play(); AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
@ -113,21 +120,34 @@ public class GameManager : Script
//multiplierText.GetComponent<Transform>().LocalScale = Vector3.Zero; //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; currGameState = GameState.WIN;
AudioHandler.stopAllSounds(false); AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["BGMWin"].Play(); 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; currGameState = GameState.LOSE;
AudioHandler.stopAllSounds(false); AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["BGMLose"].Play(); AudioHandler.audioClipHandlers["BGMLose"].Play();
SceneManager.ChangeScene(loseScene); 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(); Audio.StopAllSounds();
SceneFadeInOut.Instance.fadeOut = false; SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.fadeIn = true;
clickedFlag = true; clickedFlag = true;
} }
}); });
@ -43,7 +42,7 @@ public class ChangeSceneButton : Script
} }
protected override void update() protected override void update()
{ {
if (clickedFlag && sceneID != 0 && SceneFadeInOut.Instance.alphaValue >= 1.0f) if (clickedFlag && sceneID != 0 && SceneFadeInOut.Instance.FadeInFinished())
{ {
SceneManager.ChangeScene(sceneID); SceneManager.ChangeScene(sceneID);
} }

View File

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

View File

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

View File

@ -9,20 +9,20 @@ namespace SHADE_Scripting.UI
{ {
public class SceneFadeInOut : Script public class SceneFadeInOut : Script
{ {
[Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading. Mutually exclusive with fadeIn")] //[Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
public bool fadeIn; private bool fadeIn;
[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading. Mutually exclusive with fadeIn")] //[Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading. Mutually exclusive with fadeIn")]
public bool fadeOut; 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; public float alphaValue;
[SerializeField] [SerializeField]
private float fadeInRate; private float fadeInTime;
[SerializeField] [SerializeField]
private float fadeOutRate; private float fadeOutTime;
private Renderable fadeR; private Renderable fadeR;
@ -42,7 +42,7 @@ namespace SHADE_Scripting.UI
protected override void start() protected override void start()
{ {
CallFadeOut();
} }
protected override void update() protected override void update()
@ -52,14 +52,28 @@ namespace SHADE_Scripting.UI
if (fadeIn) //fading in if (fadeIn) //fading in
{ {
fadeOut = false; 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 (alphaValue >= 1.0f) alphaValue = 1.0f;
} }
if (fadeOut) //fading out if (fadeOut) //fading out
{ {
fadeIn = false; 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; if (alphaValue <= 0.0f) alphaValue = 0.0f;
} }
@ -73,5 +87,32 @@ namespace SHADE_Scripting.UI
Instance = null; 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);
}
} }
} }