From f9c90ece7ebc503b44b06d66adedf323a7a51450 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Mon, 27 Feb 2023 15:28:05 +0800 Subject: [PATCH 1/5] Scene Transition Script --- Assets/Scripts/UI/SC_SceneFadeInOut.cs | 63 +++++++++++++++++++ Assets/Scripts/UI/SC_SceneFadeInOut.cs.shmeta | 3 + 2 files changed, 66 insertions(+) create mode 100644 Assets/Scripts/UI/SC_SceneFadeInOut.cs create mode 100644 Assets/Scripts/UI/SC_SceneFadeInOut.cs.shmeta diff --git a/Assets/Scripts/UI/SC_SceneFadeInOut.cs b/Assets/Scripts/UI/SC_SceneFadeInOut.cs new file mode 100644 index 00000000..34cfdc78 --- /dev/null +++ b/Assets/Scripts/UI/SC_SceneFadeInOut.cs @@ -0,0 +1,63 @@ +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 + { + [SerializeField] + private GameObject fadeUI; + + [Tooltip("If true, the panel fadeUI fades in (increasing alpha). If false, no fading")] + public bool fadeIn; + + [Tooltip("If true, the panel fadeUI fades out (decreasing alpha). If false, no fading")] + public bool fadeOut; + + [Tooltip("The alpha value of the UI that is faded")] + public float alphaValue; + + [SerializeField] + private float fadeInRate; + + [SerializeField] + private float fadeOutRate; + + private Renderable fadeR; + + protected override void awake() + { + fadeR = fadeUI.GetComponent(); + alphaValue = fadeR.Material.GetProperty("data.alpha"); + } + + protected override void start() + { + + } + + protected override void update() + { + if (fadeR != null) + { + if (fadeIn) //fading in + { + alphaValue += fadeInRate * Time.DeltaTimeF; + if (alphaValue >= 1.0f) alphaValue = 1.0f; + } + + if (fadeOut) //fading out + { + alphaValue -= fadeOutRate * Time.DeltaTimeF; + if (alphaValue <= 0.0f) alphaValue = 0.0f; + } + + fadeR.Material.SetProperty("data.alpha", alphaValue); + } + } + } +} diff --git a/Assets/Scripts/UI/SC_SceneFadeInOut.cs.shmeta b/Assets/Scripts/UI/SC_SceneFadeInOut.cs.shmeta new file mode 100644 index 00000000..ddebe65c --- /dev/null +++ b/Assets/Scripts/UI/SC_SceneFadeInOut.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_SceneFadeInOut +ID: 153328192 +Type: 9 -- 2.40.1 From c32867228649c7c79d27df2289df96844c2ac3d8 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Mon, 27 Feb 2023 16:22:54 +0800 Subject: [PATCH 2/5] black shader --- Assets/Materials/UI/UIMat_Black.shmat | 8 +++ Assets/Materials/UI/UIMat_Black.shmat.shmeta | 3 ++ Assets/Shaders/UI_Black_FS.glsl | 49 +++++++++++++++++++ Assets/Shaders/UI_Black_FS.shshaderb | Bin 0 -> 1973 bytes Assets/Shaders/UI_Black_FS.shshaderb.shmeta | 3 ++ 5 files changed, 63 insertions(+) create mode 100644 Assets/Materials/UI/UIMat_Black.shmat create mode 100644 Assets/Materials/UI/UIMat_Black.shmat.shmeta create mode 100644 Assets/Shaders/UI_Black_FS.glsl create mode 100644 Assets/Shaders/UI_Black_FS.shshaderb create mode 100644 Assets/Shaders/UI_Black_FS.shshaderb.shmeta diff --git a/Assets/Materials/UI/UIMat_Black.shmat b/Assets/Materials/UI/UIMat_Black.shmat new file mode 100644 index 00000000..d27853ac --- /dev/null +++ b/Assets/Materials/UI/UIMat_Black.shmat @@ -0,0 +1,8 @@ +- VertexShader: 46580970 + FragmentShader: 50110174 + SubPass: UI + Properties: + data.color: {x: 0.5, y: 0, z: 0, w: 1} + data.textureIndex: 0 + data.alpha: 0 + data.beta: {x: 1, y: 1, z: 1} \ No newline at end of file diff --git a/Assets/Materials/UI/UIMat_Black.shmat.shmeta b/Assets/Materials/UI/UIMat_Black.shmat.shmeta new file mode 100644 index 00000000..caac5feb --- /dev/null +++ b/Assets/Materials/UI/UIMat_Black.shmat.shmeta @@ -0,0 +1,3 @@ +Name: UIMat_Black +ID: 120016136 +Type: 7 diff --git a/Assets/Shaders/UI_Black_FS.glsl b/Assets/Shaders/UI_Black_FS.glsl new file mode 100644 index 00000000..84664ede --- /dev/null +++ b/Assets/Shaders/UI_Black_FS.glsl @@ -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; +} \ No newline at end of file diff --git a/Assets/Shaders/UI_Black_FS.shshaderb b/Assets/Shaders/UI_Black_FS.shshaderb new file mode 100644 index 0000000000000000000000000000000000000000..17a072c9f4323047a3e0c0242bb02a8d481237fb GIT binary patch literal 1973 zcmZ9L>rN9v7={PhA_otk97Gfg#3O=;fOt$$NhPU)s6YI-8QY<(F59}@61XQXz~A14 zm!dJ6_&(bmMTdNRr+44)Fw@~rCrowqg9%%C}C9(6-z#Plj+%#i8Jbfx;by4X(Z ziz};3Ku()Nh6HoQ449%cvTwtf#DHW}vLIQN3=2=5k_G+sN`KMEMIkHIVB^)(pzT^V zv8fB%d$#V9p!x2-tEKIKF-nDTBZzF==-7q}R+g7qw)R0h{qStQeG|mZxD$uF&166L z*s)Q#8@fdKLGqRD?MihssI^)_J3WeA5QVV|>S3Zv;en%8#*^d1xE6Kl#{nfFj?Y;# zrEJ#S#5SHaqh_MHhz&`Ky#VP%G9I+K4#{*&Eu@%c90ZjNd>Q9V1#D*mvM=fH^ z0oO_CK1o>u#_!d0Rn!l$f&@G}o|VAk{TbODu<)MF>|$oqr~h_AHa>mvEx#2%2R^gH z&GA0m;LoWdHD|;IANIH`-}{8V=l6!sn=R{qzcg6l4|AX05gU^~C|#DoKb`LpEOB@) z3CVug@3d_8fDbn_(gQKL@!1Wr`J9`*bEq{UUB=O&7H^I^#JjnoX6*Jt4o-abNq^KF z%k6I8MRQ(0_2`+J@JvaV5B$a4W)|}3%aXybbB{*#WjT+-cTEBp-(Amb@c6f+;e?;Q z@VQH3e%3|VJreM@a~nMOvMdc3{LIepf}V+^`DR6$@5xaEpZ7s*QZIf@8V>y9$NN+2 z=AIJZ{4UmIlfNjw`_klzQSX5?hdA}{d4HTW^+>P0BMx(ZSEMApq5s^&xP-gmjvouj z4kskUH#8M@Gb!OsfFb9x%zQyY{)yOmllX9RXO|?zxJ$U1o8JlX&%%_YXC%b9&u`+G zlji&op4_a27=2^^)F!Zr`5CUr{(pw6iV&w3m*)5 a-o%oGdb|}lcprBp#KH5X@PDb-b;)lb=&8H_ literal 0 HcmV?d00001 diff --git a/Assets/Shaders/UI_Black_FS.shshaderb.shmeta b/Assets/Shaders/UI_Black_FS.shshaderb.shmeta new file mode 100644 index 00000000..b5429d75 --- /dev/null +++ b/Assets/Shaders/UI_Black_FS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: UI_Black_FS +ID: 50110174 +Type: 2 -- 2.40.1 From b3ec2fb4df913c4af54f620c4f0cfff8dff695bb Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Tue, 28 Feb 2023 06:49:40 +0800 Subject: [PATCH 3/5] implementing in progress --- Assets/Scripts/UI/SC_ChangeSceneButton.cs | 22 ++++++++++++++--- Assets/Scripts/UI/SC_SceneFadeInOut.cs | 30 +++++++++++++++++------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/UI/SC_ChangeSceneButton.cs b/Assets/Scripts/UI/SC_ChangeSceneButton.cs index c0629d0a..7b479d19 100644 --- a/Assets/Scripts/UI/SC_ChangeSceneButton.cs +++ b/Assets/Scripts/UI/SC_ChangeSceneButton.cs @@ -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); + } } } diff --git a/Assets/Scripts/UI/SC_SceneFadeInOut.cs b/Assets/Scripts/UI/SC_SceneFadeInOut.cs index 34cfdc78..df245d26 100644 --- a/Assets/Scripts/UI/SC_SceneFadeInOut.cs +++ b/Assets/Scripts/UI/SC_SceneFadeInOut.cs @@ -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(); - alphaValue = fadeR.Material.GetProperty("data.alpha"); + if (Instance != null && Instance != this) + RemoveScript(); + else + Instance = this; + + fadeR = GameObject.GetComponent(); + fadeR.Material.SetProperty("data.alpha", alphaValue); + //alphaValue = fadeR.Material.GetProperty("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("data.alpha", alphaValue); } } + + protected override void onDestroy() + { + if (Instance == this) + Instance = null; + } + } } -- 2.40.1 From a65735e0b37db0a518f2f27f0fa99e62b5108252 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Wed, 1 Mar 2023 16:37:33 +0800 Subject: [PATCH 4/5] progress --- Assets/Materials/UI/UIMat_Black.shmat | 2 +- Assets/Scenes/Level1.shade | 40 ++++++++++++++++++- Assets/Scenes/Level2.shade | 40 ++++++++++++++++++- Assets/Scenes/LoseScene.shade | 55 ++++++++++++++++++++++++--- Assets/Scenes/MainMenu.shade | 48 ++++++++++++++++++++--- Assets/Scenes/WinScene.shade | 54 +++++++++++++++++++++++--- 6 files changed, 221 insertions(+), 18 deletions(-) diff --git a/Assets/Materials/UI/UIMat_Black.shmat b/Assets/Materials/UI/UIMat_Black.shmat index d27853ac..183b5f26 100644 --- a/Assets/Materials/UI/UIMat_Black.shmat +++ b/Assets/Materials/UI/UIMat_Black.shmat @@ -2,7 +2,7 @@ FragmentShader: 50110174 SubPass: UI Properties: - data.color: {x: 0.5, y: 0, z: 0, w: 1} + data.color: {x: 0, y: 0, z: 0, w: 1} data.textureIndex: 0 data.alpha: 0 data.beta: {x: 1, y: 1, z: 1} \ No newline at end of file diff --git a/Assets/Scenes/Level1.shade b/Assets/Scenes/Level1.shade index e06548c0..bbfcd35c 100644 --- a/Assets/Scenes/Level1.shade +++ b/Assets/Scenes/Level1.shade @@ -5289,4 +5289,42 @@ Components: ~ Scripts: - Type: SHADE_Scripting.UI.TweenManager - Enabled: true \ No newline at end of file + 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 + fadeIn: false + fadeOut: true + alphaValue: 1 + fadeInRate: 2 + fadeOutRate: 2 \ No newline at end of file diff --git a/Assets/Scenes/Level2.shade b/Assets/Scenes/Level2.shade index 47b32e34..812218dd 100644 --- a/Assets/Scenes/Level2.shade +++ b/Assets/Scenes/Level2.shade @@ -13297,4 +13297,42 @@ Mesh: 136373407 Material: 131956078 IsActive: true - Scripts: ~ \ No newline at end of file + 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 + fadeIn: false + fadeOut: true + alphaValue: 1 + fadeInRate: 2 + fadeOutRate: 2 \ No newline at end of file diff --git a/Assets/Scenes/LoseScene.shade b/Assets/Scenes/LoseScene.shade index 501c203f..2a9cafd1 100644 --- a/Assets/Scenes/LoseScene.shade +++ b/Assets/Scenes/LoseScene.shade @@ -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,42 @@ - Type: EndScene Enabled: true mainGameScene: 86098106 - mainMainScene: 97158628 \ No newline at end of file + 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 + fadeIn: false + fadeOut: true + alphaValue: 1 + fadeInRate: 2 + fadeOutRate: 2 \ No newline at end of file diff --git a/Assets/Scenes/MainMenu.shade b/Assets/Scenes/MainMenu.shade index a2a5dd1c..367c3910 100644 --- a/Assets/Scenes/MainMenu.shade +++ b/Assets/Scenes/MainMenu.shade @@ -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,42 @@ Hovered: false Clicked: false IsActive: true - Scripts: ~ \ No newline at end of file + 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 + fadeIn: false + fadeOut: true + alphaValue: 1 + fadeInRate: 2 + fadeOutRate: 2 \ No newline at end of file diff --git a/Assets/Scenes/WinScene.shade b/Assets/Scenes/WinScene.shade index 0727860e..c7cd909b 100644 --- a/Assets/Scenes/WinScene.shade +++ b/Assets/Scenes/WinScene.shade @@ -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,42 @@ - Type: EndScene Enabled: true mainGameScene: 86098106 - mainMainScene: 97158628 \ No newline at end of file + 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 + fadeIn: false + fadeOut: true + alphaValue: 1 + fadeInRate: 2 + fadeOutRate: 2 \ No newline at end of file -- 2.40.1 From 1f5cfd36f7c53dd9b076f662cbb49c239ccb2644 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Wed, 1 Mar 2023 17:36:02 +0800 Subject: [PATCH 5/5] Scene transitions done --- Assets/Scenes/Level1.shade | 6 +-- Assets/Scenes/Level2.shade | 6 +-- Assets/Scenes/LoseScene.shade | 6 +-- Assets/Scenes/MainMenu.shade | 6 +-- Assets/Scenes/WinScene.shade | 6 +-- Assets/Scripts/Audio/AudioHandler.cs | 4 +- Assets/Scripts/Gameplay/SC_GameManager.cs | 36 ++++++++++--- Assets/Scripts/UI/SC_ChangeSceneButton.cs | 5 +- Assets/Scripts/UI/SC_EndScene.cs | 4 +- Assets/Scripts/UI/SC_PauseMenu.cs | 4 +- Assets/Scripts/UI/SC_SceneFadeInOut.cs | 61 +++++++++++++++++++---- 11 files changed, 97 insertions(+), 47 deletions(-) diff --git a/Assets/Scenes/Level1.shade b/Assets/Scenes/Level1.shade index bbfcd35c..3aca2ae6 100644 --- a/Assets/Scenes/Level1.shade +++ b/Assets/Scenes/Level1.shade @@ -5323,8 +5323,6 @@ Scripts: - Type: SHADE_Scripting.UI.SceneFadeInOut Enabled: true - fadeIn: false - fadeOut: true alphaValue: 1 - fadeInRate: 2 - fadeOutRate: 2 \ No newline at end of file + fadeInTime: 0.5 + fadeOutTime: 0.5 \ No newline at end of file diff --git a/Assets/Scenes/Level2.shade b/Assets/Scenes/Level2.shade index 812218dd..f0c33b5b 100644 --- a/Assets/Scenes/Level2.shade +++ b/Assets/Scenes/Level2.shade @@ -13331,8 +13331,6 @@ Scripts: - Type: SHADE_Scripting.UI.SceneFadeInOut Enabled: true - fadeIn: false - fadeOut: true alphaValue: 1 - fadeInRate: 2 - fadeOutRate: 2 \ No newline at end of file + fadeInTime: 0.5 + fadeOutTime: 0.5 \ No newline at end of file diff --git a/Assets/Scenes/LoseScene.shade b/Assets/Scenes/LoseScene.shade index 2a9cafd1..bd9d45c3 100644 --- a/Assets/Scenes/LoseScene.shade +++ b/Assets/Scenes/LoseScene.shade @@ -163,8 +163,6 @@ Scripts: - Type: SHADE_Scripting.UI.SceneFadeInOut Enabled: true - fadeIn: false - fadeOut: true alphaValue: 1 - fadeInRate: 2 - fadeOutRate: 2 \ No newline at end of file + fadeInTime: 0.5 + fadeOutTime: 0.5 \ No newline at end of file diff --git a/Assets/Scenes/MainMenu.shade b/Assets/Scenes/MainMenu.shade index 367c3910..946e7a8d 100644 --- a/Assets/Scenes/MainMenu.shade +++ b/Assets/Scenes/MainMenu.shade @@ -1121,8 +1121,6 @@ Scripts: - Type: SHADE_Scripting.UI.SceneFadeInOut Enabled: true - fadeIn: false - fadeOut: true alphaValue: 1 - fadeInRate: 2 - fadeOutRate: 2 \ No newline at end of file + fadeInTime: 0.5 + fadeOutTime: 0.5 \ No newline at end of file diff --git a/Assets/Scenes/WinScene.shade b/Assets/Scenes/WinScene.shade index c7cd909b..57096086 100644 --- a/Assets/Scenes/WinScene.shade +++ b/Assets/Scenes/WinScene.shade @@ -163,8 +163,6 @@ Scripts: - Type: SHADE_Scripting.UI.SceneFadeInOut Enabled: true - fadeIn: false - fadeOut: true alphaValue: 1 - fadeInRate: 2 - fadeOutRate: 2 \ No newline at end of file + fadeInTime: 0.5 + fadeOutTime: 0.5 \ No newline at end of file diff --git a/Assets/Scripts/Audio/AudioHandler.cs b/Assets/Scripts/Audio/AudioHandler.cs index c6067819..4743b4c5 100644 --- a/Assets/Scripts/Audio/AudioHandler.cs +++ b/Assets/Scripts/Audio/AudioHandler.cs @@ -12,7 +12,7 @@ namespace SHADE_Scripting.Audio public static Dictionary audioClipHandlers = new Dictionary(); //Functions here, maybe - public static void stopAllSounds(bool fadeOut) + public static void StopAllSounds(bool fadeOut) { foreach (KeyValuePair 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 h in audioClipHandlers) { diff --git a/Assets/Scripts/Gameplay/SC_GameManager.cs b/Assets/Scripts/Gameplay/SC_GameManager.cs index 1cebe002..3746ec0c 100644 --- a/Assets/Scripts/Gameplay/SC_GameManager.cs +++ b/Assets/Scripts/Gameplay/SC_GameManager.cs @@ -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().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); - } } } diff --git a/Assets/Scripts/UI/SC_ChangeSceneButton.cs b/Assets/Scripts/UI/SC_ChangeSceneButton.cs index 7b479d19..6a51716b 100644 --- a/Assets/Scripts/UI/SC_ChangeSceneButton.cs +++ b/Assets/Scripts/UI/SC_ChangeSceneButton.cs @@ -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); } diff --git a/Assets/Scripts/UI/SC_EndScene.cs b/Assets/Scripts/UI/SC_EndScene.cs index b934e2bd..2117b24a 100644 --- a/Assets/Scripts/UI/SC_EndScene.cs +++ b/Assets/Scripts/UI/SC_EndScene.cs @@ -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); } diff --git a/Assets/Scripts/UI/SC_PauseMenu.cs b/Assets/Scripts/UI/SC_PauseMenu.cs index 521b48ea..71e2b8c3 100644 --- a/Assets/Scripts/UI/SC_PauseMenu.cs +++ b/Assets/Scripts/UI/SC_PauseMenu.cs @@ -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().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().Enabled = true; if (canvas) diff --git a/Assets/Scripts/UI/SC_SceneFadeInOut.cs b/Assets/Scripts/UI/SC_SceneFadeInOut.cs index df245d26..5c6ebb77 100644 --- a/Assets/Scripts/UI/SC_SceneFadeInOut.cs +++ b/Assets/Scripts/UI/SC_SceneFadeInOut.cs @@ -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); + } } } -- 2.40.1