Merge pull request #378 from SHADE-DP/scenetransitions

Implemented Fade In To and Fade Out From Black Scene Transitions
This commit is contained in:
XiaoQiDigipen 2023-03-01 17:55:27 +08:00 committed by GitHub
commit b63db13c41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 446 additions and 34 deletions

View File

@ -0,0 +1,8 @@
- VertexShader: 46580970
FragmentShader: 50110174
SubPass: UI
Properties:
data.color: {x: 0, y: 0, z: 0, w: 1}
data.textureIndex: 0
data.alpha: 0
data.beta: {x: 1, y: 1, z: 1}

View File

@ -0,0 +1,3 @@
Name: UIMat_Black
ID: 120016136
Type: 7

View File

@ -5289,4 +5289,40 @@
Components: ~
Scripts:
- Type: SHADE_Scripting.UI.TweenManager
Enabled: true
Enabled: true
- EID: 461
Name: TransitionCanvas
IsActive: true
NumberOfChildren: 1
Components:
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 459
Name: Transition
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 120016136
IsActive: true
UI Component:
Canvas ID: 461
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
alphaValue: 1
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -13297,4 +13297,40 @@
Mesh: 136373407
Material: 131956078
IsActive: true
Scripts: ~
Scripts: ~
- EID: 174
Name: TransitionCanvas
IsActive: true
NumberOfChildren: 1
Components:
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 173
Name: Transition
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 120016136
IsActive: true
UI Component:
Canvas ID: 174
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
alphaValue: 1
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -20,6 +20,7 @@
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 2
@ -28,7 +29,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Translate: {x: 0, y: 0, z: 0.5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
@ -38,6 +39,8 @@
IsActive: true
UI Component:
Canvas ID: 1
Hovered: false
Clicked: false
IsActive: true
Scripts: ~
- EID: 5
@ -46,7 +49,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 75, z: 0}
Translate: {x: 0, y: 75, z: 0.400000006}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 400, y: 200, z: 1}
IsActive: true
@ -61,6 +64,8 @@
IsActive: true
UI Component:
Canvas ID: 1
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: ChangeSceneButton
@ -72,7 +77,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -200, z: 0}
Translate: {x: 0, y: -200, z: 0.400000006}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 400, y: 200, z: 1}
IsActive: true
@ -87,6 +92,8 @@
IsActive: true
UI Component:
Canvas ID: 1
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: QuitButton
@ -107,10 +114,10 @@
Yaw: 0
Roll: 0
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
FOV: 90
IsActive: true
Scripts: ~
- EID: 4
@ -122,4 +129,40 @@
- Type: EndScene
Enabled: true
mainGameScene: 86098106
mainMainScene: 97158628
mainMainScene: 97158628
- EID: 7
Name: TransitionCanvas
IsActive: true
NumberOfChildren: 1
Components:
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 8
Name: Transition
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 120016136
IsActive: true
UI Component:
Canvas ID: 7
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
alphaValue: 1
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -216,12 +216,12 @@
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 3.14159274}
Scale: {x: 1920, y: 500, z: 1}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: false
Renderable Component:
Mesh: 141771688
Material: 129138332
Mesh: 0
Material: 0
IsActive: false
UI Component:
Canvas ID: 0
@ -1087,4 +1087,40 @@
Hovered: false
Clicked: false
IsActive: true
Scripts: ~
Scripts: ~
- EID: 55
Name: Transition Canvas
IsActive: true
NumberOfChildren: 1
Components:
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 56
Name: Transition
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0.100000001}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 120016136
IsActive: true
UI Component:
Canvas ID: 55
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
alphaValue: 1
fadeInTime: 0.5
fadeOutTime: 0.5

View File

@ -20,6 +20,7 @@
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 2
@ -28,7 +29,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Translate: {x: 0, y: 0, z: 0.5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
@ -38,6 +39,8 @@
IsActive: true
UI Component:
Canvas ID: 1
Hovered: false
Clicked: false
IsActive: true
Scripts: ~
- EID: 5
@ -46,7 +49,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 75, z: 0}
Translate: {x: 0, y: 75, z: 0.400000006}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 400, y: 200, z: 1}
IsActive: true
@ -61,6 +64,8 @@
IsActive: true
UI Component:
Canvas ID: 1
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: ChangeSceneButton
@ -72,7 +77,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -200, z: 0}
Translate: {x: 0, y: -200, z: 0.400000006}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 400, y: 200, z: 1}
IsActive: true
@ -87,6 +92,8 @@
IsActive: true
UI Component:
Canvas ID: 1
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: QuitButton
@ -107,7 +114,6 @@
Yaw: 0
Roll: 0
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
@ -123,4 +129,40 @@
- Type: EndScene
Enabled: true
mainGameScene: 86098106
mainMainScene: 97158628
mainMainScene: 97158628
- EID: 7
Name: TransitionCanvas
IsActive: true
NumberOfChildren: 1
Components:
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 8
Name: Transition
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0.100000001}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1920, y: 1080, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 120016136
IsActive: true
UI Component:
Canvas ID: 7
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: SHADE_Scripting.UI.SceneFadeInOut
Enabled: true
alphaValue: 1
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

@ -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,11 @@ public class ChangeSceneButton : Script
if (sceneID != 0)
{
Audio.PlaySFXOnce2D("event:/UI/success");
SceneManager.ChangeScene(sceneID);
Audio.StopAllSounds();
SceneFadeInOut.Instance.CallFadeIn();
clickedFlag = true;
}
});
}
@ -30,6 +42,9 @@ public class ChangeSceneButton : Script
}
protected override void update()
{
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

@ -0,0 +1,118 @@
using SHADE;
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);
//alphaValue = fadeR.Material.GetProperty<float>("data.alpha");
}
protected override void start()
{
CallFadeOut();
}
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) alphaValue = 1.0f;
}
if (fadeOut) //fading out
{
fadeIn = false;
if (fadeOutTime == 0.0f)
{
alphaValue = 0.0f;
}
else
{
alphaValue -= (1.0f / fadeOutTime) * Time.DeltaTimeF;
}
if (alphaValue <= 0.0f) alphaValue = 0.0f;
}
fadeR.Material.SetProperty<float>("data.alpha", alphaValue);
}
}
protected override void onDestroy()
{
if (Instance == this)
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);
}
}
}

View File

@ -0,0 +1,3 @@
Name: SC_SceneFadeInOut
ID: 153328192
Type: 9

View File

@ -0,0 +1,49 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#extension GL_EXT_nonuniform_qualifier : require
struct MatPropData
{
vec4 color;
int textureIndex;
float alpha;
};
layout(location = 0) in struct
{
vec4 vertPos; // location 0
vec2 uv; // location = 1
vec4 normal; // location = 2
} In;
// material stuff
layout(location = 3) flat in struct
{
int materialIndex;
uint eid;
uint lightLayerIndex;
} In2;
layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global)
layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials
{
MatPropData data[];
} MatProp;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out uint outEntityID;
void main()
{
fragColor = MatProp.data[In2.materialIndex].color;
if (fragColor.a < 0.01f)
{
discard;
}
fragColor.a = MatProp.data[In2.materialIndex].alpha;
// fragColor.a = 1.0f;
outEntityID = In2.eid;
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: UI_Black_FS
ID: 50110174
Type: 2