Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using non-HDR color pickers on gradient options #290

Merged
merged 8 commits into from
Jan 7, 2025
24 changes: 12 additions & 12 deletions Assets/Demos/GradationTest/GradationTest.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481676, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -213,7 +213,6 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1299999091}
- {fileID: 591404685}
Expand Down Expand Up @@ -253,7 +252,6 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 320007022}
m_RootOrder: 1
Expand Down Expand Up @@ -380,7 +378,6 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
Expand Down Expand Up @@ -415,7 +412,6 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 320007022}
m_RootOrder: 0
Expand Down Expand Up @@ -507,6 +503,9 @@ MonoBehaviour:
m_PlayOnEnable: 1
m_WrapMode: 1
m_UpdateMode: 0
m_OnComplete:
m_PersistentCalls:
m_Calls: []
--- !u!114 &1299999096
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -525,6 +524,7 @@ MonoBehaviour:
m_ColorFilter: 0
m_ColorIntensity: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_ColorGlow: 0
m_SamplingFilter: 0
m_SamplingIntensity: 0.5
m_SamplingScale: 1
Expand All @@ -540,6 +540,7 @@ MonoBehaviour:
m_TransitionSoftness: 0.2
m_TransitionColorFilter: 6
m_TransitionColor: {r: 0, g: 0.5, b: 1, a: 1}
m_TransitionColorGlow: 0
m_TargetMode: 0
m_TargetColor: {r: 1, g: 1, b: 1, a: 1}
m_TargetRange: 0.1
Expand All @@ -553,10 +554,11 @@ MonoBehaviour:
m_ShadowFade: 0.9
m_ShadowMirrorScale: 0.5
m_ShadowBlurIntensity: 1
m_ShadowColorFilter: 4
m_ShadowColor: {r: 1, g: 1, b: 1, a: 1}
m_ShadowGlow: 0
m_ShadowColorGlow: 0
m_GradationMode: 2
m_GradationColor1: {r: 1, g: 1, b: 1, a: 1}
m_GradationColor1: {r: 0.04517317, g: 0, b: 1, a: 1}
m_GradationColor2: {r: 1, g: 1, b: 1, a: 1}
m_GradationGradient:
serializedVersion: 2
Expand Down Expand Up @@ -587,9 +589,10 @@ MonoBehaviour:
m_Mode: 0
m_NumColorKeys: 8
m_NumAlphaKeys: 2
m_GradationOffset: 1
m_GradationOffset: 0
m_GradationScale: 2
m_AllowExtendVertex: 1
m_GradationRotation: 0
m_AllowToModifyMeshShape: 1
--- !u!1 &1303535690
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -620,7 +623,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SendPointerHoverToParent: 1
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
Expand Down Expand Up @@ -653,7 +655,6 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
Expand Down Expand Up @@ -747,7 +748,6 @@ Transform:
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
Expand Down
80 changes: 40 additions & 40 deletions Assets/ProjectSettings/UIEffectProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,45 @@ ShaderVariantCollection:
variants:
- keywords:
passType: 0
- keywords: COLOR_ADDITIVE
passType: 0
- keywords: COLOR_ADDITIVE SAMPLING_BLUR_FAST
passType: 0
- keywords: COLOR_ADDITIVE SAMPLING_BLUR_FAST UNITY_UI_CLIP_RECT
- keywords: TONE_GRAYSCALE
passType: 0
- keywords: COLOR_CONTRAST
- keywords: TONE_SEPIA
passType: 0
- keywords: COLOR_HSV_MODIFIER
- keywords: TONE_NEGATIVE
passType: 0
- keywords: COLOR_HSV_MODIFIER TARGET_HUE
- keywords: TONE_RETRO
passType: 0
- keywords: COLOR_HSV_MODIFIER TARGET_LUMINANCE
- keywords: TONE_POSTERIZE
passType: 0
- keywords: COLOR_MULTIPLY
passType: 0
- keywords: COLOR_MULTIPLY SAMPLING_BLUR_FAST SHADOW_COLOR_REPLACE TARGET_HUE
TONE_GRAYSCALE TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_DISSOLVE
passType: 0
- keywords: COLOR_MULTIPLY_ADDITIVE
- keywords: COLOR_ADDITIVE
passType: 0
- keywords: COLOR_MULTIPLY_ADDITIVE SAMPLING_BLUR_FAST TONE_GRAYSCALE TRANSITION_COLOR_MULTIPLY_ADDITIVE
TRANSITION_DISSOLVE
- keywords: COLOR_SUBTRACTIVE
passType: 0
- keywords: COLOR_MULTIPLY_ADDITIVE SAMPLING_RGB_SHIFT TONE_GRAYSCALE TRANSITION_COLOR_MULTIPLY_ADDITIVE
TRANSITION_DISSOLVE
- keywords: COLOR_REPLACE
passType: 0
- keywords: COLOR_MULTIPLY_LUMINANCE
passType: 0
- keywords: COLOR_REPLACE
passType: 0
- keywords: COLOR_REPLACE SAMPLING_BLUR_FAST
- keywords: COLOR_MULTIPLY_ADDITIVE
passType: 0
- keywords: COLOR_SUBTRACTIVE
- keywords: COLOR_HSV_MODIFIER
passType: 0
- keywords: SAMPLING_BLUR_DETAIL
- keywords: COLOR_CONTRAST
passType: 0
- keywords: SAMPLING_BLUR_FAST
passType: 0
- keywords: SAMPLING_BLUR_FAST TONE_GRAYSCALE
passType: 0
- keywords: SAMPLING_BLUR_MEDIUM
- keywords: COLOR_ADDITIVE SAMPLING_BLUR_FAST
passType: 0
- keywords: SAMPLING_EDGE_ALPHA
- keywords: COLOR_ADDITIVE SAMPLING_BLUR_FAST UNITY_UI_CLIP_RECT
passType: 0
- keywords: SAMPLING_EDGE_LUMINANCE
- keywords: COLOR_REPLACE SAMPLING_BLUR_FAST
passType: 0
- keywords: SAMPLING_EDGE_LUMINANCE TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_MASK
- keywords: SAMPLING_BLUR_MEDIUM
passType: 0
- keywords: SAMPLING_BLUR_DETAIL
passType: 0
- keywords: SAMPLING_PIXELATION
passType: 0
Expand All @@ -70,39 +61,48 @@ ShaderVariantCollection:
passType: 0
- keywords: SAMPLING_RGB_SHIFT
passType: 0
- keywords: TONE_GRAYSCALE
passType: 0
- keywords: TONE_NEGATIVE
passType: 0
- keywords: TONE_POSTERIZE
- keywords: SAMPLING_EDGE_LUMINANCE
passType: 0
- keywords: TONE_RETRO
- keywords: SAMPLING_EDGE_ALPHA
passType: 0
- keywords: TONE_SEPIA
- keywords: TRANSITION_FADE
passType: 0
- keywords: TRANSITION_BURN TRANSITION_COLOR_MULTIPLY_ADDITIVE
- keywords: TRANSITION_CUTOFF
passType: 0
- keywords: TRANSITION_BURN TRANSITION_COLOR_MULTIPLY_ADDITIVE UNITY_UI_CLIP_RECT
- keywords: TRANSITION_COLOR_REPLACE TRANSITION_MELT
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_DISSOLVE
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_DISSOLVE UNITY_UI_CLIP_RECT
passType: 0
- keywords: COLOR_MULTIPLY_ADDITIVE SAMPLING_BLUR_FAST TONE_GRAYSCALE TRANSITION_COLOR_MULTIPLY_ADDITIVE
TRANSITION_DISSOLVE
passType: 0
- keywords: COLOR_MULTIPLY_ADDITIVE SAMPLING_RGB_SHIFT TONE_GRAYSCALE TRANSITION_COLOR_MULTIPLY_ADDITIVE
TRANSITION_DISSOLVE
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_SHINY
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_SHINY UNITY_UI_CLIP_RECT
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_MASK
passType: 0
- keywords: SAMPLING_EDGE_LUMINANCE TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_MASK
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_MELT
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_MELT UNITY_UI_CLIP_RECT
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_SHINY
- keywords: TRANSITION_BURN TRANSITION_COLOR_MULTIPLY_ADDITIVE
passType: 0
- keywords: TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_SHINY UNITY_UI_CLIP_RECT
- keywords: TRANSITION_BURN TRANSITION_COLOR_MULTIPLY_ADDITIVE UNITY_UI_CLIP_RECT
passType: 0
- keywords: TRANSITION_COLOR_REPLACE TRANSITION_MELT
- keywords: COLOR_HSV_MODIFIER TARGET_HUE
passType: 0
- keywords: TRANSITION_CUTOFF
- keywords: COLOR_MULTIPLY SAMPLING_BLUR_FAST SHADOW_COLOR_REPLACE TARGET_HUE
TONE_GRAYSCALE TRANSITION_COLOR_MULTIPLY_ADDITIVE TRANSITION_DISSOLVE
passType: 0
- keywords: TRANSITION_FADE
- keywords: COLOR_HSV_MODIFIER TARGET_LUMINANCE
passType: 0
- first: {fileID: 4800000, guid: e65241fa80a374114b3f55ed746c04d9, type: 3}
second:
Expand Down
30 changes: 24 additions & 6 deletions Packages/src/Editor/UIEffectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void DrawProperties()
}

