From 78f7c2f789fb4af0ad2eb7accfb111eb9adccd4e Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:22:57 +0900 Subject: [PATCH] feat: add gradient reverse button --- Packages/src/Editor/Icons/ReverseIcon.png | Bin 0 -> 1266 bytes .../src/Editor/Icons/ReverseIcon.png.meta | 109 ++++++++++++++++++ Packages/src/Editor/Icons/d_ReverseIcon.png | Bin 0 -> 547 bytes .../src/Editor/Icons/d_ReverseIcon.png.meta | 109 ++++++++++++++++++ Packages/src/Editor/UIEffectPropertyEditor.cs | 42 ++++++- .../src/Runtime/Internal/Utilities/Misc.cs | 22 ++++ 6 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 Packages/src/Editor/Icons/ReverseIcon.png create mode 100644 Packages/src/Editor/Icons/ReverseIcon.png.meta create mode 100644 Packages/src/Editor/Icons/d_ReverseIcon.png create mode 100644 Packages/src/Editor/Icons/d_ReverseIcon.png.meta diff --git a/Packages/src/Editor/Icons/ReverseIcon.png b/Packages/src/Editor/Icons/ReverseIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..147541daa4951bed4651f98644106ea46ddc7c77 GIT binary patch literal 1266 zcmVpF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H11b<0H zK~#90?U`F>990~~zyFyehInNk7NHfz7saI22SF>?l6t|rVrR~5K!Q-bKoO0;7S{wH ze2@yYqOo8!1~Qk;#zbp{QX&;g($> zXJ%&pj>9XJ1pt6)nwy0X2LNnT$R~p!cxY~J?sU68sdxygC=?1O0Ne@SJB7T-FpOhT z%G=uYNo@fD;CbFkrBc}n;0uMk0l*O{TU9)OeXV8Gu!04D*ym2%ese% z<^Wu+kPidc;d$O)QLYuK03xDXF1N8-t*&WZ7lvVMX69*}e-1Qq(lCsNXJ==B4ZBWg z0j6o*EQB}+;D(lx>SIL+vCVOuQEuavO}3)V~TR zO}7Bu0d&(XKz9J$MEW$gx(yBsAudZgP#o0j^>c<{9B~}y`>?g4+n{Axj}Xx(0F1Z- zc8GwPclf@)aH&P1e*q%eh4pvy0ALW&&ag#MUWNaNCr{@gqR{M73fK)`C6+{;Hgx=oXs^d7Pqs#{*p9Q3pR{-z;JgAWW zAtKv#-Orngs-LC~L&L+vJ=tt_A2UCvkZVNrg6q2P#TPGmS~?9%DPIKe7S@iZ!OVLL zg~ChCj;D3e@^RR*tWhG`51?<&MTz`@fq~Jfsi|_i0h6Y!d4QC1JAgT;M^8)DYW2za z`T0LvHs}Ct4@6AU99;d1d%Z&barGj&VR-IRw3VF7{)QvG;eR$ zCn;h%4SJsUTYrE5HUOU~6Xm7ZE!TB;>t-UNwF zgnZw3nE5^czbj-ro6WwGly@^EIui4J|0@7@0r2QUHPAQ8PhI5_xrC%nVxej3vqKsVh2bO+E)w*cJ%bki+B ccL3e|2Nlz#AoC4NDgXcg07*qoM6N<$g5okgasU7T literal 0 HcmV?d00001 diff --git a/Packages/src/Editor/Icons/ReverseIcon.png.meta b/Packages/src/Editor/Icons/ReverseIcon.png.meta new file mode 100644 index 0000000..6f71ae5 --- /dev/null +++ b/Packages/src/Editor/Icons/ReverseIcon.png.meta @@ -0,0 +1,109 @@ +fileFormatVersion: 2 +guid: 4075e0c7a9e2c4f4d8f9e3c34e3e59a3 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/src/Editor/Icons/d_ReverseIcon.png b/Packages/src/Editor/Icons/d_ReverseIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..f3fbc1d5ac455ea9784d4eddcd5d8e7612f33ef2 GIT binary patch literal 547 zcmV+;0^I$HP)$h>DVwsYDP&kgx`eSVsSWU|}PusDxA!HH#t+ zv*$fwivb~!&Y<9eRZycvzHcCe+0)&H+viGrA9Xy+dZ-u} zf!j<|dZ`GQgxks-`p6z0z~z}oKUqtim$3dOU{us96()FSm4WKZFY~mR25eEb}?hQuE)}K zku|xg#}dyA7|X^*{ApL<&)K1lFEA~0Whc@Y#DX5nv`l`}r|=yvP+D?=eDDe`U|y3C z-Ulu4fqY~DtHF+6#TD}7stogJfYjtn+@PbVBV5J35MwCATqQrg7V<+R1LT7`T)<3{ zkGu(5;05_`1+8Gme@jo2Us}eD-fJ6!T-k}F<&HPQWIv`~T%4 z){Y++uv+sCEVV1hM6#Ex$p!p|%kw2UOxAE3KU9TTIZoD+Bgj;RUpP)Delegate.CreateDelegate(typeof(Action), s_PiGradient.SetMethod); + private static GUIContent s_ReverseGradientContent; + private SerializedProperty _toneFilter; private SerializedProperty _toneIntensity; @@ -109,6 +112,12 @@ namespace Coffee.UIEffects.Editors protected virtual void OnEnable() { + if (s_ReverseGradientContent == null) + { + var iconDir = "Packages/com.coffee.ui-effect/Editor/Icons"; + s_ReverseGradientContent = Misc.GetIconContent($"{iconDir}/ReverseIcon.png", "Reverse gradient"); + } + _toneFilter = serializedObject.FindProperty("m_ToneFilter"); _toneIntensity = serializedObject.FindProperty("m_ToneIntensity"); @@ -513,17 +522,48 @@ namespace Coffee.UIEffects.Editors private static void DrawGradientField(SerializedProperty gradient) { var r = EditorGUILayout.GetControlRect(); + const float reverseWidth = 20f; + var gradientRect = new Rect(r.x, r.y, r.width - reverseWidth - 2, r.height); + var reverseRect = new Rect(gradientRect.xMax + 2, r.y, reverseWidth, r.height); var label = EditorGUIUtility.TrTempContent(gradient.displayName); label.tooltip = gradient.tooltip; var hdr = UIEffectProjectSettings.useHdrColorPicker; EditorGUI.showMixedValue = gradient.hasMultipleDifferentValues; EditorGUI.BeginChangeCheck(); - var gradientValue = EditorGUI.GradientField(r, label, s_GetGradient(gradient), hdr); + var gradientValue = EditorGUI.GradientField(gradientRect, label, s_GetGradient(gradient), hdr); if (EditorGUI.EndChangeCheck()) { s_SetGradient(gradient, gradientValue); } + + if (GUI.Button(reverseRect, s_ReverseGradientContent, "IconButton")) + { + ReverseGradient(gradient); + } + } + + private static void ReverseGradient(SerializedProperty property) + { + var source = s_GetGradient(property); + var colorKeys = source.colorKeys; + var alphaKeys = source.alphaKeys; + for (var i = 0; i < colorKeys.Length; i++) + { + colorKeys[i].time = 1f - colorKeys[i].time; + } + + for (var i = 0; i < alphaKeys.Length; i++) + { + alphaKeys[i].time = 1f - alphaKeys[i].time; + } + + Array.Reverse(colorKeys); + Array.Reverse(alphaKeys); + + var reversed = new Gradient { mode = source.mode }; + reversed.SetKeys(colorKeys, alphaKeys); + s_SetGradient(property, reversed); } private static void DrawColor(SerializedProperty color, ColorFilter filter, ColorFilter prevFilter, diff --git a/Packages/src/Runtime/Internal/Utilities/Misc.cs b/Packages/src/Runtime/Internal/Utilities/Misc.cs index 4232450..e8d379b 100644 --- a/Packages/src/Runtime/Internal/Utilities/Misc.cs +++ b/Packages/src/Runtime/Internal/Utilities/Misc.cs @@ -87,6 +87,28 @@ namespace Coffee.UIEffectInternal } #endif } + +#if UNITY_EDITOR + public static GUIContent GetIconContent(string iconPath, string tooltip = null) + { + if (string.IsNullOrEmpty(iconPath)) + { + return new GUIContent(tooltip); + } + + if (EditorGUIUtility.isProSkin) + { + var darkIconPath = $"{Path.GetDirectoryName(iconPath)}/d_{Path.GetFileName(iconPath)}"; + if (File.Exists(darkIconPath)) + { + iconPath = darkIconPath; + } + } + + var icon = AssetDatabase.LoadAssetAtPath(iconPath); + return new GUIContent(icon, tooltip); + } +#endif } #if !UNITY_2021_2_OR_NEWER