UnityEditor.ColorPicker.MakeTexture C# (CSharp) Method

MakeTexture() public static method

public static MakeTexture ( int width, int height ) : Texture2D
width int
height int
return UnityEngine.Texture2D
        public static Texture2D MakeTexture(int width, int height)
        {
            return new Texture2D(width, height, TextureFormat.ARGB32, false) { hideFlags = HideFlags.HideAndDontSave, wrapMode = TextureWrapMode.Clamp, hideFlags = HideFlags.HideAndDontSave };
        }

Usage Example

示例#1
0
        public static void DrawPreview(Rect position)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            if (EyeDropper.styles == null)
            {
                EyeDropper.styles = new EyeDropper.Styles();
            }
            Texture2D texture2D = EyeDropper.get.m_Preview;
            int       num1      = (int)Mathf.Ceil(position.width / 10f);
            int       num2      = (int)Mathf.Ceil(position.height / 10f);

            if ((Object)texture2D == (Object)null)
            {
                EyeDropper.get.m_Preview = texture2D = ColorPicker.MakeTexture(num1, num2);
                texture2D.filterMode     = UnityEngine.FilterMode.Point;
            }
            if (texture2D.width != num1 || texture2D.height != num2)
            {
                texture2D.Resize(num1, num2);
            }
            Vector2 screenPoint = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
            Vector2 pixelPos    = screenPoint - new Vector2((float)(num1 / 2), (float)(num2 / 2));

            texture2D.SetPixels(InternalEditorUtility.ReadScreenPixel(pixelPos, num1, num2), 0);
            texture2D.Apply(true);
            Graphics.DrawTexture(position, (Texture)texture2D);
            float    width = position.width / (float)num1;
            GUIStyle dropperVerticalLine = EyeDropper.styles.eyeDropperVerticalLine;
            float    x = position.x;

            while ((double)x < (double)position.xMax)
            {
                Rect position1 = new Rect(Mathf.Round(x), position.y, width, position.height);
                dropperVerticalLine.Draw(position1, false, false, false, false);
                x += width;
            }
            float    height = position.height / (float)num2;
            GUIStyle dropperHorizontalLine = EyeDropper.styles.eyeDropperHorizontalLine;
            float    y = position.y;

            while ((double)y < (double)position.yMax)
            {
                Rect position1 = new Rect(position.x, Mathf.Floor(y), position.width, height);
                dropperHorizontalLine.Draw(position1, false, false, false, false);
                y += height;
            }
            Rect position2 = new Rect((screenPoint.x - pixelPos.x) * width + position.x, (screenPoint.y - pixelPos.y) * height + position.y, width, height);

            EyeDropper.styles.eyeDropperPickedPixel.Draw(position2, false, false, false, false);
        }
All Usage Examples Of UnityEditor.ColorPicker::MakeTexture