2023-05-07 20:33:15 +00:00
|
|
|
using System;
|
2022-02-08 01:07:03 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2023-05-07 20:33:15 +00:00
|
|
|
using UnityEngine.UI;
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-02-08 01:07:03 +00:00
|
|
|
using System.Linq;
|
2023-06-10 19:13:29 +00:00
|
|
|
using Jukebox;
|
|
|
|
using Jukebox.Legacy;
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Global
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
|
|
|
public class Flash : MonoBehaviour
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
[NonSerialized] public double startBeat;
|
2023-05-07 20:33:15 +00:00
|
|
|
[NonSerialized] public float length;
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2023-05-07 20:33:15 +00:00
|
|
|
[NonSerialized] public Color startColor;
|
|
|
|
[NonSerialized] public Color endColor;
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
[NonSerialized] public Util.EasingFunction.Ease ease;
|
|
|
|
[NonSerialized] private Util.EasingFunction.Function func;
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2023-05-07 20:33:15 +00:00
|
|
|
[NonSerialized] private Image spriteRenderer;
|
2022-02-08 01:07:03 +00:00
|
|
|
|
|
|
|
[SerializeField] private Color currentCol;
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
[NonSerialized] private List<RiqEntity> allFadeEvents = new List<RiqEntity>();
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
private void Awake()
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
spriteRenderer = GetComponent<Image>();
|
|
|
|
spriteRenderer.color = currentCol;
|
2023-06-10 19:13:29 +00:00
|
|
|
func = Util.EasingFunction.GetEasingFunction(Util.EasingFunction.Ease.Linear);
|
2022-02-08 01:07:03 +00:00
|
|
|
GameManager.instance.onBeatChanged += OnBeatChanged;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void OnBeatChanged(double beat)
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
2022-07-28 23:07:19 +00:00
|
|
|
allFadeEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "flash" });
|
|
|
|
// backwards-compatibility baybee
|
|
|
|
allFadeEvents.AddRange(EventCaller.GetAllInGameManagerList("gameManager", new string[] { "flash" }));
|
2023-05-07 20:33:15 +00:00
|
|
|
allFadeEvents.Sort((x, y) => x.beat.CompareTo(y.beat));
|
|
|
|
|
|
|
|
FindFadeFromBeat(beat);
|
2022-02-08 01:07:03 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
private void FindFadeFromBeat(double beat)
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
|
|
|
Color startCol = Color.white;
|
|
|
|
Color endCol = Color.white;
|
|
|
|
|
|
|
|
bool override_ = false;
|
|
|
|
|
|
|
|
if (allFadeEvents.Count > 0)
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
RiqEntity startEntity = default(RiqEntity);
|
2022-02-08 01:07:03 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < allFadeEvents.Count; i++)
|
|
|
|
{
|
|
|
|
if (allFadeEvents[i].beat <= beat)
|
|
|
|
{
|
|
|
|
startEntity = allFadeEvents[i];
|
|
|
|
}
|
|
|
|
else if (i == 0 && allFadeEvents[i].beat > beat)
|
|
|
|
{
|
|
|
|
startEntity = allFadeEvents[i];
|
|
|
|
override_ = true;
|
|
|
|
startCol = new Color(1, 1, 1, 0);
|
|
|
|
endCol = new Color(1, 1, 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
if (!string.IsNullOrEmpty(startEntity.datamodel))
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
|
|
|
if (!override_)
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
Color colA = startEntity["colorA"];
|
|
|
|
Color colB = startEntity["colorB"];
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2022-08-21 23:46:45 +00:00
|
|
|
startCol = new Color(colA.r, colA.g, colA.b, startEntity["valA"]);
|
|
|
|
endCol = new Color(colB.r, colB.g, colB.b, startEntity["valB"]);
|
2022-02-08 01:07:03 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
SetFade(startEntity.beat, startEntity.length, startCol, endCol, (Util.EasingFunction.Ease) startEntity["ease"]);
|
2022-02-08 01:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void SetFade(double beat, float length, Color startCol, Color endCol, Util.EasingFunction.Ease ease)
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
|
|
|
this.startBeat = beat;
|
|
|
|
this.length = length;
|
|
|
|
this.startColor = startCol;
|
|
|
|
this.endColor = endCol;
|
|
|
|
this.ease = ease;
|
2023-06-10 19:13:29 +00:00
|
|
|
func = Util.EasingFunction.GetEasingFunction(ease);
|
2022-02-08 01:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
FindFadeFromBeat(Conductor.instance.songPositionInBeatsAsDouble);
|
2022-02-08 01:07:03 +00:00
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, length);
|
|
|
|
// normalizedBeat = Mathf.Clamp01(normalizedBeat);
|
|
|
|
|
|
|
|
currentCol = new Color(func(startColor.r, endColor.r, normalizedBeat), func(startColor.g, endColor.g, normalizedBeat), func(startColor.b, endColor.b, normalizedBeat), func(startColor.a, endColor.a, normalizedBeat));
|
|
|
|
spriteRenderer.color = currentCol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|