Example #1
0
        public static void Color32Field(string hash, string name, ref Color32 value, float ident = 0.0f, WatchButtonCallback watch = null, bool noSpace = false, bool noTypeLabel = false, ColorPicker.OnColor32Changed onColor32Changed = null)
        {
            GUILayout.BeginHorizontal();

            if (ident != 0.0f)
            {
                GUILayout.Space(ident);
            }

            if (!noTypeLabel)
            {
                GUI.contentColor = config.typeColor;
                GUILayout.Label("Color");
            }

            GUI.contentColor = config.nameColor;
            GUILayout.Label(name);

            GUI.contentColor = config.valueColor;

            if (!noSpace)
            {
                GUILayout.FlexibleSpace();
            }

            ByteField(hash + ".r", "r", ref value.r, 0.0f, true, true);
            ByteField(hash + ".g", "g", ref value.g, 0.0f, true, true);
            ByteField(hash + ".b", "b", ref value.b, 0.0f, true, true);
            ByteField(hash + ".a", "a", ref value.a, 0.0f, true, true);

            if (onColor32Changed != null)
            {
                if (GUILayout.Button("", GUILayout.Width(72)))
                {
                    var picker = ModTools.Instance.colorPicker;
                    if (picker != null)
                    {
                        picker.SetColor(value, onColor32Changed);

                        Vector2 mouse = Input.mousePosition;
                        mouse.y = Screen.height - mouse.y;

                        picker.rect.position = mouse;
                        picker.visible       = true;
                    }
                }

                var lastRect = GUILayoutUtility.GetLastRect();
                lastRect.x      += 4.0f;
                lastRect.y      += 4.0f;
                lastRect.width  -= 8.0f;
                lastRect.height -= 8.0f;
                GUI.DrawTexture(lastRect, ColorPicker.GetColorTexture(hash, value), ScaleMode.StretchToFill);
            }

            if (watch != null)
            {
                if (GUILayout.Button("Watch"))
                {
                    watch();
                }
            }

            GUI.contentColor = Color.white;

            GUILayout.EndHorizontal();
        }
Example #2
0
        static public void ColorField(string hash, string name, ref Color value, float ident = 0.0f, WatchButtonCallback watch = null, bool noSpace = false, bool noTypeLabel = false, ColorPicker.OnColorChanged onColorChanged = null)
        {
            GUILayout.BeginHorizontal();

            if (ident != 0.0f)
            {
                GUILayout.Space(ident);
            }

            if (!noTypeLabel)
            {
                GUI.contentColor = config.typeColor;
                GUILayout.Label("Color");
            }

            GUI.contentColor = config.nameColor;
            GUILayout.Label(name);

            GUI.contentColor = config.valueColor;

            if (!noSpace)
            {
                GUILayout.FlexibleSpace();
            }

            var r = (byte)(Mathf.Clamp(value.r * 255.0f, Byte.MinValue, Byte.MaxValue));
            var g = (byte)(Mathf.Clamp(value.g * 255.0f, Byte.MinValue, Byte.MaxValue));
            var b = (byte)(Mathf.Clamp(value.b * 255.0f, Byte.MinValue, Byte.MaxValue));
            var a = (byte)(Mathf.Clamp(value.a * 255.0f, Byte.MinValue, Byte.MaxValue));

            ByteField(hash + ".r", "r", ref r, 0.0f, true, true);
            ByteField(hash + ".g", "g", ref g, 0.0f, true, true);
            ByteField(hash + ".b", "b", ref b, 0.0f, true, true);
            ByteField(hash + ".a", "a", ref a, 0.0f, true, true);

            value.r = Mathf.Clamp01((float)r / 255.0f);
            value.g = Mathf.Clamp01((float)g / 255.0f);
            value.b = Mathf.Clamp01((float)b / 255.0f);
            value.a = Mathf.Clamp01((float)a / 255.0f);

            if (onColorChanged != null)
            {
                if (value.r != r || value.g != g || value.b != b || value.a != a)
                {
                    onColorChanged(value);
                }

                if (GUILayout.Button("", GUILayout.Width(72)))
                {
                    var picker = ModTools.Instance.colorPicker;
                    if (picker != null)
                    {
                        picker.SetColor(value, onColorChanged);

                        Vector2 mouse = Input.mousePosition;
                        mouse.y = Screen.height - mouse.y;

                        picker.rect.position = mouse;
                        picker.visible       = true;
                    }
                }

                var lastRect = GUILayoutUtility.GetLastRect();
                lastRect.x      += 4.0f;
                lastRect.y      += 4.0f;
                lastRect.width  -= 8.0f;
                lastRect.height -= 8.0f;
                GUI.DrawTexture(lastRect, ColorPicker.GetColorTexture(hash, value), ScaleMode.StretchToFill);
            }

            if (watch != null)
            {
                if (GUILayout.Button("Watch"))
                {
                    watch();
                }
            }

            GUI.contentColor = Color.white;

            GUILayout.EndHorizontal();
        }