diff --git a/Packages/src/Editor/Icons/ReverseIcon.png b/Packages/src/Editor/Icons/ReverseIcon.png new file mode 100644 index 0000000..147541d Binary files /dev/null and b/Packages/src/Editor/Icons/ReverseIcon.png differ 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 0000000..f3fbc1d Binary files /dev/null and b/Packages/src/Editor/Icons/d_ReverseIcon.png differ diff --git a/Packages/src/Editor/Icons/d_ReverseIcon.png.meta b/Packages/src/Editor/Icons/d_ReverseIcon.png.meta new file mode 100644 index 0000000..82f8d48 --- /dev/null +++ b/Packages/src/Editor/Icons/d_ReverseIcon.png.meta @@ -0,0 +1,109 @@ +fileFormatVersion: 2 +guid: 5634431eb895c4ff6bf61ddd65c83608 +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/UIEffectPropertyEditor.cs b/Packages/src/Editor/UIEffectPropertyEditor.cs index f9cec04..8c05644 100644 --- a/Packages/src/Editor/UIEffectPropertyEditor.cs +++ b/Packages/src/Editor/UIEffectPropertyEditor.cs @@ -2,6 +2,7 @@ using UnityEngine; using System; using System.Reflection; +using Coffee.UIEffectInternal; namespace Coffee.UIEffects.Editors { @@ -18,6 +19,8 @@ namespace Coffee.UIEffects.Editors (Action)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