internal ColorPickerHDRConfig(ColorPickerHDRConfig other)
 {
     this.minBrightness = other.minBrightness;
     this.maxBrightness = other.maxBrightness;
     this.minExposureValue = other.minExposureValue;
     this.maxExposureValue = other.maxExposureValue;
 }
 /// <summary>
 ///   <para>Method for showing a texture property control with a HDR color field and its color brightness float field.</para>
 /// </summary>
 /// <param name="label">The label used for the texture property.</param>
 /// <param name="textureProp">The texture property.</param>
 /// <param name="colorProperty">The color property (will be treated as a HDR color).</param>
 /// <param name="hdrConfig">The HDR color configuration used by the HDR Color Picker.</param>
 /// <param name="showAlpha">If false then the alpha channel information will be hidden in the GUI.</param>
 /// <returns>
 ///   <para>Return the Rect used.</para>
 /// </returns>
 public Rect TexturePropertyWithHDRColor(GUIContent label, MaterialProperty textureProp, MaterialProperty colorProperty, ColorPickerHDRConfig hdrConfig, bool showAlpha)
 {
   Rect rectForSingleLine = this.GetControlRectForSingleLine();
   this.TexturePropertyMiniThumbnail(rectForSingleLine, textureProp, label.text, label.tooltip);
   if (colorProperty.type != MaterialProperty.PropType.Color)
   {
     Debug.LogError((object) ("Assuming MaterialProperty.PropType.Color (was " + (object) colorProperty.type + ")"));
     return rectForSingleLine;
   }
   this.BeginAnimatedCheck(colorProperty);
   ColorPickerHDRConfig hdrConfig1 = hdrConfig ?? ColorPicker.defaultHDRConfig;
   Rect alignedFieldRect = MaterialEditor.GetLeftAlignedFieldRect(rectForSingleLine);
   EditorGUI.BeginChangeCheck();
   EditorGUI.showMixedValue = colorProperty.hasMixedValue;
   Color color1 = EditorGUI.ColorField(alignedFieldRect, GUIContent.none, colorProperty.colorValue, true, showAlpha, true, hdrConfig1);
   EditorGUI.showMixedValue = false;
   if (EditorGUI.EndChangeCheck())
     colorProperty.colorValue = color1;
   Rect fieldAndRightEdge = MaterialEditor.GetFlexibleRectBetweenFieldAndRightEdge(rectForSingleLine);
   float labelWidth = EditorGUIUtility.labelWidth;
   EditorGUIUtility.labelWidth = fieldAndRightEdge.width - EditorGUIUtility.fieldWidth;
   EditorGUI.BeginChangeCheck();
   Color color2 = EditorGUI.ColorBrightnessField(fieldAndRightEdge, GUIContent.Temp(" "), colorProperty.colorValue, hdrConfig1.minBrightness, hdrConfig1.maxBrightness);
   if (EditorGUI.EndChangeCheck())
     colorProperty.colorValue = color2;
   EditorGUIUtility.labelWidth = labelWidth;
   this.EndAnimatedCheck();
   return rectForSingleLine;
 }
 public static void Show(GUIView viewToUpdate, Color col, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig)
 {
   ColorPicker get = ColorPicker.get;
   get.m_HDR = hdr;
   get.m_HDRConfig = new ColorPickerHDRConfig(hdrConfig ?? ColorPicker.defaultHDRConfig);
   get.m_DelegateView = viewToUpdate;
   get.SetColor(col);
   get.m_OriginalColor = ColorPicker.get.m_Color;
   get.m_ShowAlpha = showAlpha;
   get.m_ModalUndoGroup = Undo.GetCurrentGroup();
   if (get.m_HDR)
     get.m_IsOSColorPicker = false;
   if (get.m_IsOSColorPicker)
   {
     OSColorPicker.Show(showAlpha);
   }
   else
   {
     get.titleContent = !hdr ? EditorGUIUtility.TextContent("Color") : EditorGUIUtility.TextContent("HDR Color");
     float y = (float) EditorPrefs.GetInt("CPickerHeight", (int) get.position.height);
     get.minSize = new Vector2(233f, y);
     get.maxSize = new Vector2(233f, y);
     get.InitIfNeeded();
     get.ShowAuxWindow();
   }
 }