EditorGUILayout.PropertyField(_shadowColorFilter);
EditorGUILayout.PropertyField(_shadowColor);
DrawColorPickerField(_shadowColor, false);
EditorGUILayout.PropertyField(_shadowColorGlow);
EditorGUILayout.PropertyField(_shadowFade);

Expand Down Expand Up @@ -289,12 +289,14 @@ public void DrawProperties()
EditorGUILayout.PropertyField(_gradationGradient);
break;
default:
EditorGUILayout.PropertyField(_gradationColor1);
var r = EditorGUILayout.GetControlRect();
r.width -= 20;
EditorGUI.PropertyField(r, _gradationColor2);
r.height = EditorGUIUtility.singleLineHeight;
DrawColorPickerField(_gradationColor1, r, new GUIContent("Gradation Color 1"));
r = EditorGUILayout.GetControlRect();
r.width -= 24;
DrawColorPickerField(_gradationColor2, r, new GUIContent("Gradation Color 2"));

r.x += r.width;
r.x += r.width + 4;
r.width = 20;
// Swap colors
if (GUI.Button(r, EditorGUIUtility.IconContent("preaudioloopoff"), "iconbutton"))
Expand Down Expand Up @@ -326,6 +328,22 @@ public void DrawProperties()
}
}

private static void DrawColorPickerField(SerializedProperty color, bool showAlpha = true)
{
var r = EditorGUILayout.GetControlRect();
r.height = EditorGUIUtility.singleLineHeight;
DrawColorPickerField(color, r, new GUIContent(color.displayName, color.tooltip), showAlpha);
}

