Created
May 10, 2015 18:23
-
-
Save thebeardphantom/b8aa10165c87dfd6ca28 to your computer and use it in GitHub Desktop.
MixColors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
[ExecuteInEditMode] | |
public class MixColors : MonoBehaviour { | |
[SerializeField] | |
Color[] colors; | |
[SerializeField] | |
Image image; | |
[SerializeField] | |
float multiplier; | |
public Color result { get; private set; } | |
// Update is called once per frame | |
void Update() { | |
if(colors == null || colors.Length == 0) { | |
return; | |
} | |
var r = 0f; | |
var g = 0f; | |
var b = 0f; | |
var a = 0f; | |
foreach(var c in colors) { | |
r += c.r; | |
g += c.g; | |
b += c.b; | |
a += c.a; | |
} | |
r /= colors.Length; | |
g /= colors.Length; | |
b /= colors.Length; | |
a /= colors.Length; | |
result = new Color(r, g, b, a); | |
result *= multiplier; | |
if(image != null) { | |
image.color = result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment