Beispiel #1
0
    void setHueSprite(float oldHue, float newHue, Sprite sprite)
    {
        Rect      bounds = sprite.rect;
        Texture2D tex    = sprite.texture;

        for (int y = Mathf.RoundToInt(bounds.yMin); y < Mathf.RoundToInt(bounds.yMax); y++)
        {
            int xMin = Mathf.RoundToInt(bounds.xMin), xMax = Mathf.RoundToInt(bounds.xMax);
            for (int x = xMin; x < xMax; x++)
            {
                Color temp = tex.GetPixel(x, y);
                float hue, saturation, value;
                HSVColor.RGBToHSV(temp, out hue, out saturation, out value);
                temp = HSVColor.HSVToRGB((hue + (newHue - oldHue) + 1) % 1, saturation, value, temp.a);
                tex.SetPixel(x, y, temp);
            }
        }
        tex.Apply();
    }