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;
|
|
|
|
|
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-05-07 20:33:15 +00:00
|
|
|
[NonSerialized] public float startBeat;
|
|
|
|
[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-05-07 20:33:15 +00:00
|
|
|
[NonSerialized] public EasingFunction.Ease ease;
|
|
|
|
[NonSerialized] private 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-05-07 20:33:15 +00:00
|
|
|
[NonSerialized] private List<DynamicBeatmap.DynamicEntity> allFadeEvents = new List<DynamicBeatmap.DynamicEntity>();
|
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;
|
2022-02-08 01:07:03 +00:00
|
|
|
func = EasingFunction.GetEasingFunction(EasingFunction.Ease.Linear);
|
|
|
|
GameManager.instance.onBeatChanged += OnBeatChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnBeatChanged(float beat)
|
|
|
|
{
|
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-05-07 20:33:15 +00:00
|
|
|
private void FindFadeFromBeat(float beat)
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
|
|
|
Color startCol = Color.white;
|
|
|
|
Color endCol = Color.white;
|
|
|
|
|
|
|
|
bool override_ = false;
|
|
|
|
|
|
|
|
if (allFadeEvents.Count > 0)
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
DynamicBeatmap.DynamicEntity startEntity = null;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startEntity != null)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-08-22 00:50:19 +00:00
|
|
|
SetFade(startEntity.beat, startEntity.length, startCol, endCol, (EasingFunction.Ease) startEntity["ease"]);
|
2022-02-08 01:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFade(float beat, float length, Color startCol, Color endCol, EasingFunction.Ease ease)
|
|
|
|
{
|
|
|
|
this.startBeat = beat;
|
|
|
|
this.length = length;
|
|
|
|
this.startColor = startCol;
|
|
|
|
this.endColor = endCol;
|
|
|
|
this.ease = ease;
|
|
|
|
func = EasingFunction.GetEasingFunction(ease);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
FindFadeFromBeat(Conductor.instance.songPositionInBeats);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|