Esempio n. 4
0
 private static Color DoColorField(Rect position, int id, Color value, bool showEyedropper, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig)
 {
   Event current = Event.current;
   GUIStyle colorField = EditorStyles.colorField;
   Color color1 = value;
   value = !EditorGUI.showMixedValue ? value : Color.white;
   EventType typeForControl = current.GetTypeForControl(id);
   switch (typeForControl)
   {
     case EventType.KeyDown:
       if (current.MainActionKeyForControl(id))
       {
         Event.current.Use();
         EditorGUI.showMixedValue = false;
         ColorPicker.Show(GUIView.current, value, showAlpha, hdr, hdrConfig);
         GUIUtility.ExitGUI();
         break;
       }
       break;
     case EventType.Repaint:
       Rect position1 = !showEyedropper ? position : colorField.padding.Remove(position);
       if (showEyedropper && EditorGUI.s_ColorPickID == id)
       {
         Color pickedColor = EyeDropper.GetPickedColor();
         pickedColor.a = value.a;
         EditorGUIUtility.DrawColorSwatch(position1, pickedColor, showAlpha, hdr);
       }
       else
         EditorGUIUtility.DrawColorSwatch(position1, value, showAlpha, hdr);
       if (showEyedropper)
       {
         colorField.Draw(position, GUIContent.none, id);
         break;
       }
       EditorStyles.colorPickerBox.Draw(position, GUIContent.none, id);
       break;
     default:
       if (typeForControl != EventType.ValidateCommand)
       {
         if (typeForControl != EventType.ExecuteCommand)
         {
           if (typeForControl == EventType.MouseDown)
           {
             if (showEyedropper)
               position.width -= 20f;
             if (position.Contains(current.mousePosition))
             {
               switch (current.button)
               {
                 case 0:
                   GUIUtility.keyboardControl = id;
                   EditorGUI.showMixedValue = false;
                   ColorPicker.Show(GUIView.current, value, showAlpha, hdr, hdrConfig);
                   GUIUtility.ExitGUI();
                   break;
                 case 1:
                   GUIUtility.keyboardControl = id;
                   string[] options1 = new string[2]
                   {
                     "Copy",
                     "Paste"
                   };
                   bool[] enabled = new bool[2]
                   {
                     true,
                     (ColorClipboard.HasColor() ? 1 : 0) != 0
                   };
                   EditorUtility.DisplayCustomMenu(position, options1, enabled, (int[]) null, (EditorUtility.SelectMenuItemFunction) ((data, options, selected) =>
                   {
                     if (selected == 0)
                     {
                       GUIView.current.SendEvent(EditorGUIUtility.CommandEvent("Copy"));
                     }
                     else
                     {
                       if (selected != 1)
                         return;
                       GUIView.current.SendEvent(EditorGUIUtility.CommandEvent("Paste"));
                     }
                   }), (object) null);
                   return color1;
               }
             }
             if (showEyedropper)
             {
               position.width += 20f;
               if (position.Contains(current.mousePosition))
               {
                 GUIUtility.keyboardControl = id;
                 EyeDropper.Start(GUIView.current);
                 EditorGUI.s_ColorPickID = id;
                 GUIUtility.ExitGUI();
                 break;
               }
               break;
             }
             break;
           }
           break;
         }
         if (GUIUtility.keyboardControl == id)
         {
           string commandName = current.commandName;
           if (commandName != null)
           {
             // ISSUE: reference to a compiler-generated field
             if (EditorGUI.\u003C\u003Ef__switch\u0024map3 == null)
             {
               // ISSUE: reference to a compiler-generated field
               EditorGUI.\u003C\u003Ef__switch\u0024map3 = new Dictionary<string, int>(6)
               {
                 {
                   "EyeDropperUpdate",
                   0
                 },
                 {
                   "EyeDropperClicked",
                   1
                 },
                 {
                   "EyeDropperCancelled",
                   2
                 },
                 {
                   "ColorPickerChanged",
                   3
                 },
                 {
                   "Copy",
                   4
                 },
                 {
                   "Paste",
                   5
                 }
               };
             }
             int num;
             // ISSUE: reference to a compiler-generated field
             if (EditorGUI.\u003C\u003Ef__switch\u0024map3.TryGetValue(commandName, out num))
             {
               switch (num)
               {
                 case 0:
                   HandleUtility.Repaint();
                   break;
                 case 1:
                   GUI.changed = true;
                   HandleUtility.Repaint();
                   Color lastPickedColor = EyeDropper.GetLastPickedColor();
                   lastPickedColor.a = value.a;
                   EditorGUI.s_ColorPickID = 0;
                   return lastPickedColor;
                 case 2:
                   HandleUtility.Repaint();
                   EditorGUI.s_ColorPickID = 0;
                   break;
                 case 3:
                   GUI.changed = true;
                   HandleUtility.Repaint();
                   return ColorPicker.color;
                 case 4:
                   ColorClipboard.SetColor(value);
                   current.Use();
                   break;
                 case 5:
                   Color color2;
                   if (ColorClipboard.TryGetColor(hdr, out color2))
                   {
                     if (!showAlpha)
                       color2.a = color1.a;
                     color1 = color2;
                     GUI.changed = true;
                     current.Use();
                     break;
                   }
                   break;
               }
             }
             else
               break;
           }
           else
             break;
         }
         else
           break;
       }
       else
       {
         string commandName = current.commandName;
         if (commandName != null)
         {
           // ISSUE: reference to a compiler-generated field
           if (EditorGUI.\u003C\u003Ef__switch\u0024map2 == null)
           {
             // ISSUE: reference to a compiler-generated field
             EditorGUI.\u003C\u003Ef__switch\u0024map2 = new Dictionary<string, int>(3)
             {
               {
                 "UndoRedoPerformed",
                 0
               },
               {
                 "Copy",
                 1
               },
               {
                 "Paste",
                 1
               }
             };
           }
           int num;
           // ISSUE: reference to a compiler-generated field
           if (EditorGUI.\u003C\u003Ef__switch\u0024map2.TryGetValue(commandName, out num))
           {
             if (num != 0)
             {
               if (num == 1)
               {
                 current.Use();
                 break;
               }
               break;
             }
             if (GUIUtility.keyboardControl == id && ColorPicker.visible)
             {
               ColorPicker.color = value;
               break;
             }
             break;
           }
           break;
         }
         break;
       }
   }
   return color1;
 }
