1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-22 16:24:20 +00:00
gravity-fusion/Assets/Components/Hue.cs

46 lines
1.1 KiB
C#
Raw Normal View History

2019-10-06 13:04:50 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Particle))]
public class Hue : MonoBehaviour
{
protected Gradient _possibleColors;
protected Particle particle;
protected Material material;
2019-10-06 15:44:41 +00:00
protected Color color;
2019-10-06 13:04:50 +00:00
protected void Awake() {
particle = GetComponent<Particle>();
material = new Material(Shader.Find("Custom/HSVRangeShader"));
}
public Gradient PossibleColors {
get {
return _possibleColors;
}
set {
_possibleColors = value;
2019-10-06 15:44:41 +00:00
color = _possibleColors.Evaluate(Random.value);
2019-10-06 13:04:50 +00:00
}
}
2019-10-06 15:44:41 +00:00
public void RefreshColor() {
Vector4 hsva = new Vector4(0, 0, particle.disappear.FractionLeft - 1, 0);
Color.RGBToHSV(color, out hsva.x, out _, out _);
material.SetVector("_HSVAAdjust", hsva);
2019-10-06 13:04:50 +00:00
}
protected void Start() {
particle.mainRenderer.material = material;
particle.auraRenderer.material = material;
particle.detailsRenderer.material = material;
}
2019-10-06 15:44:41 +00:00
protected void Update() {
RefreshColor();
}
2019-10-06 13:04:50 +00:00
}