예제 #1
0
 private void DrawInternal(Rect rect, Gradient gradient)
 {
     if (gradient != null)
     {
         GradientEditor.DrawGradientWithBackground(rect, GradientPreviewCache.GetGradientPreview(gradient));
     }
 }
예제 #2
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);
            }
        }
예제 #3
0
        void OnGradientChanged(Gradient newValue)
        {
            value = newValue;

            GradientPreviewCache.ClearCache(); // needed because GradientEditor itself uses the cache and will no invalidate it on changes.
            IncrementVersion(VersionChangeType.Repaint);
        }
예제 #4
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);
         }
     }
 }
        void OnGradientChanged(Gradient newValue)
        {
            SetValueAndNotify(newValue);

            GradientPreviewCache.ClearCache(); // needed because GradientEditor itself uses the cache and will no invalidate it on changes.
            Dirty(ChangeType.Repaint);
        }
        public static void SetGradientAsColor(SerializedProperty gradientProp, Color color)
        {
            Gradient gradientValue = gradientProp.gradientValue;

            gradientValue.constantColor = color;
            GradientPreviewCache.ClearCache();
        }
예제 #7
0
 public static void Show(Gradient newGradient, bool hdr, Action <Gradient> onGradientChanged)
 {
     GradientPicker.PrepareShow(hdr);
     GradientPicker.s_GradientPicker.m_DelegateView = null;
     GradientPicker.s_GradientPicker.m_Delegate     = onGradientChanged;
     GradientPicker.s_GradientPicker.Init(newGradient, hdr);
     GradientPreviewCache.ClearCache();
 }
예제 #8
0
 private void Paste()
 {
     ParticleSystemClipboard.PasteGradient(this.m_Prop1, null);
     if (this.m_Prop1 != null)
     {
         this.m_Prop1.serializedObject.ApplyModifiedProperties();
     }
     GradientPreviewCache.ClearCache();
 }
예제 #9
0
        private static void Show(Gradient newGradient, bool hdr, ColorSpace colorSpace, System.Action <Gradient> onGradientChanged, GUIView currentView)
        {
            PrepareShow(hdr, colorSpace);
            s_GradientPicker.m_DelegateView = currentView;
            s_GradientPicker.m_Delegate     = onGradientChanged;
            s_GradientPicker.Init(newGradient, hdr, colorSpace);

            GradientPreviewCache.ClearCache();
        }
예제 #10
0
        public static void Show(Gradient newGradient, bool hdr)
        {
            GUIView current = GUIView.current;

            GradientPicker.PrepareShow(hdr);
            GradientPicker.s_GradientPicker.m_DelegateView = current;
            GradientPicker.s_GradientPicker.m_Delegate     = null;
            GradientPicker.s_GradientPicker.Init(newGradient, hdr);
            GradientPreviewCache.ClearCache();
        }
예제 #11
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);
                 }
             }
         }
     }
 }
예제 #12
0
 private void UpdateGradientTexture()
 {
     if (this.m_ValueNull)
     {
         base.style.backgroundImage = null;
     }
     else
     {
         Texture2D value = GradientPreviewCache.GenerateGradientPreview(this.value, base.style.backgroundImage.value);
         base.style.backgroundImage = value;
     }
 }
예제 #13
0
        private void PresetClickedCallback(int clickCount, object presetObject)
        {
            Gradient gradient = presetObject as Gradient;

            if (gradient == null)
            {
                Debug.LogError("Incorrect object passed " + presetObject);
            }
            GradientPicker.SetCurrentGradient(gradient);
            GradientPreviewCache.ClearCache();
            this.gradientChanged = true;
        }
예제 #14
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);
            }
        }
예제 #15
0
        public static void Show(Gradient newGradient)
        {
            GUIView current = GUIView.current;

            if (GradientPicker.s_GradientPicker == null)
            {
                GradientPicker.s_GradientPicker = (GradientPicker)EditorWindow.GetWindow(typeof(GradientPicker), true, "Gradient Editor", false);
                Vector2 minSize = new Vector2(360f, 224f);
                Vector2 maxSize = new Vector2(1900f, 3000f);
                GradientPicker.s_GradientPicker.minSize        = minSize;
                GradientPicker.s_GradientPicker.maxSize        = maxSize;
                GradientPicker.s_GradientPicker.wantsMouseMove = true;
                GradientPicker.s_GradientPicker.ShowAuxWindow();
            }
            else
            {
                GradientPicker.s_GradientPicker.Repaint();
            }
            GradientPicker.s_GradientPicker.m_DelegateView = current;
            GradientPicker.s_GradientPicker.Init(newGradient);
            GradientPreviewCache.ClearCache();
        }
예제 #16
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);
        }
예제 #17
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);
            }
        }
        internal static Gradient DoGradientField(Rect position, int id, Gradient value, SerializedProperty property, bool hdr)
        {
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (position.Contains(evt.mousePosition))
                {
                    if (evt.button == 0)
                    {
                        s_GradientID = id;
                        GUIUtility.keyboardControl = id;
                        Gradient gradient = property != null ? property.gradientValue : value;
                        GradientPicker.Show(gradient, hdr);
                        GUIUtility.ExitGUI();
                    }
                    else if (evt.button == 1)
                    {
                        if (property != null)
                        {
                            GradientContextMenu.Show(property.Copy());
                        }
                        // TODO: make work for Gradient value
                    }
                }
                break;

            case EventType.Repaint:
            {
                Rect r2 = new Rect(position.x + 1, position.y + 1, position.width - 2, position.height - 2);        // Adjust for box drawn on top
                if (property != null)
                {
                    GradientEditor.DrawGradientSwatch(r2, property, Color.white);
                }
                else
                {
                    GradientEditor.DrawGradientSwatch(r2, value, Color.white);
                }
                EditorStyles.colorPickerBox.Draw(position, GUIContent.none, id);
                break;
            }

            case EventType.ExecuteCommand:
                if (s_GradientID == id && evt.commandName == GradientPicker.GradientPickerChangedCommand)
                {
                    GUI.changed = true;
                    GradientPreviewCache.ClearCache();
                    HandleUtility.Repaint();
                    if (property != null)
                    {
                        property.gradientValue = GradientPicker.gradient;
                    }

                    return(GradientPicker.gradient);
                }
                break;

            case EventType.ValidateCommand:
                if (s_GradientID == id && evt.commandName == EventCommandNames.UndoRedoPerformed)
                {
                    if (property != null)
                    {
                        GradientPicker.SetCurrentGradient(property.gradientValue);
                    }
                    GradientPreviewCache.ClearCache();
                    return(value);
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.keyboardControl == id && (evt.keyCode == KeyCode.Space || evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter))
                {
                    Event.current.Use();
                    Gradient gradient = property != null ? property.gradientValue : value;
                    GradientPicker.Show(gradient, hdr);
                    GUIUtility.ExitGUI();
                }
                break;
            }
            return(value);
        }
예제 #19
0
        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);
            }
        }
예제 #20
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);
            }
        }
예제 #21
0
 private void OnGradientChanged(Gradient newValue)
 {
     this.SetValueAndNotify(newValue);
     GradientPreviewCache.ClearCache();
     base.Dirty(ChangeType.Repaint);
 }
예제 #22
0
        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);
            }
        }
예제 #23
0
 private void Paste()
 {
     ParticleSystemClipboard.PasteGradient(this.m_Prop1, null);
     GradientPreviewCache.ClearCache();
 }