예제 #1
0
        public static GUIStyle ColoredBox(Color boxColor, int border, float alphaFalloff)
        {
            GUIStyle style = new GUIStyle("box");
            Texture2D texture = new Texture2D(64, 64);
            Color[] pixels = new Color[texture.height * texture.width];
            float alpha = boxColor.a;

            for (int y = 0; y < texture.height; y++) {
                for (int x = 0; x < texture.width; x++) {
                    bool isBorder = (x < border || x > texture.width - border - 1 || y < border || y > texture.height - border - 1);
                    Color pixel = isBorder ? boxColor : boxColor.SetValues(boxColor / 2, Channels.RGB);
                    pixel.a = isBorder ? alpha : alpha * alphaFalloff;
                    pixels[y * texture.width + x] = pixel;
                }
            }

            texture.SetPixels(pixels);
            texture.Apply();
            style.normal.background = texture;

            return style;
        }
예제 #2
0
        public static Texture2D Box(Color boxColor, int border = 1, float alphaFalloff = 1f)
        {
            var texture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
            var pixels = new Color[texture.height * texture.width];
            var alpha = boxColor.a;

            for (int y = 0; y < texture.height; y++)
            {
                for (int x = 0; x < texture.width; x++)
                {
                    bool isBorder = (x < border || x > texture.width - border - 1 || y < border || y > texture.height - border - 1);
                    var pixel = isBorder ? boxColor : boxColor.SetValues(boxColor / 2, Channels.RGB);

                    pixel.a = isBorder ? alpha : alpha * alphaFalloff;
                    pixels[y * texture.width + x] = pixel;
                }
            }

            texture.filterMode = FilterMode.Point;
            texture.hideFlags = HideFlags.DontSave;
            texture.SetPixels(pixels);
            texture.Apply();

            return texture;
        }