HeavenStudioPlus/Assets/Scripts/Games/MonkeyWatch/BalloonHandler.cs

134 lines
4.8 KiB
C#
Raw Normal View History

Monkey watch (#555) * basic setup+inputs this is gonna be so annoying to optimize i am SO overwhelmed with the options that i have object pooling, disabling the monkeys, literally just placing them manually... idk. * custom monkeys + more setup stuff it's all coming together . * a few tweaks committing to update the spritesheet * hi ev * player stuff * player anims * particles * more of prefab * upscale for this sheet * prefab more * oops * anims n stuff * assign the stuff, a little bit of rotation * better sheet * balloon sheet * particles * Revert "particles" This reverts commit fe4d589731a3ceacc7d80b7fde520f87b1c6e745. * Revert "Revert "particles"" This reverts commit ce117b280d4bd7400bd40260f4d858f2d5fba9e3. * fixed the watch outline + pink monkey prefab variant the bccad really is a life saver * anims for monkeys * convert to dictionary yippee for dictionaries * better camera * click animations are all done * custom monkeys are actually good now :) * prefab adjustments * oopps2 * tweaked particles * inactive monkeys/custom monkeys + prefab fixes they should work perfectly now, and the prefab should also need no further adjustment hopefully... * many animations * click fixes * the prefab needed One more adjustment * oops again hopefully the shadow is good now * sheet adjustment * all yellow anims done * progress. starting on the monkeys appear block rn, and then i'll work on the monkey spawning logic. honestly should be pretty easy (and i DON'T think this will be something i look back on as if i was crazy :smile: ) * open / close hole * monkey spawning working better * pink monkey anims * clean slate * gonna test something * proper camera * Camera movements done * pink monkey sounds and a small bug fix * clock arrow now moves * gettin ready to spawn el monkeys * monkeys should spawn now ig * bug fixes * oops * monkeys appear added * more fixes yahoo * shadow tweak * bug fixes * zoom out beginnings * hour more smooth * smooth minute too * it now zooms out lol * middle monkey * oopsie doopsie * hot air balloon * oops * anim * disappear fix * ticks on input now * prepare earlier * tiny tweak * oops again * fixed the input bug * holes * middle monkey anims * fixed layering * zoom out tweaks and shadow movement * camera tweak * tweaks * quad * camera tweak * quart * inspcetor * shadow correct * Okay * zoom out seperation * instant * balloon movement * balloon fixed * fixed particle * icon * fixed beataction parameters * monkey watch camera refactor run sourcegen --------- Co-authored-by: AstrlJelly <bdlawson115@gmail.com> Co-authored-by: ev <85412919+evdial@users.noreply.github.com> Co-authored-by: minenice55 <star.elementa@gmail.com>
2024-01-29 03:04:19 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HeavenStudio.Games.Scripts_MonkeyWatch
{
public class BalloonHandler : MonoBehaviour
{
[Header("Components")]
[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<Movement> movements = new();
private int movementIndex = 0;
private struct Movement
{
public double beat;
public float length;
public float xStart;
public float xEnd;
public float yStart;
public float yEnd;
public float angleStart;
public float angleEnd;
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
{
beat = e.beat,
length = e.length,
xStart = e["xStart"],
xEnd = e["xEnd"],
yStart = e["yStart"],
yEnd = e["yEnd"],
angleStart = e["angleStart"],
angleEnd = e["angleEnd"],
ease = (Util.EasingFunction.Ease)e["ease"]
});
}
Update();
}
private void UpdateIndex()
{
movementIndex++;
if (movementIndex >= movements.Count) return;
if (Conductor.instance.songPositionInBeatsAsDouble > movements[movementIndex].beat + movements[movementIndex].length)
{
UpdateIndex();
}
}
private void Update()
{
var cond = Conductor.instance;
float normalizedFirst = Mathf.Clamp01(cond.GetPositionFromBeat(movementFirstBeat, 0.25f));
float normalizedLast = Mathf.Clamp01(cond.GetPositionFromBeat(movementLastBeat, 0.25f));
if (normalizedFirst >= 1)
{
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];
float normalizedBeat = Mathf.Clamp01(cond.GetPositionFromBeat(e.beat, e.length));
var func = Util.EasingFunction.GetEasingFunction(e.ease);
float newX = func(e.xStart, e.xEnd, normalizedBeat);
float newY = func(e.yStart, e.yEnd, normalizedBeat);
float newAngle = func(e.angleStart, e.angleEnd, normalizedBeat);
additionalXOffset = newX;
additionalYOffset = newY;
anchor.localEulerAngles = new Vector3(0, 0, newAngle);
}
balloonTrans.position = new Vector3(target.position.x + xOffset + additionalXOffset, target.position.y + yOffset + additionalYOffset, target.position.z);
}
}
}