private static void DrawGradientSwatchInternal(Rect position, Gradient gradient, SerializedProperty property, Color bgColor)
 {
     if (Event.current.type == EventType.Repaint)
     {
         Texture2D backgroundTexture = GetBackgroundTexture();
         if (backgroundTexture != null)
         {
             Color color = GUI.color;
             GUI.color = bgColor;
             EditorGUIUtility.GetBasicTextureStyle(backgroundTexture).Draw(position, false, false, false, false);
             GUI.color = color;
         }
         Texture2D tex = null;
         if (property != null)
         {
             tex = GradientPreviewCache.GetPropertyPreview(property);
         }
         else
         {
             tex = GradientPreviewCache.GetGradientPreview(gradient);
         }
         if (tex == null)
         {
             Debug.Log("Warning: Could not create preview for gradient");
         }
         else
         {
             EditorGUIUtility.GetBasicTextureStyle(tex).Draw(position, false, false, false, false);
         }
     }
 }
Exemple #2
0
 private static void DrawGradientSwatchInternal(Rect position, Gradient gradient, SerializedProperty property, Color bgColor)
 {
     if (Event.current.type == EventType.Repaint)
     {
         if (EditorGUI.showMixedValue)
         {
             Color color = GUI.color;
             float a     = (float)((!GUI.enabled) ? 2 : 1);
             GUI.color = new Color(0.82f, 0.82f, 0.82f, a) * bgColor;
             GUIStyle whiteTextureStyle = EditorGUIUtility.whiteTextureStyle;
             whiteTextureStyle.Draw(position, false, false, false, false);
             EditorGUI.BeginHandleMixedValueContentColor();
             whiteTextureStyle.Draw(position, EditorGUI.mixedValueContent, false, false, false, false);
             EditorGUI.EndHandleMixedValueContentColor();
             GUI.color = color;
         }
         else
         {
             Texture2D backgroundTexture = GradientEditor.GetBackgroundTexture();
             if (backgroundTexture != null)
             {
                 Color color2 = GUI.color;
                 GUI.color = bgColor;
                 GUIStyle basicTextureStyle = EditorGUIUtility.GetBasicTextureStyle(backgroundTexture);
                 basicTextureStyle.Draw(position, false, false, false, false);
                 GUI.color = color2;
             }
             Texture2D texture2D;
             float     maxColorComponent;
             if (property != null)
             {
                 texture2D         = GradientPreviewCache.GetPropertyPreview(property);
                 maxColorComponent = GradientEditor.GetMaxColorComponent(property.gradientValue);
             }
             else
             {
                 texture2D         = GradientPreviewCache.GetGradientPreview(gradient);
                 maxColorComponent = GradientEditor.GetMaxColorComponent(gradient);
             }
             if (texture2D == null)
             {
                 Debug.Log("Warning: Could not create preview for gradient");
             }
             else
             {
                 GUIStyle basicTextureStyle2 = EditorGUIUtility.GetBasicTextureStyle(texture2D);
                 basicTextureStyle2.Draw(position, false, false, false, false);
                 if (maxColorComponent > 1f)
                 {
                     GUI.Label(new Rect(position.x, position.y - 1f, position.width - 3f, position.height + 2f), "HDR", EditorStyles.centeredGreyMiniLabel);
                 }
             }
         }
     }
 }
