2022-02-03 02:09:50 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-05-16 05:29:39 +00:00
|
|
|
using HeavenStudio.Util;
|
|
|
|
using System.Linq;
|
2023-06-10 19:17:06 +00:00
|
|
|
using Jukebox;
|
|
|
|
using Jukebox.Legacy;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio
|
2022-02-03 02:09:50 +00:00
|
|
|
{
|
|
|
|
public class GameCamera : MonoBehaviour
|
|
|
|
{
|
|
|
|
public static GameCamera instance { get; private set; }
|
|
|
|
public new Camera camera;
|
|
|
|
|
2023-03-11 04:51:22 +00:00
|
|
|
public enum CameraAxis
|
|
|
|
{
|
|
|
|
All,
|
|
|
|
X,
|
|
|
|
Y,
|
|
|
|
Z
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
private List<RiqEntity> positionEvents = new();
|
|
|
|
private List<RiqEntity> rotationEvents = new();
|
|
|
|
private List<RiqEntity> shakeEvents = new();
|
2023-07-17 15:56:57 +00:00
|
|
|
private List<RiqEntity> colorEvents = new();
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
default cam position, for quick-resetting
|
|
|
|
**/
|
2022-07-27 22:35:18 +00:00
|
|
|
public static Vector3 defaultPosition = new Vector3(0, 0, -10);
|
|
|
|
public static Vector3 defaultRotEluer = new Vector3(0, 0, 0);
|
2022-08-17 03:24:39 +00:00
|
|
|
public static Vector3 defaultShake = new Vector3(0, 0, 0);
|
2023-04-23 19:27:23 +00:00
|
|
|
public static float defaultFoV = 53.15f;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
camera's current transformation
|
|
|
|
**/
|
|
|
|
private static Vector3 position;
|
|
|
|
private static Vector3 rotEluer;
|
2022-08-17 03:21:04 +00:00
|
|
|
private static Vector3 shakeResult;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
camera's last transformation
|
|
|
|
**/
|
|
|
|
private static Vector3 positionLast;
|
|
|
|
private static Vector3 rotEluerLast;
|
2022-08-17 03:21:04 +00:00
|
|
|
private static Vector3 shakeLast;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
transformations to apply *after* the global transform,
|
|
|
|
to use in minigame scripts (Spaceball, Rhythm Rally, Built to Scale, etc.)
|
|
|
|
and NOT in the editor
|
|
|
|
**/
|
|
|
|
public static Vector3 additionalPosition;
|
|
|
|
public static Vector3 additionalRotEluer;
|
|
|
|
public static Vector3 additionalScale;
|
2023-04-23 19:27:23 +00:00
|
|
|
public static float additionalFoV;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
2022-02-03 02:09:50 +00:00
|
|
|
[Header("Components")]
|
|
|
|
public Color baseColor;
|
|
|
|
|
2023-07-17 15:56:57 +00:00
|
|
|
public static Color currentColor;
|
|
|
|
|
2022-02-03 02:09:50 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
camera = this.GetComponent<Camera>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2022-05-16 05:29:39 +00:00
|
|
|
GameManager.instance.onBeatChanged += OnBeatChanged;
|
2022-02-03 02:09:50 +00:00
|
|
|
camera.backgroundColor = baseColor;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
ResetTransforms();
|
|
|
|
ResetAdditionalTransforms();
|
2023-07-17 15:56:57 +00:00
|
|
|
currentColor = baseColor;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
positionLast = defaultPosition;
|
|
|
|
rotEluerLast = defaultRotEluer;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public void OnBeatChanged(double beat)
|
2022-05-16 05:29:39 +00:00
|
|
|
{
|
|
|
|
ResetTransforms();
|
|
|
|
ResetAdditionalTransforms();
|
2023-07-17 15:56:57 +00:00
|
|
|
currentColor = baseColor;
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
positionLast = defaultPosition;
|
|
|
|
rotEluerLast = defaultRotEluer;
|
|
|
|
|
|
|
|
// this entire thing is a mess redo it later
|
|
|
|
//pos
|
2022-06-04 03:15:05 +00:00
|
|
|
positionEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "move camera" });
|
2022-06-06 16:54:49 +00:00
|
|
|
// legacy event
|
|
|
|
positionEvents.AddRange(EventCaller.GetAllInGameManagerList("gameManager", new string[] { "move camera" }));
|
2022-05-16 05:29:39 +00:00
|
|
|
|
|
|
|
//rot
|
2022-06-04 03:15:05 +00:00
|
|
|
rotationEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "rotate camera" });
|
2022-06-06 16:54:49 +00:00
|
|
|
positionEvents.AddRange(EventCaller.GetAllInGameManagerList("gameManager", new string[] { "rotate camera" }));
|
2022-05-16 05:29:39 +00:00
|
|
|
|
2022-08-17 03:21:04 +00:00
|
|
|
//screen shake time baybee
|
|
|
|
|
|
|
|
shakeEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "screen shake" });
|
|
|
|
|
2023-07-17 15:56:57 +00:00
|
|
|
//color/colour time baybee
|
|
|
|
|
|
|
|
colorEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "camera background color" });
|
|
|
|
|
2022-05-16 05:29:39 +00:00
|
|
|
UpdateCameraTranslate();
|
|
|
|
UpdateCameraRotate();
|
2022-08-17 03:21:04 +00:00
|
|
|
SetShakeIntensity();
|
2023-07-17 15:56:57 +00:00
|
|
|
UpdateCameraColor();
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
UpdateCameraTranslate();
|
|
|
|
UpdateCameraRotate();
|
2022-08-17 03:21:04 +00:00
|
|
|
SetShakeIntensity();
|
2023-07-17 15:56:57 +00:00
|
|
|
UpdateCameraColor();
|
2023-05-21 17:35:00 +00:00
|
|
|
}
|
2022-05-16 05:29:39 +00:00
|
|
|
|
2023-05-21 17:35:00 +00:00
|
|
|
private void LateUpdate()
|
|
|
|
{
|
2022-05-16 05:29:39 +00:00
|
|
|
Camera cam = GetCamera();
|
2023-04-23 19:27:23 +00:00
|
|
|
// rotate position by additional rotation
|
|
|
|
Vector3 userPos = Quaternion.Euler(additionalRotEluer) * position;
|
|
|
|
cam.transform.localPosition = userPos + additionalPosition + shakeResult;
|
2022-05-16 05:29:39 +00:00
|
|
|
cam.transform.eulerAngles = rotEluer + additionalRotEluer;
|
2023-04-23 19:27:23 +00:00
|
|
|
cam.fieldOfView = additionalFoV;
|
2023-07-17 15:56:57 +00:00
|
|
|
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"];
|
|
|
|
}
|
|
|
|
}
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateCameraTranslate()
|
|
|
|
{
|
|
|
|
foreach (var e in positionEvents)
|
|
|
|
{
|
|
|
|
float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length);
|
|
|
|
if (prog >= 0f)
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
Util.EasingFunction.Function func = Util.EasingFunction.GetEasingFunction((Util.EasingFunction.Ease) e["ease"]);
|
2023-03-11 04:51:22 +00:00
|
|
|
switch (e["axis"])
|
|
|
|
{
|
|
|
|
case (int) CameraAxis.X:
|
|
|
|
position.x = func(positionLast.x, e["valA"], Mathf.Min(prog, 1f));
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Y:
|
|
|
|
position.y = func(positionLast.y, e["valB"], Mathf.Min(prog, 1f));
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Z:
|
|
|
|
position.z = func(positionLast.z, -e["valC"], Mathf.Min(prog, 1f));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
float dx = func(positionLast.x, e["valA"], Mathf.Min(prog, 1f));
|
|
|
|
float dy = func(positionLast.y, e["valB"], Mathf.Min(prog, 1f));
|
|
|
|
float dz = func(positionLast.z, -e["valC"], Mathf.Min(prog, 1f));
|
|
|
|
position = new Vector3(dx, dy, dz);
|
|
|
|
break;
|
|
|
|
}
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
if (prog > 1f)
|
|
|
|
{
|
2023-03-11 04:51:22 +00:00
|
|
|
switch (e["axis"])
|
|
|
|
{
|
|
|
|
case (int) CameraAxis.X:
|
|
|
|
positionLast.x = e["valA"];
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Y:
|
|
|
|
positionLast.y = e["valB"];
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Z:
|
|
|
|
positionLast.z = -e["valC"];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
positionLast = new Vector3(e["valA"], e["valB"], -e["valC"]);
|
|
|
|
break;
|
|
|
|
}
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateCameraRotate()
|
|
|
|
{
|
|
|
|
foreach (var e in rotationEvents)
|
|
|
|
{
|
|
|
|
float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length);
|
|
|
|
if (prog >= 0f)
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
Util.EasingFunction.Function func = Util.EasingFunction.GetEasingFunction((Util.EasingFunction.Ease) e["ease"]);
|
2023-03-11 04:51:22 +00:00
|
|
|
switch (e["axis"])
|
|
|
|
{
|
|
|
|
case (int) CameraAxis.X:
|
|
|
|
rotEluer.x = func(rotEluerLast.x, e["valA"], Mathf.Min(prog, 1f));
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Y:
|
|
|
|
rotEluer.y = func(rotEluerLast.y, e["valB"], Mathf.Min(prog, 1f));
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Z:
|
|
|
|
rotEluer.z = func(rotEluerLast.z, -e["valC"], Mathf.Min(prog, 1f));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
float dx = func(rotEluerLast.x, e["valA"], Mathf.Min(prog, 1f));
|
|
|
|
float dy = func(rotEluerLast.y, e["valB"], Mathf.Min(prog, 1f));
|
|
|
|
float dz = func(rotEluerLast.z, -e["valC"], Mathf.Min(prog, 1f));
|
|
|
|
rotEluer = new Vector3(dx, dy, dz); //I'm stupid and forgot to negate the rotation gfd 😢
|
|
|
|
break;
|
|
|
|
}
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
if (prog > 1f)
|
|
|
|
{
|
2023-03-11 04:51:22 +00:00
|
|
|
switch (e["axis"])
|
|
|
|
{
|
|
|
|
case (int) CameraAxis.X:
|
|
|
|
rotEluerLast.x = e["valA"];
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Y:
|
|
|
|
rotEluerLast.y = e["valB"];
|
|
|
|
break;
|
|
|
|
case (int) CameraAxis.Z:
|
|
|
|
rotEluerLast.z = -e["valC"];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rotEluerLast = new Vector3(e["valA"], e["valB"], -e["valC"]);
|
|
|
|
break;
|
|
|
|
}
|
2022-08-21 23:46:45 +00:00
|
|
|
rotEluerLast = new Vector3(e["valA"], e["valB"], -e["valC"]);
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 03:21:04 +00:00
|
|
|
private void SetShakeIntensity()
|
|
|
|
{
|
|
|
|
foreach (var e in shakeEvents)
|
|
|
|
{
|
|
|
|
float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length);
|
|
|
|
if (prog >= 0f)
|
|
|
|
{
|
2022-08-19 20:48:55 +00:00
|
|
|
float fac = Mathf.Cos(Time.time * 80f) * 0.5f;
|
2022-08-21 23:46:45 +00:00
|
|
|
shakeResult = new Vector3(fac * e["valA"], fac * e["valB"]);
|
2022-08-17 03:21:04 +00:00
|
|
|
}
|
|
|
|
if (prog > 1f)
|
|
|
|
{
|
2022-08-17 03:30:22 +00:00
|
|
|
shakeResult = new Vector3(0, 0);
|
2022-08-17 03:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 05:29:39 +00:00
|
|
|
public static void ResetTransforms()
|
|
|
|
{
|
|
|
|
position = defaultPosition;
|
|
|
|
rotEluer = defaultRotEluer;
|
2022-08-17 03:24:39 +00:00
|
|
|
shakeResult = defaultShake;
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void ResetAdditionalTransforms()
|
|
|
|
{
|
|
|
|
additionalPosition = new Vector3(0, 0, 0);
|
|
|
|
additionalRotEluer = new Vector3(0, 0, 0);
|
2023-04-23 19:27:23 +00:00
|
|
|
additionalFoV = defaultFoV;
|
2022-05-16 05:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Camera GetCamera()
|
|
|
|
{
|
|
|
|
return instance.camera;
|
2022-02-03 02:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|