Esempio n. 5
0
 /// <summary>
 ///   <para>Make a field for selecting a Color.</para>
 /// </summary>
 /// <param name="position">Rectangle on the screen to use for the field.</param>
 /// <param name="label">Optional label to display in front of the field.</param>
 /// <param name="value">The color to edit.</param>
 /// <param name="showEyedropper">If true, the color picker should show the eyedropper control. If false, don't show it.</param>
 /// <param name="showAlpha">If true, allow the user to set an alpha value for the color. If false, hide the alpha component.</param>
 /// <param name="hdr">If true, treat the color as an HDR value. If false, treat it as a standard LDR value.</param>
 /// <param name="hdrConfig">An object that sets the presentation parameters for an HDR color. If not using an HDR color, set this to null.</param>
 /// <returns>
 ///   <para>The color selected by the user.</para>
 /// </returns>
 public static Color ColorField(Rect position, GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig)
 {
   int controlId = GUIUtility.GetControlID(EditorGUI.s_ColorHash, EditorGUIUtility.native, position);
   return EditorGUI.DoColorField(EditorGUI.PrefixLabel(position, controlId, label), controlId, value, showEyedropper, showAlpha, hdr, hdrConfig);
 }
 public Rect TexturePropertyWithHDRColor(
     GUIContent label, MaterialProperty textureProp, MaterialProperty colorProperty, ColorPickerHDRConfig hdrConfig, bool showAlpha
     )
 {
     return(TexturePropertyWithHDRColor(label, textureProp, colorProperty, showAlpha));
 }
 /// <summary>
 ///   <para>Make a field for selecting a Color.</para>
 /// </summary>
 /// <param name="label">Optional label to display in front of the field.</param>
 /// <param name="value">The color to edit.</param>
 /// <param name="showEyedropper">If true, the color picker should show the eyedropper control. If false, don't show it.</param>
 /// <param name="showAlpha">If true, allow the user to set an alpha value for the color. If false, hide the alpha component.</param>
 /// <param name="hdr">If true, treat the color as an HDR value. If false, treat it as a standard LDR value.</param>
 /// <param name="hdrConfig">An object that sets the presentation parameters for an HDR color. If not using an HDR color, set this to null.</param>
 /// <param name="options">An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.&lt;br&gt;
 /// See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight,
 /// GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.</param>
 /// <returns>
 ///   <para>The color selected by the user.</para>
 /// </returns>
 public static Color ColorField(GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig, params GUILayoutOption[] options)
 {
   return EditorGUI.ColorField(EditorGUILayout.s_LastRect = EditorGUILayout.GetControlRect(true, 16f, EditorStyles.colorField, options), label, value, showEyedropper, showAlpha, hdr, hdrConfig);
 }
