private void DrawInternal(Rect rect, Gradient gradient)
 {
     if (gradient != null)
     {
         GradientEditor.DrawGradientWithBackground(rect, GradientPreviewCache.GetGradientPreview(gradient));
     }
 }
Example #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);
         }
     }
 }
        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);
            }
        }
Example #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);
                 }
             }
         }
     }
 }
Example #5
0
        public static void DrawGradientWithBackground(Rect position, Gradient gradient)
        {
            Texture2D gradientPreview   = GradientPreviewCache.GetGradientPreview(gradient);
            Rect      position2         = new Rect(position.x + 1f, position.y + 1f, position.width - 2f, position.height - 2f);
            Texture2D backgroundTexture = GradientEditor.GetBackgroundTexture();
            Rect      texCoords         = new Rect(0f, 0f, position2.width / (float)backgroundTexture.width, position2.height / (float)backgroundTexture.height);

            GUI.DrawTextureWithTexCoords(position2, backgroundTexture, texCoords, false);
            if (gradientPreview != null)
            {
                GUI.DrawTexture(position2, gradientPreview, ScaleMode.StretchToFill, true);
            }
            GUI.Label(position, GUIContent.none, EditorStyles.colorPickerBox);
            float maxColorComponent = GradientEditor.GetMaxColorComponent(gradient);

            if (maxColorComponent > 1f)
            {
                GUI.Label(new Rect(position.x, position.y, position.width - 3f, position.height), "HDR", EditorStyles.centeredGreyMiniLabel);
            }
        }
Example #6
0
        static Vector3 PrepareGeneralPreview(Material material, Texture texture, out Vector3 inverseScale,
                                             out float inverseResolution, Gradient customColorRamp = null)
        {
            Vector3 voxelSize = VoxelSize(GetTextureResolution(texture), out inverseResolution);

            inverseScale = new Vector3(1.0f / voxelSize.x, 1.0f / voxelSize.y, 1.0f / voxelSize.z);

            material.mainTexture = texture;
            material.SetVector(MaterialProps.voxelSize, voxelSize);
            material.SetVector(MaterialProps.invScale, inverseScale);

            if (customColorRamp != null)
            {
                material.SetTexture(MaterialProps.colorRamp, GradientPreviewCache.GetGradientPreview(customColorRamp));
            }
            else
            {
                material.SetTexture(MaterialProps.colorRamp, TurboColorRamp);
            }

            return(voxelSize);
        }
