From 3466b2fa8db927493e284e8d6143e9dbd025c732 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:05:05 +0200 Subject: [PATCH] balloon fixed --- Assets/Resources/Games/monkeyWatch.prefab | 10 +++++ .../Games/MonkeyWatch/BalloonHandler.cs | 42 +++++++++++++++++-- .../Scripts/Games/MonkeyWatch/MonkeyWatch.cs | 12 +++--- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Assets/Resources/Games/monkeyWatch.prefab b/Assets/Resources/Games/monkeyWatch.prefab index d26d1709d..df054a446 100644 --- a/Assets/Resources/Games/monkeyWatch.prefab +++ b/Assets/Resources/Games/monkeyWatch.prefab @@ -17688,6 +17688,16 @@ MonoBehaviour: anchor: {fileID: 5973755251599500745} target: {fileID: 4339140097867587715} balloonTrans: {fileID: 5836723102826521910} + srs: + - {fileID: 9182958110959949118} + - {fileID: 8501495778278024990} + - {fileID: 6606279674685812598} + - {fileID: 8504151232427483742} + - {fileID: 1269034092386606761} + - {fileID: 3200788305752962139} + - {fileID: 2829749095567035486} + - {fileID: 5083661034436039098} + shadow: {fileID: 3790953526902078340} xOffset: -2.962 yOffset: -14.204 --- !u!1 &4183335457383268975 diff --git a/Assets/Scripts/Games/MonkeyWatch/BalloonHandler.cs b/Assets/Scripts/Games/MonkeyWatch/BalloonHandler.cs index 04245e08c..fd1e5cc37 100644 --- a/Assets/Scripts/Games/MonkeyWatch/BalloonHandler.cs +++ b/Assets/Scripts/Games/MonkeyWatch/BalloonHandler.cs @@ -10,12 +10,17 @@ namespace HeavenStudio.Games.Scripts_MonkeyWatch [SerializeField] private Transform anchor; [SerializeField] private Transform target; [SerializeField] private Transform balloonTrans; + [SerializeField] private SpriteRenderer[] srs; + [SerializeField] private SpriteRenderer shadow; [Header("Properties")] [SerializeField] private float xOffset; [SerializeField] private float yOffset; + private float shadowOpacity; private float additionalXOffset; private float additionalYOffset; + private double movementFirstBeat = -2; + private double movementLastBeat = -1; private List movements = new(); private int movementIndex = 0; @@ -34,10 +39,20 @@ namespace HeavenStudio.Games.Scripts_MonkeyWatch public Util.EasingFunction.Ease ease; } + private void Awake() + { + shadowOpacity = shadow.color.a; + } + public void Init(double beat) { var allEvents = EventCaller.GetAllInGameManagerList("monkeyWatch", new string[] { "balloon" }); allEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); + if (allEvents.Count > 0) + { + movementFirstBeat = allEvents[0].beat; + movementLastBeat = allEvents[^1].beat + allEvents[^1].length - 0.25; + } foreach (var e in allEvents) { movements.Add(new Movement @@ -59,7 +74,8 @@ namespace HeavenStudio.Games.Scripts_MonkeyWatch private void UpdateIndex() { movementIndex++; - if (movementIndex + 1 < movements.Count && Conductor.instance.songPositionAsDouble > movements[movementIndex].beat + movements[movementIndex].length) + if (movementIndex >= movements.Count) return; + if (Conductor.instance.songPositionInBeatsAsDouble > movements[movementIndex].beat + movements[movementIndex].length) { UpdateIndex(); } @@ -68,12 +84,30 @@ namespace HeavenStudio.Games.Scripts_MonkeyWatch private void Update() { var cond = Conductor.instance; - balloonTrans.gameObject.SetActive(movements.Count > 0); - if (movements.Count > 0) + float normalizedFirst = Mathf.Clamp01(cond.GetPositionFromBeat(movementFirstBeat, 0.25f)); + float normalizedLast = Mathf.Clamp01(cond.GetPositionFromBeat(movementLastBeat, 0.25f)); + if (normalizedFirst >= 1) { - if (movementIndex + 1 < movements.Count && cond.songPositionAsDouble > movements[movementIndex].beat + movements[movementIndex].length) + foreach (var sr in srs) + { + sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 1 - normalizedLast); + } + shadow.color = new Color(shadow.color.r, shadow.color.g, shadow.color.b, Mathf.Lerp(shadowOpacity, 0, normalizedLast)); + } + else + { + foreach (var sr in srs) + { + sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, normalizedFirst); + } + shadow.color = new Color(shadow.color.r, shadow.color.g, shadow.color.b, Mathf.Lerp(0, shadowOpacity, normalizedFirst)); + } + if (movements.Count > 0 && movementIndex < movements.Count) + { + if (cond.songPositionInBeatsAsDouble > movements[movementIndex].beat + movements[movementIndex].length) { UpdateIndex(); + if (movementIndex >= movements.Count) return; } var e = movements[movementIndex]; diff --git a/Assets/Scripts/Games/MonkeyWatch/MonkeyWatch.cs b/Assets/Scripts/Games/MonkeyWatch/MonkeyWatch.cs index 4278d7038..420c7bd4d 100644 --- a/Assets/Scripts/Games/MonkeyWatch/MonkeyWatch.cs +++ b/Assets/Scripts/Games/MonkeyWatch/MonkeyWatch.cs @@ -126,12 +126,12 @@ namespace HeavenStudio.Games.Loaders defaultLength = 4f, parameters = new List() { - new Param("angleStart", new EntityTypes.Float(0, 360, 0), "Start Angle"), - new Param("angleEnd", new EntityTypes.Float(0, 360, 0), "End Angle"), - new Param("yStart", new EntityTypes.Float(0, 200, 15), "Y Start"), - new Param("yEnd", new EntityTypes.Float(0, 200, 15), "Y End"), - new Param("xStart", new EntityTypes.Float(0, 200, 15), "X Start"), - new Param("xEnd", new EntityTypes.Float(0, 200, 15), "X End"), + new Param("angleStart", new EntityTypes.Float(-360, 360, 0), "Start Angle"), + new Param("angleEnd", new EntityTypes.Float(-360, 360, 0), "End Angle"), + new Param("yStart", new EntityTypes.Float(-200, 200, 0), "Y Start"), + new Param("yEnd", new EntityTypes.Float(-200, 200, 0), "Y End"), + new Param("xStart", new EntityTypes.Float(-200, 200, 0), "X Start"), + new Param("xEnd", new EntityTypes.Float(-200, 200, 0), "X End"), new Param("ease", Util.EasingFunction.Ease.Linear, "Ease") } }