Created
March 23, 2024 00:56
-
-
Save baba-s/7e305195a37fe8ad26ade4943bad74bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
namespace Kogane.Internal | |
{ | |
[InitializeOnLoad] | |
internal static class LineRendererConstantColorPropertyField | |
{ | |
static LineRendererConstantColorPropertyField() | |
{ | |
_ = new EditorGUIUtility.PropertyCallbackScope( Callback ); | |
static void Callback | |
( | |
Rect rect, | |
SerializedProperty serializedProperty | |
) | |
{ | |
if ( serializedProperty.serializedObject.targetObject.GetType().Name != nameof( LineRenderer ) ) return; | |
if ( serializedProperty.propertyPath != "m_Parameters.colorGradient" ) return; | |
var color = serializedProperty.gradientValue.colorKeys[ 0 ].color; | |
using var changeCheckScope = new EditorGUI.ChangeCheckScope(); | |
var newColor = EditorGUILayout.ColorField( "Constant Color", color ); | |
if ( !changeCheckScope.changed ) return; | |
var newGradient = new Gradient(); | |
var newAlpha = newColor.a; | |
newGradient.SetKeys | |
( | |
new GradientColorKey[] { new( newColor, 0 ), new( newColor, 1 ) }, | |
new GradientAlphaKey[] { new( newAlpha, 0 ), new( newAlpha, 1 ) } | |
); | |
serializedProperty.gradientValue = newGradient; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment