From 52ee46eebd9ccd7e5fb678ed65c66672daab1481 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:56:57 +0200 Subject: [PATCH] Game Switch Black Flash is now beat-based. (#503) * Game switch flashes are now 0.25 beats long * ambient glow now turns black when the game switch flash is on * you can now set the void color, it doesn't work with game switch flashes * black --- Assets/Scripts/GameCamera.cs | 34 ++++++++++++++++++++++++++++++++++ Assets/Scripts/GameManager.cs | 28 +++++++++++++++++++--------- Assets/Scripts/Minigames.cs | 7 +++++++ Assets/Scripts/StaticCamera.cs | 6 +++++- 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/GameCamera.cs b/Assets/Scripts/GameCamera.cs index 6bb41578..638f33e8 100644 --- a/Assets/Scripts/GameCamera.cs +++ b/Assets/Scripts/GameCamera.cs @@ -25,6 +25,7 @@ namespace HeavenStudio private List positionEvents = new(); private List rotationEvents = new(); private List shakeEvents = new(); + private List colorEvents = new(); /** default cam position, for quick-resetting @@ -61,6 +62,8 @@ namespace HeavenStudio [Header("Components")] public Color baseColor; + public static Color currentColor; + private void Awake() { instance = this; @@ -74,6 +77,7 @@ namespace HeavenStudio ResetTransforms(); ResetAdditionalTransforms(); + currentColor = baseColor; positionLast = defaultPosition; rotEluerLast = defaultRotEluer; @@ -83,6 +87,7 @@ namespace HeavenStudio { ResetTransforms(); ResetAdditionalTransforms(); + currentColor = baseColor; positionLast = defaultPosition; rotEluerLast = defaultRotEluer; @@ -101,9 +106,14 @@ namespace HeavenStudio shakeEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "screen shake" }); + //color/colour time baybee + + colorEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "camera background color" }); + UpdateCameraTranslate(); UpdateCameraRotate(); SetShakeIntensity(); + UpdateCameraColor(); } private void Update() @@ -111,6 +121,7 @@ namespace HeavenStudio UpdateCameraTranslate(); UpdateCameraRotate(); SetShakeIntensity(); + UpdateCameraColor(); } private void LateUpdate() @@ -121,6 +132,29 @@ namespace HeavenStudio cam.transform.localPosition = userPos + additionalPosition + shakeResult; cam.transform.eulerAngles = rotEluer + additionalRotEluer; cam.fieldOfView = additionalFoV; + cam.backgroundColor = currentColor; + if (!StaticCamera.instance.usingMinigameAmbientColor) StaticCamera.instance.SetAmbientGlowColour(currentColor, false, false); + } + + private void UpdateCameraColor() + { + foreach (var e in colorEvents) + { + float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length); + if (prog >= 0f) + { + Util.EasingFunction.Function func = Util.EasingFunction.GetEasingFunction((Util.EasingFunction.Ease)e["ease"]); + float newColorR = func(e["color"].r, e["color2"].r, prog); + float newColorG = func(e["color"].g, e["color2"].g, prog); + float newColorB = func(e["color"].b, e["color2"].b, prog); + + currentColor = new Color(newColorR, newColorG, newColorB); + } + if (prog > 1f) + { + currentColor = e["color2"]; + } + } } private void UpdateCameraTranslate() diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 9df92edc..b5d89bc0 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -761,24 +761,25 @@ namespace HeavenStudio IEnumerator SwitchGameIE(string game, double beat, bool flash) { - if(flash == true) + if(flash) { HeavenStudio.StaticCamera.instance.ToggleCanvasVisibility(false); } - SetGame(game); + SetGame(game, false); Minigame miniGame = currentGameO.GetComponent(); if (miniGame != null) miniGame.OnGameSwitch(beat); - //TODO: wait time in beats instead of seconds - yield return new WaitForSeconds(0.1f); + //before beat-based: yield return new WaitForSeconds(0.1f); + yield return new WaitForSeconds(Conductor.instance.pitchedSecPerBeat / 4); HeavenStudio.StaticCamera.instance.ToggleCanvasVisibility(true); + SetAmbientGlowToCurrentMinigameColor(); } - private void SetGame(string game) + private void SetGame(string game, bool useMinigameColor = true) { Destroy(currentGameO); @@ -786,7 +787,7 @@ namespace HeavenStudio currentGameO.transform.parent = eventCaller.GamesHolder.transform; currentGameO.name = game; - SetCurrentGame(game); + SetCurrentGame(game, useMinigameColor); ResetCamera(); } @@ -833,21 +834,30 @@ namespace HeavenStudio return EventCaller.instance.minigames.Find(c => c.name == name); } - public void SetCurrentGame(string game) + public void SetCurrentGame(string game, bool useMinigameColor = true) { currentGame = game; if (GetGameInfo(currentGame) != null) { CircleCursor.InnerCircle.GetComponent().color = Colors.Hex2RGB(GetGameInfo(currentGame).color); - HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(Colors.Hex2RGB(GetGameInfo(currentGame).color)); + if (useMinigameColor) HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(Colors.Hex2RGB(GetGameInfo(currentGame).color), true); + //else HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(HeavenStudio.GameCamera.currentColor, false); + else HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(Color.black, false); } else { CircleCursor.InnerCircle.GetComponent().color = Color.white; - HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(Color.black); + //HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(HeavenStudio.GameCamera.currentColor, false); + HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(Color.black, false); } } + private void SetAmbientGlowToCurrentMinigameColor() + { + if (GetGameInfo(currentGame) != null) + HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(Colors.Hex2RGB(GetGameInfo(currentGame).color), true); + } + private bool SongPosLessThanClipLength(float t) { if (Conductor.instance.musicSource.clip != null) diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index e068aae8..9c91392f 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -677,6 +677,13 @@ namespace HeavenStudio new Param("axis", GameCamera.CameraAxis.All, "Axis", "The axis to move the camera on" ) } ), + new GameAction("camera background color", "Camera Background Color", 1, true, new List() + { + new Param("color", Color.black, "Start Color"), + new Param("color2", Color.black, "End Color"), + new Param("ease", Util.EasingFunction.Ease.Linear, "Ease Type") + } + ), new GameAction("pan view", "Pan Viewport", 1f, true, new List() { new Param("valA", new EntityTypes.Float(-50, 50, 0), "Right / Left", "Next position on the X axis"), diff --git a/Assets/Scripts/StaticCamera.cs b/Assets/Scripts/StaticCamera.cs index a1de536d..c3f4b7b3 100644 --- a/Assets/Scripts/StaticCamera.cs +++ b/Assets/Scripts/StaticCamera.cs @@ -8,6 +8,7 @@ using HeavenStudio.Common; using HeavenStudio.Editor; using Jukebox; using Jukebox.Legacy; +using System; namespace HeavenStudio { @@ -210,8 +211,11 @@ namespace HeavenStudio overlayView.SetActive(toggle); } - public void SetAmbientGlowColour(Color colour) + [NonSerialized] public bool usingMinigameAmbientColor; + + public void SetAmbientGlowColour(Color colour, bool minigameColor, bool overrideMinigameColor = true) { + if (overrideMinigameColor) usingMinigameAmbientColor = minigameColor; ambientBg.color = colour; GameSettings.UpdatePreviewAmbient(colour); }