コード例 #1
0
        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);
            }
        }
コード例 #2
0
 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);
         }
     }
 }
コード例 #3
0
        internal static void DrawColorSwatch(Rect position, Color color, bool showAlpha, bool hdr)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            Color color2 = GUI.color;
            float a      = (float)((!GUI.enabled) ? 2 : 1);

            GUI.color = ((!EditorGUI.showMixedValue) ? new Color(color.r, color.g, color.b, a) : (new Color(0.82f, 0.82f, 0.82f, a) * color2));
            GUIStyle whiteTextureStyle = EditorGUIUtility.whiteTextureStyle;

            whiteTextureStyle.Draw(position, false, false, false, false);
            float maxColorComponent = GUI.color.maxColorComponent;

            if (hdr && maxColorComponent > 1f)
            {
                float num       = position.width / 3f;
                Rect  position2 = new Rect(position.x, position.y, num, position.height);
                Rect  position3 = new Rect(position.xMax - num, position.y, num, position.height);
                Color color3    = GUI.color.RGBMultiplied(1f / maxColorComponent);
                Color color4    = GUI.color;
                GUI.color = color3;
                GUIStyle basicTextureStyle = EditorGUIUtility.GetBasicTextureStyle(EditorGUIUtility.whiteTexture);
                basicTextureStyle.Draw(position2, false, false, false, false);
                basicTextureStyle.Draw(position3, false, false, false, false);
                GUI.color         = color4;
                basicTextureStyle = EditorGUIUtility.GetBasicTextureStyle(ColorPicker.GetGradientTextureWithAlpha0To1());
                basicTextureStyle.Draw(position2, false, false, false, false);
                basicTextureStyle = EditorGUIUtility.GetBasicTextureStyle(ColorPicker.GetGradientTextureWithAlpha1To0());
                basicTextureStyle.Draw(position3, false, false, false, false);
            }
            if (!EditorGUI.showMixedValue)
            {
                if (showAlpha)
                {
                    GUI.color = new Color(0f, 0f, 0f, a);
                    float num2      = Mathf.Clamp(position.height * 0.2f, 2f, 20f);
                    Rect  position4 = new Rect(position.x, position.yMax - num2, position.width, num2);
                    whiteTextureStyle.Draw(position4, false, false, false, false);
                    GUI.color        = new Color(1f, 1f, 1f, a);
                    position4.width *= Mathf.Clamp01(color.a);
                    whiteTextureStyle.Draw(position4, false, false, false, false);
                }
            }
            else
            {
                EditorGUI.BeginHandleMixedValueContentColor();
                whiteTextureStyle.Draw(position, EditorGUI.mixedValueContent, false, false, false, false);
                EditorGUI.EndHandleMixedValueContentColor();
            }
            GUI.color = color2;
            if (hdr && maxColorComponent > 1f)
            {
                GUI.Label(new Rect(position.x, position.y, position.width - 3f, position.height), "HDR", EditorStyles.centeredGreyMiniLabel);
            }
        }
コード例 #4
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);
                 }
             }
         }
     }
 }
コード例 #5
0
        private static void DrawCurveSwatchInternal(Rect position, AnimationCurve curve, AnimationCurve curve2, SerializedProperty property, SerializedProperty property2, Color color, Color bgColor, bool useCurveRanges, Rect curveRanges)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            int   previewWidth  = (int)position.width;
            int   previewHeight = (int)position.height;
            Color color2        = GUI.color;

            GUI.color = bgColor;
            GUIStyle gUIStyle = EditorGUIUtility.whiteTextureStyle;

            gUIStyle.Draw(position, false, false, false, false);
            GUI.color = color2;
            if (property != null && property.hasMultipleDifferentValues)
            {
                EditorGUI.BeginHandleMixedValueContentColor();
                GUI.Label(position, EditorGUI.mixedValueContent, "PreOverlayLabel");
                EditorGUI.EndHandleMixedValueContentColor();
            }
            else
            {
                Texture2D texture2D = null;
                if (property != null)
                {
                    if (property2 == null)
                    {
                        texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, property, color) : AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, property, color, curveRanges));
                    }
                    else
                    {
                        texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, property, property2, color) : AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, property, property2, color, curveRanges));
                    }
                }
                else
                {
                    if (curve != null)
                    {
                        if (curve2 == null)
                        {
                            texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, curve, color) : AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, curve, color, curveRanges));
                        }
                        else
                        {
                            texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, curve, curve2, color) : AnimationCurvePreviewCache.GetPreview(previewWidth, previewHeight, curve, curve2, color, curveRanges));
                        }
                    }
                }
                gUIStyle        = EditorGUIUtility.GetBasicTextureStyle(texture2D);
                position.width  = (float)texture2D.width;
                position.height = (float)texture2D.height;
                gUIStyle.Draw(position, false, false, false, false);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
        private static void DrawCurveSwatchInternal(Rect position, AnimationCurve curve, AnimationCurve curve2, SerializedProperty property, SerializedProperty property2, Color color, Color bgColor, bool useCurveRanges, Rect curveRanges, Color topFillColor, Color bottomFillColor)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            int  num            = (int)position.width;
            int  num2           = (int)position.height;
            int  maxTextureSize = SystemInfo.maxTextureSize;
            bool flag           = num > maxTextureSize;
            bool flag2          = num2 > maxTextureSize;

            if (flag)
            {
                num = Mathf.Min(num, maxTextureSize);
            }
            if (flag2)
            {
                num2 = Mathf.Min(num2, maxTextureSize);
            }
            Color color2 = GUI.color;

            GUI.color = bgColor;
            GUIStyle gUIStyle = EditorGUIUtility.whiteTextureStyle;

            gUIStyle.Draw(position, false, false, false, false);
            GUI.color = color2;
            if (property != null && property.hasMultipleDifferentValues)
            {
                EditorGUI.BeginHandleMixedValueContentColor();
                GUI.Label(position, EditorGUI.mixedValueContent, "PreOverlayLabel");
                EditorGUI.EndHandleMixedValueContentColor();
            }
            else
            {
                Texture2D texture2D = null;
                if (property != null)
                {
                    if (property2 == null)
                    {
                        texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(num, num2, property, color, topFillColor, bottomFillColor) : AnimationCurvePreviewCache.GetPreview(num, num2, property, color, topFillColor, bottomFillColor, curveRanges));
                    }
                    else
                    {
                        texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(num, num2, property, property2, color, topFillColor, bottomFillColor) : AnimationCurvePreviewCache.GetPreview(num, num2, property, property2, color, topFillColor, bottomFillColor, curveRanges));
                    }
                }
                else if (curve != null)
                {
                    if (curve2 == null)
                    {
                        texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(num, num2, curve, color, topFillColor, bottomFillColor) : AnimationCurvePreviewCache.GetPreview(num, num2, curve, color, topFillColor, bottomFillColor, curveRanges));
                    }
                    else
                    {
                        texture2D = ((!useCurveRanges) ? AnimationCurvePreviewCache.GetPreview(num, num2, curve, curve2, color, topFillColor, bottomFillColor) : AnimationCurvePreviewCache.GetPreview(num, num2, curve, curve2, color, topFillColor, bottomFillColor, curveRanges));
                    }
                }
                gUIStyle = EditorGUIUtility.GetBasicTextureStyle(texture2D);
                if (!flag)
                {
                    position.width = (float)texture2D.width;
                }
                if (!flag2)
                {
                    position.height = (float)texture2D.height;
                }
                gUIStyle.Draw(position, false, false, false, false);
            }
        }
コード例 #8
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);
            }
        }