Example #1
0
    }//spawnSprite

    //*******************************************************
    //*******************************************************
    public static void CircleOnTex(Texture2D tex, int cx, int cy, int rad, Color color, float outlineThickness = 0.2f, float outlineBrightness = 0.75f)
    {
        int x, y, px, nx, py, ny, d;

        Color altColor;

        if (color != Color.clear)
        {
            altColor = UColor.ChangeRelativeBrightness(color, outlineBrightness);
        }
        else
        {
            altColor = Color.black;
        }//else

        Color[] fillColorArray = tex.GetPixels();

        for (var i = 0; i < fillColorArray.Length; ++i)
        {
            fillColorArray[i] = Color.clear;
        }

        tex.SetPixels(fillColorArray);

        for (x = 0; x <= rad; x++)
        {
            d = (int)Mathf.Ceil(Mathf.Sqrt(rad * rad - x * x));
            for (y = 0; y <= d; y++)
            {
                Vector2 mag      = new Vector2(x, y);
                Color   theColor = color;
                if (mag.magnitude > rad * (1 - outlineThickness))
                {
                    theColor = altColor;
                }//if

                px = cx + x;
                nx = cx - x;
                py = cy + y;
                ny = cy - y;

                tex.SetPixel(px, py, theColor);
                tex.SetPixel(nx, py, theColor);

                tex.SetPixel(px, ny, theColor);
                tex.SetPixel(nx, ny, theColor);
            } //for
        }     //for
    }         //circleOnTex
Example #2
0
    }//setupTile

    public void setupTile(int links)
    {
        //If we've done it already, set the pointer to the existing texture
        if (!tileLists.ContainsKey(color.ToString()))
        {
            Texture2D[] allTextures = new Texture2D[16];
            //Make all 16 tiles
            for (int i = 0; i < allTextures.Length; i++)
            {
                Texture2D tex = new Texture2D(pixelWidth, pixelHeight);
                tex.filterMode = FilterMode.Point;
                tex.wrapMode   = TextureWrapMode.Repeat;

                int outlineInt = Mathf.FloorToInt(outlineSize * 10 + 1);
                for (int y = 0; y < pixelHeight; y++)
                {
                    for (int x = 0; x < pixelWidth; x++)
                    {
                        Color pixelColor = color;

                        Color altColor;
                        altColor   = UColor.ChangeRelativeBrightness(color, outlineBrightness);
                        altColor.a = 1.0f;

                        if (isNo(i, 1)) // up
                        {
                            if (y >= pixelHeight - outlineInt - 1)
                            {
                                pixelColor = altColor;
                            }
                        }//if

                        if (isNo(i, 2)) // right
                        {
                            if (x >= pixelWidth - outlineInt - 1)
                            {
                                pixelColor = altColor;
                            }
                        }//if

                        if (isNo(i, 4)) // down
                        {
                            if (y <= outlineInt)
                            {
                                pixelColor = altColor;
                            }
                        }//if

                        if (isNo(i, 8)) // left
                        {
                            if (x <= outlineInt)
                            {
                                pixelColor = altColor;
                            }
                        }//if

                        tex.SetPixel(x, y, pixelColor);
                    } //for
                }     //for
                tex.Apply();
                allTextures[i] = tex;
            } //for
            tileLists.Add(color.ToString(), allTextures);
        }     //if

        //Point it at the requested one
        texture = tileLists[color.ToString()][links];
    }//setupTile
Example #3
0
    }//setupCircle

    public void setupTileStrip()
    {
        Texture2D[] allTextures = new Texture2D[16];

        //Make all 16 tiles
        for (int i = 0; i < allTextures.Length; i++)
        {
            Texture2D tex = new Texture2D(pixelWidth, pixelHeight);
            tex.filterMode = FilterMode.Point;
            tex.wrapMode   = TextureWrapMode.Repeat;

            int outlineInt = Mathf.FloorToInt(outlineSize * 10 + 1);
            for (int y = 0; y < pixelHeight; y++)
            {
                for (int x = 0; x < pixelWidth; x++)
                {
                    Color pixelColor = color;

                    Color altColor;
                    altColor   = UColor.ChangeRelativeBrightness(color, outlineBrightness);
                    altColor.a = 1.0f;

                    if (isNo(i, 1)) // up
                    {
                        if (y >= pixelHeight - outlineInt - 1)
                        {
                            pixelColor = altColor;
                        }
                    }//if

                    if (isNo(i, 2)) // right
                    {
                        if (x >= pixelWidth - outlineInt - 1)
                        {
                            pixelColor = altColor;
                        }
                    }//if

                    if (isNo(i, 4)) // down
                    {
                        if (y <= outlineInt)
                        {
                            pixelColor = altColor;
                        }
                    }//if

                    if (isNo(i, 8)) // left
                    {
                        if (x <= outlineInt)
                        {
                            pixelColor = altColor;
                        }
                    }//if

                    tex.SetPixel(x, y, pixelColor);
                } //for
            }     //for
            tex.Apply();
            allTextures[i] = tex;
        }//for

        tileLists.Add(color.ToString(), allTextures);

        Texture2D stripTex = new Texture2D(pixelWidth * allTextures.Length, pixelHeight);

        stripTex.filterMode = FilterMode.Point;
        stripTex.wrapMode   = TextureWrapMode.Clamp;

        for (int i = 0; i < allTextures.Length; i++)
        {
            stripTex.SetPixels(pixelWidth * i, 0, pixelWidth, pixelHeight, allTextures[i].GetPixels());
        }//for
        stripTex.Apply();
        texture = stripTex;
    }//setupTileStrip