mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 13:37:40 +02:00
Camera flashes (bug associated with fullscreen)
This commit is contained in:
116
Assets/Scripts/Games/Global/Flash.cs
Normal file
116
Assets/Scripts/Games/Global/Flash.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using RhythmHeavenMania.Util;
|
||||
using System.Linq;
|
||||
|
||||
namespace RhythmHeavenMania.Games.Global
|
||||
{
|
||||
public class Flash : MonoBehaviour
|
||||
{
|
||||
public float startBeat;
|
||||
public float length;
|
||||
|
||||
public Color startColor;
|
||||
public Color endColor;
|
||||
|
||||
public EasingFunction.Ease ease;
|
||||
private EasingFunction.Function func;
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
[SerializeField] private Color currentCol;
|
||||
|
||||
private List<Beatmap.Entity> allFadeEvents = new List<Beatmap.Entity>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
this.gameObject.transform.SetParent(GameManager.instance.gameObject.transform);
|
||||
this.gameObject.layer = 3;
|
||||
this.gameObject.transform.localScale = new Vector3(1, 1);
|
||||
|
||||
spriteRenderer = this.gameObject.AddComponent<SpriteRenderer>();
|
||||
|
||||
spriteRenderer.color = startColor;
|
||||
spriteRenderer.sortingOrder = 30001;
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("Sprites/GeneralPurpose/Square");
|
||||
|
||||
func = EasingFunction.GetEasingFunction(EasingFunction.Ease.Linear);
|
||||
|
||||
GameManager.instance.onBeatChanged += OnBeatChanged;
|
||||
}
|
||||
|
||||
public void OnBeatChanged(float beat)
|
||||
{
|
||||
// I really need to create a class for objects that are constant like the Spaceball Camera
|
||||
// startColor = new Color(1, 1, 1, 0);
|
||||
// endColor = new Color(1, 1, 1, 0);
|
||||
|
||||
allFadeEvents = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "flash" });
|
||||
Test(beat);
|
||||
}
|
||||
|
||||
private void Test(float beat)
|
||||
{
|
||||
Color startCol = Color.white;
|
||||
Color endCol = Color.white;
|
||||
|
||||
bool override_ = false;
|
||||
|
||||
if (allFadeEvents.Count > 0)
|
||||
{
|
||||
Beatmap.Entity startEntity = null;
|
||||
|
||||
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_)
|
||||
{
|
||||
Color colA = startEntity.colorA;
|
||||
Color colB = startEntity.colorB;
|
||||
|
||||
startCol = new Color(colA.r, colA.g, colA.b, startEntity.valA);
|
||||
endCol = new Color(colB.r, colB.g, colB.b, startEntity.valB);
|
||||
}
|
||||
|
||||
SetFade(startEntity.beat, startEntity.length, startCol, endCol, startEntity.ease);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
Test(Conductor.instance.songPositionInBeats);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Games/Global/Flash.cs.meta
Normal file
11
Assets/Scripts/Games/Global/Flash.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16a839834af94a042a3feb7a4762bafd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user