/////////////////////////////////////////////////////////////////////////////////////////////////
// GF - Color
// various color utilitary functions
/////////////////////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;

public class GFColor
{
	public static uint ColorToUint(Color c)
	{
		uint a = (uint)Mathf.RoundToInt(c.a * 255.0f);
		uint r = (uint)Mathf.RoundToInt(c.r * 255.0f);
		uint g = (uint)Mathf.RoundToInt(c.g * 255.0f);
		uint b = (uint)Mathf.RoundToInt(c.b * 255.0f);
		return (a << 24) | (r << 16) | (g << 8) | b;
	}

	public static Color UintToColor(uint u)
	{
		uint a = u >> 24;
		uint r = (u >> 16) & 0xff;
		uint g = (u >> 8) & 0xff;
		uint b = u & 0xff;
		return new Color((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f);
	}

	public static Color Lerp(Color a, Color b, float t)
	{
		float it = 1.0f - t;
		return new Color(a.r * it + b.r * t, a.g * it + b.g * t, a.b * it + b.b * t, a.a * it + b.a * t );
	}

    public static void SetMaterialColor(Material m, Color diffuse)
    {
        m.color = diffuse;
    }

    public static void SetMaterialColor(Material m, Color diffuse, Color emmisive, float f = 1f)
    {
        m.color = diffuse;
        m.SetColor("_EmissionColor", emmisive * f);
    }
}
