Beispiel #1
0
    // Add material with color replacement shader, and generate color replacement texture
    private Material GetMaterial(Character character)
    {
        // this 256x1 texture is transparent. Each pixel represents the red color value to replace.
        // if pixel 10 is not transparent, every color with r=10 will be replaced by the color of the pixel
        Texture2D colorSwapTex = new Texture2D(256, 1, TextureFormat.RGBA32, false, false);

        colorSwapTex.filterMode = FilterMode.Point;

        // Reset texture
        for (int i = 0; i < colorSwapTex.width; ++i)
        {
            colorSwapTex.SetPixel(i, 0, new Color(0.0f, 0.0f, 0.0f, 0.0f));
        }

        colorSwapTex.Apply();

        // Define the swapping colors. Add white to highlights and black to shadows
        Color newUniformStripeColorLight     = Color.Lerp(character.GetCharacterColor(), ColorUtilities.ColorFromIntRGB(255, 255, 255), 0.5f);
        Color newUniformStripeColorVeryLight = Color.Lerp(newUniformStripeColorLight, ColorUtilities.ColorFromIntRGB(255, 255, 255), 0.5f);
        Color newUniformStripeColorDark      = Color.Lerp(character.GetCharacterColor(), ColorUtilities.ColorFromIntRGB(0, 0, 0), 0.5f);
        Color newUniformStripeColorVeryDark  = Color.Lerp(newUniformStripeColorDark, ColorUtilities.ColorFromIntRGB(0, 0, 0), 0.5f);
        Color newSkinColor             = character.GetCharacterSkinColor();
        Color newSkinColorDark         = Color.Lerp(newSkinColor, ColorUtilities.ColorFromIntRGB(0, 0, 0), 0.2f);
        Color newSkinColorVeryDark     = Color.Lerp(newSkinColorDark, ColorUtilities.ColorFromIntRGB(0, 0, 0), 0.5f);
        Color newUniformColor          = character.GetCharacterUniformColor();
        Color newUniformColorLight     = Color.Lerp(newUniformColor, ColorUtilities.ColorFromIntRGB(255, 255, 255), 0.2f);
        Color newUniformColorVeryLight = Color.Lerp(newUniformColorLight, ColorUtilities.ColorFromIntRGB(255, 255, 255), 0.5f);
        Color newUniformColorDark      = Color.Lerp(newUniformColor, ColorUtilities.ColorFromIntRGB(0, 0, 0), 0.2f);
        Color newUniformColorVeryDark  = Color.Lerp(newUniformColorDark, ColorUtilities.ColorFromIntRGB(0, 0, 0), 0.5f);

        // add the colors to the texture
        // TODO: Do something similar for HAIRCOLOR, when we have a character with visible hair
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMCOLOR, newUniformColor);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMCOLORLIGHT, newUniformColorLight);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMCOLORVERYLIGHT, newUniformColorVeryLight);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMCOLORDARK, newUniformColorDark);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMCOLORVERYDARK, newUniformColorVeryDark);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMSTRIPECOLOR, character.GetCharacterColor());
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMSTRIPECOLORLIGHT, newUniformStripeColorLight);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMSTRIPECOLORVERYLIGHT, newUniformStripeColorVeryLight);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMSTRIPECOLORDARK, newUniformStripeColorDark);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.UNIFORMSTRIPECOLOVVERYRDARK, newUniformStripeColorVeryDark);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.SKINCOLOR, newSkinColor);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.SKINCOLORDARK, newSkinColorDark);
        colorSwapTex = SwapColor(colorSwapTex, SpriteSwapRedColor.SKINCOLORVERYDARK, newSkinColorVeryDark);
        colorSwapTex.Apply();

        // load material and shader
        Material swapMaterial = new Material(Resources.Load <Material>("Shaders/ColorSwap"));
        Shader   swapShader   = Resources.Load <Shader>("Shaders/Sprites-ColorSwap");

        swapMaterial.shader = swapShader;
        swapMaterial.SetTexture("_SwapTex", colorSwapTex);

        return(swapMaterial);
    }
Beispiel #2
0
 public static Color RandomSkinColor()
 {
     // default skincolors to pick at random
     Color[] skinColors = new Color[]
     {
         ColorUtilities.ColorFromIntRGB(245, 217, 203),
         ColorUtilities.ColorFromIntRGB(237, 191, 167),
         ColorUtilities.ColorFromIntRGB(211, 142, 111),
         ColorUtilities.ColorFromIntRGB(234, 183, 138),
         ColorUtilities.ColorFromIntRGB(197, 132, 92),
         ColorUtilities.ColorFromIntRGB(88, 59, 43)
     };
     return(skinColors[UnityEngine.Random.Range(0, skinColors.Length - 1)]);
 }