Exemple #3
0
        private static void DrawGradientSwatchInternal(Rect position, Gradient gradient, SerializedProperty property, Color bgColor, ColorSpace colorSpace)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (EditorGUI.showMixedValue)
            {
                Color oldColor = GUI.color;
                float a        = GUI.enabled ? 1 : 2;

                GUI.color = new Color(0.82f, 0.82f, 0.82f, a) * bgColor;
                GUIStyle mgs = EditorGUIUtility.whiteTextureStyle;
                mgs.Draw(position, false, false, false, false);

                EditorGUI.BeginHandleMixedValueContentColor();
                mgs.Draw(position, EditorGUI.mixedValueContent, false, false, false, false);
                EditorGUI.EndHandleMixedValueContentColor();

                GUI.color = oldColor;
                return;
            }

            // Draw Background
            Texture2D backgroundTexture = GradientEditor.GetBackgroundTexture();

            if (backgroundTexture != null)
            {
                Color oldColor = GUI.color;
                GUI.color = bgColor;

                GUIStyle backgroundStyle = EditorGUIUtility.GetBasicTextureStyle(backgroundTexture);
                backgroundStyle.Draw(position, false, false, false, false);

                GUI.color = oldColor;
            }

            // DrawTexture
            Texture2D preview = null;
            float     maxColorComponent;

            bool linearGradientKeys = colorSpace == ColorSpace.Linear;

            if (colorSpace == ColorSpace.Uninitialized)
            {
                Debug.LogError("GradientEditor color space is not initialized, assuming linear gradient keys to build the gradient preview.");
                linearGradientKeys = true;
            }
            if (property != null)
            {
                preview           = GradientPreviewCache.GetPropertyPreview(property, linearGradientKeys);
                maxColorComponent = GetMaxColorComponent(property.gradientValue);
            }
            else
            {
                preview           = GradientPreviewCache.GetGradientPreview(gradient, linearGradientKeys);
                maxColorComponent = GetMaxColorComponent(gradient);
            }

            if (preview == null)
            {
                Debug.Log("Warning: Could not create preview for gradient");
                return;
            }

            Color color = GUI.color;

            GUI.color = Color.white;            //Dont want the Playmode tint to be applied to gradient textures.
            GUIStyle gs = EditorGUIUtility.GetBasicTextureStyle(preview);

            gs.Draw(position, false, false, false, false);
            GUI.color = color;

            // HDR label
            if (maxColorComponent > 1.0f)
            {
                GUI.Label(new Rect(position.x, position.y - 1, position.width - 3, position.height + 2), "HDR", EditorStyles.centeredGreyMiniLabel);
            }
        }
Exemple #4
0
        private static void DrawGradientSwatchInternal(Rect position, Gradient gradient, SerializedProperty property, Color bgColor)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (EditorGUI.showMixedValue)
            {
                Color oldColor = GUI.color;
                float a        = GUI.enabled ? 1 : 2;

                GUI.color = new Color(0.82f, 0.82f, 0.82f, a) * bgColor;
                GUIStyle mgs = EditorGUIUtility.whiteTextureStyle;
                mgs.Draw(position, false, false, false, false);

                EditorGUI.BeginHandleMixedValueContentColor();
                mgs.Draw(position, EditorGUI.mixedValueContent, false, false, false, false);
                EditorGUI.EndHandleMixedValueContentColor();

                GUI.color = oldColor;
                return;
            }

            // Draw Background
            Texture2D backgroundTexture = GradientEditor.GetBackgroundTexture();

            if (backgroundTexture != null)
            {
                Color oldColor = GUI.color;
                GUI.color = bgColor;

                GUIStyle backgroundStyle = EditorGUIUtility.GetBasicTextureStyle(backgroundTexture);
                backgroundStyle.Draw(position, false, false, false, false);

                GUI.color = oldColor;
            }

            // DrawTexture
            Texture2D preview = null;
            float     maxColorComponent;

            if (property != null)
            {
                preview           = GradientPreviewCache.GetPropertyPreview(property);
                maxColorComponent = GetMaxColorComponent(property.gradientValue);
            }
            else
            {
                preview           = GradientPreviewCache.GetGradientPreview(gradient);
                maxColorComponent = GetMaxColorComponent(gradient);
            }

            if (preview == null)
            {
                Debug.Log("Warning: Could not create preview for gradient");
                return;
            }

            GUIStyle gs = EditorGUIUtility.GetBasicTextureStyle(preview);

            gs.Draw(position, false, false, false, false);

            // HDR label
            if (maxColorComponent > 1.0f)
            {
                GUI.Label(new Rect(position.x, position.y - 1, position.width - 3, position.height + 2), "HDR", EditorStyles.centeredGreyMiniLabel);
            }
        }
        private static void DrawGradientSwatchInternal(Rect position, Gradient gradient, SerializedProperty property, Color bgColor)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            Texture2D backgroundTexture = GradientEditor.GetBackgroundTexture();

            if ((UnityEngine.Object)backgroundTexture != (UnityEngine.Object)null)
            {
                Color color = GUI.color;
                GUI.color = bgColor;
                EditorGUIUtility.GetBasicTextureStyle(backgroundTexture).Draw(position, false, false, false, false);
                GUI.color = color;
            }
            Texture2D tex = property == null?GradientPreviewCache.GetGradientPreview(gradient) : GradientPreviewCache.GetPropertyPreview(property);

            if ((UnityEngine.Object)tex == (UnityEngine.Object)null)
            {
                Debug.Log((object)"Warning: Could not create preview for gradient");
            }
            else
            {
                EditorGUIUtility.GetBasicTextureStyle(tex).Draw(position, false, false, false, false);
            }
        }