private static void DrawColorPickerField(SerializedProperty color, Rect rect, GUIContent label, bool showAlpha = true)
{
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = color.hasMultipleDifferentValues;
var colorField = EditorGUI.ColorField(rect, label, color.colorValue, true, showAlpha, UIEffectProjectSettings.useHdrColorPicker);
if (EditorGUI.EndChangeCheck())
color.colorValue = colorField;
}

private static void DrawColor(SerializedProperty filter, SerializedProperty color, ColorFilter prevFilter)
{
if (filter.intValue == (int)ColorFilter.None)
Expand Down Expand Up @@ -361,7 +379,7 @@ private static void DrawColor(SerializedProperty filter, SerializedProperty colo
color.colorValue = Color.white;
}

EditorGUILayout.PropertyField(color);
DrawColorPickerField(color);
}
}

Expand Down
11 changes: 9 additions & 2 deletions Packages/src/Editor/UIEffectProjectSettingsEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEditor;
using System;
using UnityEditor;
using UnityEngine;
using Coffee.UIEffectInternal;
using UnityEditorInternal;
Expand All @@ -8,16 +9,18 @@ namespace Coffee.UIEffects.Editors
[CustomEditor(typeof(UIEffectProjectSettings))]
public class UIEffectProjectSettingsEditor : Editor
{
private bool _isInitialized;
private ReorderableList _reorderableList;
private SerializedProperty _useHdrColorPicker;
private SerializedProperty _transformSensitivity;
private bool _isInitialized;
private ShaderVariantRegistryEditor _shaderVariantRegistryEditor;

private void InitializeIfNeeded()
{
if (_isInitialized) return;

_transformSensitivity = serializedObject.FindProperty("m_TransformSensitivity");
_useHdrColorPicker = serializedObject.FindProperty("m_UseHdrColorPicker");
var runtimePresets = serializedObject.FindProperty("m_RuntimePresets");
_reorderableList = new ReorderableList(serializedObject, runtimePresets, true, true, true, true);
_reorderableList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "Runtime Presets");
Expand Down Expand Up @@ -64,6 +67,10 @@ public override void OnInspectorGUI()

// Settings
EditorGUILayout.PropertyField(_transformSensitivity);

// A GUIContent is used here to override the capitalization of HDR
EditorGUILayout.PropertyField(_useHdrColorPicker, new GUIContent("HDR Color Picker", "Use HDR color pickers on color fields."));

_reorderableList.DoLayoutList();

// Shader registry
Expand Down
3 changes: 2 additions & 1 deletion Packages/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,13 @@ UIEffectProjectSettings.shaderVariantCollection.WarmUp();

### Project Settings

![](https://github.com/user-attachments/assets/54dd42cf-099d-4fb1-b699-cad29bf211b6)
![](https://github.com/user-attachments/assets/e9938d45-ccb1-4e8a-819d-01329cda637a)

You can adjust the project-wide settings for UIEffect. (`Edit > Project Settings > UI > UIEffect`)

- **Transform Sensitivity**: `Low`, `Medium`, `High`
- Set the sensitivity of the transformation when `Use Target Transform` is enabled in `UIEffectReplica` component.
- **HDR Gradient**: Use HDR input fields for two-color gradients.
- **Runtime Presets**: A list of presets that can be loaded at runtime. Load them using `UIEffect.LoadPreset(presetName)` method.
- **Optional Shaders (UIEffect)**: A list of shaders that will be prioritized when a ui-effect shader is
requested.
Expand Down
Loading
Loading