148 lines
3.6 KiB
C#
148 lines
3.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
public class ThemeManager : MonoBehaviour
|
|
{
|
|
|
|
[Header("Color Mixer")]
|
|
[Range(0f,1f)]
|
|
public float r = 1;
|
|
|
|
[Range(0f, 1f)]
|
|
public float g = 1;
|
|
|
|
[Range(0f, 1f)]
|
|
public float b = 1;
|
|
|
|
public Color baseColor;
|
|
|
|
[Range(0f, 1f)]
|
|
public float accentMult = 0.5f;
|
|
public Color accentColor;
|
|
|
|
[Range(0f, 1f)]
|
|
public float mainMult = 0.2f;
|
|
public Color mainColor;
|
|
|
|
[Range(0f, 1f)]
|
|
public float fxMult = 0.6f;
|
|
public Color fxColor;
|
|
|
|
[Header("Receivers")]
|
|
public Material[] accentMats;
|
|
public Material[] mainMats;
|
|
public Material[] fxMats;
|
|
public ParticleSystem[] particleSystems;
|
|
public Light2D[] lights;
|
|
|
|
public float randomizerSmoothness = 0.01f;
|
|
public float randomizerIntensity = 0.1f;
|
|
public Camera mainCam;
|
|
|
|
private void OnValidate()
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
baseColor = new Color(r, g, b);
|
|
accentColor = new Color(r * accentMult, g * accentMult, b * accentMult);
|
|
mainColor = new Color(r * mainMult, g * mainMult, b * mainMult);
|
|
fxColor = new Color(r * fxMult, g * fxMult, b * fxMult);
|
|
|
|
foreach (Material mat in mainMats)
|
|
{
|
|
mat.color = mainColor;
|
|
}
|
|
|
|
foreach (Material mat in fxMats)
|
|
{
|
|
mat.color = fxColor;
|
|
}
|
|
|
|
foreach (Material mat in accentMats)
|
|
{
|
|
mat.color = accentColor;
|
|
}
|
|
|
|
foreach (ParticleSystem particle in particleSystems)
|
|
{
|
|
particle.startColor = fxColor;
|
|
}
|
|
|
|
foreach (Light2D light in lights)
|
|
{
|
|
light.color = fxColor;
|
|
}
|
|
|
|
mainCam.backgroundColor = mainColor;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
targetColor = baseColor;
|
|
}
|
|
|
|
Color targetColor;
|
|
public void SetColor(Color color)
|
|
{
|
|
targetColor = color;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
r = Mathf.Lerp(r, targetColor.r, randomizerSmoothness * Time.deltaTime);
|
|
g = Mathf.Lerp(g, targetColor.g, randomizerSmoothness * Time.deltaTime);
|
|
b = Mathf.Lerp(b, targetColor.b, randomizerSmoothness * Time.deltaTime);
|
|
|
|
Refresh();
|
|
}
|
|
bool addR,addG, addB;
|
|
|
|
public float minR, minG, minB;
|
|
public void Randomize(float intensity = 1f)
|
|
{
|
|
Color newC = new Color(Random.Range(minR, 1f), Random.Range(minG, 1f), Random.Range(minB, 1f));
|
|
float rDiff = newC.r - r;
|
|
float gDiff = newC.g - g;
|
|
float bDiff = newC.b - b;
|
|
|
|
|
|
targetColor= new Color(r + (rDiff * randomizerIntensity), g + (gDiff * randomizerIntensity), b + (bDiff * randomizerIntensity));
|
|
return;
|
|
if(r <= minR)
|
|
{
|
|
addR = true;
|
|
}else if(r >= 0.9f)
|
|
{
|
|
addR = false;
|
|
}
|
|
|
|
if(g <= minG)
|
|
{
|
|
addG = true;
|
|
}else if(g >= 0.9f)
|
|
{
|
|
addG = false;
|
|
}
|
|
|
|
if(b <= minB)
|
|
{
|
|
addB = true;
|
|
}else if (b >= 0.9f)
|
|
{
|
|
addB = false;
|
|
}
|
|
|
|
float rA = ((addR) ? Random.Range(0f, 1 - r) : -Random.Range(0f, r / randomizerIntensity)) * intensity * randomizerIntensity;
|
|
float rG = ((addG) ? Random.Range(0f, 1 - g) : -Random.Range(0f, g / randomizerIntensity)) *intensity * randomizerIntensity;
|
|
float rB = ((addB) ? Random.Range(0f, 1 - b) : -Random.Range(0f, b / randomizerIntensity)) *intensity * randomizerIntensity;
|
|
|
|
targetColor = new Color(Mathf.Clamp(r+rA,minR,1), Mathf.Clamp(g + rG,minG,1), Mathf.Clamp(b + rB,minB,1));
|
|
|
|
}
|
|
}
|