Example #7
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);
            }
        }
        public void OnGUI(Rect position)
        {
            if (GradientEditor.s_Styles == null)
            {
                GradientEditor.s_Styles = new GradientEditor.Styles();
            }
            float num  = 16f;
            float num2 = 30f;
            float num3 = position.height - 2f * num - num2;

            position.height = num;
            this.ShowSwatchArray(position, this.m_AlphaSwatches, true);
            position.y += num;
            if (Event.current.type == EventType.Repaint)
            {
                position.height = num3;
                GradientEditor.DrawGradientWithBackground(position, GradientPreviewCache.GetGradientPreview(this.m_Gradient));
            }
            position.y     += num3;
            position.height = num;
            this.ShowSwatchArray(position, this.m_RGBSwatches, false);
            if (this.m_SelectedSwatch != null)
            {
                position.y     += num;
                position.height = num2;
                position.y     += 10f;
                float num4       = 45f;
                float num5       = 60f;
                float num6       = 20f;
                float labelWidth = 50f;
                float num7       = num5 + num6 + num5 + num4;
                Rect  position2  = position;
                position2.height            = 18f;
                position2.x                += 17f;
                position2.width            -= num7;
                EditorGUIUtility.labelWidth = labelWidth;
                if (this.m_SelectedSwatch.m_IsAlpha)
                {
                    EditorGUIUtility.fieldWidth = 30f;
                    EditorGUI.BeginChangeCheck();
                    float num8 = (float)EditorGUI.IntSlider(position2, GradientEditor.s_Styles.alphaText, (int)(this.m_SelectedSwatch.m_Value.r * 255f), 0, 255) / 255f;
                    if (EditorGUI.EndChangeCheck())
                    {
                        num8 = Mathf.Clamp01(num8);
                        this.m_SelectedSwatch.m_Value.r = (this.m_SelectedSwatch.m_Value.g = (this.m_SelectedSwatch.m_Value.b = num8));
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_SelectedSwatch.m_Value = EditorGUI.ColorField(position2, GradientEditor.s_Styles.colorText, this.m_SelectedSwatch.m_Value, true, false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                position2.x                += position2.width + num6;
                position2.width             = num4 + num5;
                EditorGUIUtility.labelWidth = num5;
                string kFloatFieldFormatString = EditorGUI.kFloatFieldFormatString;
                EditorGUI.kFloatFieldFormatString = "f1";
                EditorGUI.BeginChangeCheck();
                float value = EditorGUI.FloatField(position2, GradientEditor.s_Styles.locationText, this.m_SelectedSwatch.m_Time * 100f) / 100f;
                if (EditorGUI.EndChangeCheck())
                {
                    this.m_SelectedSwatch.m_Time = Mathf.Clamp(value, 0f, 1f);
                    this.AssignBack();
                }
                EditorGUI.kFloatFieldFormatString = kFloatFieldFormatString;
                position2.x    += position2.width;
                position2.width = 20f;
                GUI.Label(position2, GradientEditor.s_Styles.percentText);
            }
        }
Example #9
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);
            }
        }
        public void OnGUI(Rect position)
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }
            float num  = 24f;
            float num2 = 16f;
            float num3 = 26f;
            float num4 = ((position.height - (2f * num2)) - num3) - num;

            position.height     = num;
            this.m_GradientMode = (GradientMode)EditorGUI.EnumPopup(position, s_Styles.modeText, this.m_GradientMode);
            if (this.m_GradientMode != this.m_Gradient.mode)
            {
                this.AssignBack();
            }
            position.y     += num;
            position.height = num2;
            this.ShowSwatchArray(position, this.m_AlphaSwatches, true);
            position.y += num2;
            if (Event.current.type == EventType.Repaint)
            {
                position.height = num4;
                DrawGradientWithBackground(position, GradientPreviewCache.GetGradientPreview(this.m_Gradient));
            }
            position.y     += num4;
            position.height = num2;
            this.ShowSwatchArray(position, this.m_RGBSwatches, false);
            if (this.m_SelectedSwatch != null)
            {
                position.y     += num2;
                position.height = num3;
                position.y     += 10f;
                float num5 = 45f;
                float num6 = 60f;
                float num7 = 20f;
                float num8 = 50f;
                float num9 = ((num6 + num7) + num6) + num5;
                Rect  rect = position;
                rect.height = 18f;
                rect.x     += 17f;
                rect.width -= num9;
                EditorGUIUtility.labelWidth = num8;
                if (this.m_SelectedSwatch.m_IsAlpha)
                {
                    EditorGUIUtility.fieldWidth = 30f;
                    EditorGUI.BeginChangeCheck();
                    float num10 = ((float)EditorGUI.IntSlider(rect, s_Styles.alphaText, (int)(this.m_SelectedSwatch.m_Value.r * 255f), 0, 0xff)) / 255f;
                    if (EditorGUI.EndChangeCheck())
                    {
                        num10 = Mathf.Clamp01(num10);
                        this.m_SelectedSwatch.m_Value.r = this.m_SelectedSwatch.m_Value.g = this.m_SelectedSwatch.m_Value.b = num10;
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_SelectedSwatch.m_Value = EditorGUI.ColorField(rect, s_Styles.colorText, this.m_SelectedSwatch.m_Value, true, false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                rect.x    += rect.width + num7;
                rect.width = num5 + num6;
                EditorGUIUtility.labelWidth = num6;
                string kFloatFieldFormatString = EditorGUI.kFloatFieldFormatString;
                EditorGUI.kFloatFieldFormatString = "f1";
                EditorGUI.BeginChangeCheck();
                float num12 = EditorGUI.FloatField(rect, s_Styles.locationText, this.m_SelectedSwatch.m_Time * 100f) / 100f;
                if (EditorGUI.EndChangeCheck())
                {
                    this.m_SelectedSwatch.m_Time = Mathf.Clamp(num12, 0f, 1f);
                    this.AssignBack();
                }
                EditorGUI.kFloatFieldFormatString = kFloatFieldFormatString;
                rect.x    += rect.width;
                rect.width = 20f;
                GUI.Label(rect, s_Styles.percentText);
            }
        }