Esempio n. 8
0
 public Rect TexturePropertyWithHDRColor(GUIContent label, MaterialProperty textureProp, MaterialProperty colorProperty, ColorPickerHDRConfig hdrConfig, bool showAlpha)
 {
     ColorPickerHDRConfig defaultHDRConfig;
     Rect controlRectForSingleLine = this.GetControlRectForSingleLine();
     this.TexturePropertyMiniThumbnail(controlRectForSingleLine, textureProp, label.text, label.tooltip);
     if (colorProperty.type != MaterialProperty.PropType.Color)
     {
         Debug.LogError("Assuming MaterialProperty.PropType.Color (was " + colorProperty.type + ")");
         return controlRectForSingleLine;
     }
     this.BeginAnimatedCheck(colorProperty);
     if (hdrConfig != null)
     {
         defaultHDRConfig = hdrConfig;
     }
     else
     {
         defaultHDRConfig = ColorPicker.defaultHDRConfig;
     }
     Rect leftAlignedFieldRect = GetLeftAlignedFieldRect(controlRectForSingleLine);
     EditorGUI.BeginChangeCheck();
     EditorGUI.showMixedValue = colorProperty.hasMixedValue;
     Color color = EditorGUI.ColorField(leftAlignedFieldRect, GUIContent.none, colorProperty.colorValue, true, showAlpha, true, defaultHDRConfig);
     EditorGUI.showMixedValue = false;
     if (EditorGUI.EndChangeCheck())
     {
         colorProperty.colorValue = color;
     }
     Rect flexibleRectBetweenFieldAndRightEdge = GetFlexibleRectBetweenFieldAndRightEdge(controlRectForSingleLine);
     float labelWidth = EditorGUIUtility.labelWidth;
     EditorGUIUtility.labelWidth = flexibleRectBetweenFieldAndRightEdge.width - EditorGUIUtility.fieldWidth;
     EditorGUI.BeginChangeCheck();
     color = EditorGUI.ColorBrightnessField(flexibleRectBetweenFieldAndRightEdge, GUIContent.Temp(" "), colorProperty.colorValue, defaultHDRConfig.minBrightness, defaultHDRConfig.maxBrightness);
     if (EditorGUI.EndChangeCheck())
     {
         colorProperty.colorValue = color;
     }
     EditorGUIUtility.labelWidth = labelWidth;
     this.EndAnimatedCheck();
     return controlRectForSingleLine;
 }