From adf5980fc64ca032c0ede9a48c33114432425575 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Mon, 20 Nov 2023 20:54:48 +0100 Subject: [PATCH] ok done now (#578) --- Assets/Scripts/Games/Global/Filter.cs | 81 +++++++-------------------- Assets/Scripts/Minigames.cs | 12 +++- 2 files changed, 30 insertions(+), 63 deletions(-) diff --git a/Assets/Scripts/Games/Global/Filter.cs b/Assets/Scripts/Games/Global/Filter.cs index b409a80e..3f0683d5 100644 --- a/Assets/Scripts/Games/Global/Filter.cs +++ b/Assets/Scripts/Games/Global/Filter.cs @@ -86,6 +86,12 @@ namespace HeavenStudio.Games.Global GameManager.instance.onBeatChanged += OnBeatChanged; + for (int i = 0; i < 10; i++) + { + var newAmplify = GameManager.instance.GameCamera.gameObject.AddComponent(); + amplifies.Add(newAmplify); + } + // Don't use this because of serialization, add to the "FilterType" enum above manually. // GenerateFilterTypeEnum(); } @@ -97,77 +103,30 @@ namespace HeavenStudio.Games.Global private void OnBeatChanged(double beat) { allFilterEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "filter" }); + allFilterEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); + foreach (var a in amplifies) + { + a.LutTexture = null; + a.BlendAmount = 1; + } } private void Update() { var songPosBeat = Conductor.instance.songPositionInBeatsAsDouble; - var filterIndexes = new List(); - for (int i = 0; i < allFilterEvents.Count; i++) + foreach (var e in allFilterEvents) { - var filter = allFilterEvents[i]; + if (e.beat > songPosBeat) continue; + var func = Util.EasingFunction.GetEasingFunction((Util.EasingFunction.Ease)e["ease"]); + int track = (int)e["track"]; + float normalizedBeat = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(e.beat, e.length)); - if (filter.beat > songPosBeat) - break; - if (filter.beat + filter.length < songPosBeat) - continue; + float intensity = func(1 - e["start"], 1 - e["end"], normalizedBeat); - filterIndexes.Add(i); + amplifies[track - 1].LutTexture = amplifyTextures[(int)e["filter"]]; + amplifies[track - 1].BlendAmount = intensity; } - - bool indexCountChanged = filterIndexes.Count != lastFilterIndexesCount; - - if (indexCountChanged) - { - for (int i = 0; i < amplifies.Count; i++) - { - Destroy(amplifies[i]); - } - amplifies.Clear(); - } - - for (int i = 0; i < filterIndexes.Count; i++) - { - var filter = allFilterEvents[filterIndexes[i]]; - - if (filter.beat <= songPosBeat && filter.beat + filter.length >= songPosBeat) - { - var fadeInTime = filter["fadein"] * 0.01f; - var fadeOutTime = filter["fadeout"] * 0.01f; - - var intensity = filter["inten"]; - intensity = Mathf.Lerp(1, 0, Mathp.Normalize(intensity, 0, 100)); - var blendAmount = intensity; - - var endFadeInTime = Mathf.Lerp((float) filter.beat, (float) filter.beat + filter.length, fadeInTime); - var startFadeOutTime = (float) filter.beat + (Mathf.Lerp(0, filter.length, Mathf.Lerp(1, 0, fadeOutTime))); - - if (songPosBeat < endFadeInTime) - { - var normalizedFadeIn = Mathp.Normalize((float) songPosBeat, (float) filter.beat, endFadeInTime); - blendAmount = Mathf.Lerp(1f, intensity, normalizedFadeIn); - } - else if (songPosBeat >= startFadeOutTime) - { - var normalizedFadeOut = Mathf.Clamp01(Mathp.Normalize((float) songPosBeat, startFadeOutTime, (float) filter.beat + filter.length)); - blendAmount = Mathf.Lerp(intensity, 1f, normalizedFadeOut); - } - - var newAmplify = - (indexCountChanged) ? - GameManager.instance.GameCamera.gameObject.AddComponent() : - (AmplifyColorEffect)GameManager.instance.GameCamera.GetComponents(typeof(AmplifyColorEffect))[i]; - - var texIndex = (int)filter["filter"]; - newAmplify.LutTexture = amplifyTextures[texIndex]; - newAmplify.BlendAmount = blendAmount; - - amplifies.Add(newAmplify); - } - } - - lastFilterIndexesCount = filterIndexes.Count; } /// diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 75604128..4afe66aa 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -781,9 +781,17 @@ namespace HeavenStudio new List() { new Param("filter", Games.Global.Filter.FilterType.grayscale, "Filter"), - new Param("inten", new EntityTypes.Float(0, 100, 100), "Intensity"), + // old + + /*new Param("inten", new EntityTypes.Float(0, 100, 100), "Intensity"), new Param("fadein", new EntityTypes.Float(0, 100, 0), "Fade In"), - new Param("fadeout", new EntityTypes.Float(0, 100, 0), "Fade Out") + new Param("fadeout", new EntityTypes.Float(0, 100, 0), "Fade Out")*/ + + // new + + new Param("start", new EntityTypes.Float(0, 1, 1), "Start Intensity"), + new Param("end", new EntityTypes.Float(0, 1, 1), "End Intensity"), + new Param("ease", Util.EasingFunction.Ease.Linear, "Ease"), } ), new GameAction("move camera", "Move Camera", 1f, true, new List()