@@ -42,16 +42,16 @@ public void SetSerializedObject(SerializedObject serialized)
4242 m_SerializedObject = serialized ;
4343 }
4444
45- public virtual void Draw ( Rect rect , SerializedProperty value )
45+ public virtual void Draw ( Rect rect , SerializedProperty value , ref float floatValue )
4646 {
4747 BuildRects ( rect , out var sliderRect , out var iconRect ) ;
4848
4949 if ( m_Descriptor . clampValue )
50- ClampValue ( value , m_Descriptor . sliderRange ) ;
50+ ClampValue ( ref floatValue , m_Descriptor . sliderRange ) ;
5151
52- var level = CurrentRange ( value . floatValue ) ;
52+ var level = CurrentRange ( floatValue ) ;
5353
54- DoSlider ( sliderRect , value , m_Descriptor . sliderRange , level . value ) ;
54+ DoSlider ( sliderRect , ref floatValue , m_Descriptor . sliderRange , level . value ) ;
5555
5656 if ( m_Descriptor . hasMarkers )
5757 {
@@ -66,9 +66,9 @@ public virtual void Draw(Rect rect, SerializedProperty value)
6666
6767 var levelIconContent = level . content ;
6868 var levelRange = level . value ;
69- DoIcon ( iconRect , levelIconContent , value , levelRange . y ) ;
69+ DoIcon ( iconRect , levelIconContent , value , floatValue , levelRange . y ) ;
7070
71- var thumbValue = value . floatValue ;
71+ var thumbValue = floatValue ;
7272 var thumbPosition = GetPositionOnSlider ( thumbValue , level . value ) ;
7373 var thumbTooltip = levelIconContent . tooltip ;
7474 DoThumbTooltip ( sliderRect , thumbPosition , thumbValue , thumbTooltip ) ;
@@ -99,8 +99,8 @@ void BuildRects(Rect baseRect, out Rect sliderRect, out Rect iconRect)
9999 iconRect . width = EditorGUIUtility . singleLineHeight ;
100100 }
101101
102- void ClampValue ( SerializedProperty value , Vector2 range ) =>
103- value . floatValue = Mathf . Clamp ( value . floatValue , range . x , range . y ) ;
102+ void ClampValue ( ref float value , Vector2 range ) =>
103+ value = Mathf . Clamp ( value , range . x , range . y ) ;
104104
105105 private static Color k_DarkThemeColor = new Color32 ( 153 , 153 , 153 , 255 ) ;
106106 private static Color k_LiteThemeColor = new Color32 ( 97 , 97 , 97 , 255 ) ;
@@ -143,7 +143,7 @@ void DoSliderMarker(Rect rect, float position, float value, string tooltip)
143143 EditorGUI . LabelField ( markerTooltipRect , GetLightUnitTooltip ( tooltip , value , m_Descriptor . unitName ) ) ;
144144 }
145145
146- void DoIcon ( Rect rect , GUIContent icon , SerializedProperty value , float range )
146+ void DoIcon ( Rect rect , GUIContent icon , SerializedProperty value , float floatValue , float range )
147147 {
148148 // Draw the context menu feedback before the icon
149149 GUI . Box ( rect , GUIContent . none , SliderStyles . k_IconButton ) ;
@@ -162,20 +162,20 @@ void DoIcon(Rect rect, GUIContent icon, SerializedProperty value, float range)
162162 if ( rect . Contains ( e . mousePosition ) )
163163 {
164164 var menuPosition = rect . position + rect . size ;
165- DoContextMenu ( menuPosition , value ) ;
165+ DoContextMenu ( menuPosition , value , floatValue ) ;
166166 e . Use ( ) ;
167167 }
168168 }
169169 }
170170
171- void DoContextMenu ( Vector2 pos , SerializedProperty value )
171+ void DoContextMenu ( Vector2 pos , SerializedProperty value , float floatValue )
172172 {
173173 var menu = new GenericMenu ( ) ;
174174
175175 foreach ( var preset in m_Descriptor . valueRanges )
176176 {
177177 // Indicate a checkmark if the value is within this preset range.
178- var isInPreset = CurrentRange ( value . floatValue ) . value == preset . value ;
178+ var isInPreset = CurrentRange ( floatValue ) . value == preset . value ;
179179
180180 menu . AddItem ( EditorGUIUtility . TrTextContent ( preset . content . tooltip ) , isInPreset , ( ) => SetValueToPreset ( value , preset ) ) ;
181181 }
@@ -218,17 +218,17 @@ protected virtual GUIContent GetLightUnitTooltip(string baseTooltip, float value
218218 return new GUIContent ( string . Empty , tooltip ) ;
219219 }
220220
221- protected virtual void DoSlider ( Rect rect , SerializedProperty value , Vector2 sliderRange , Vector2 valueRange )
221+ protected virtual void DoSlider ( Rect rect , ref float value , Vector2 sliderRange , Vector2 valueRange )
222222 {
223- DoSlider ( rect , value , sliderRange ) ;
223+ DoSlider ( rect , ref value , sliderRange ) ;
224224 }
225225
226226 /// <summary>
227227 /// Draws a linear slider mapped to the min/max value range. Override this for different slider behavior (texture background, power).
228228 /// </summary>
229- protected virtual void DoSlider ( Rect rect , SerializedProperty value , Vector2 sliderRange )
229+ protected virtual void DoSlider ( Rect rect , ref float value , Vector2 sliderRange )
230230 {
231- value . floatValue = GUI . HorizontalSlider ( rect , value . floatValue , sliderRange . x , sliderRange . y ) ;
231+ value = GUI . HorizontalSlider ( rect , value , sliderRange . x , sliderRange . y ) ;
232232 }
233233
234234 // Remaps value in the domain { Min0, Max0 } to { Min1, Max1 } (by default, normalizes it to (0, 1).
@@ -338,36 +338,36 @@ bool UpdatePiece(ref Piece piece, float x)
338338 return false ;
339339 }
340340
341- void SliderOutOfBounds ( Rect rect , SerializedProperty value )
341+ void SliderOutOfBounds ( Rect rect , ref float value )
342342 {
343343 EditorGUI . BeginChangeCheck ( ) ;
344- var internalValue = GUI . HorizontalSlider ( rect , value . floatValue , 0f , 1f ) ;
344+ var internalValue = GUI . HorizontalSlider ( rect , value , 0f , 1f ) ;
345345 if ( EditorGUI . EndChangeCheck ( ) )
346346 {
347347 Piece p = new Piece ( ) ;
348348 UpdatePiece ( ref p , internalValue ) ;
349- value . floatValue = SliderToValue ( p , internalValue ) ;
349+ value = SliderToValue ( p , internalValue ) ;
350350 }
351351 }
352352
353- protected override void DoSlider ( Rect rect , SerializedProperty value , Vector2 sliderRange , Vector2 valueRange )
353+ protected override void DoSlider ( Rect rect , ref float value , Vector2 sliderRange , Vector2 valueRange )
354354 {
355355 // Map the internal slider value to the current piecewise function
356356 if ( ! m_PiecewiseFunctionMap . TryGetValue ( valueRange , out var piece ) )
357357 {
358358 // Assume that if the piece is not found, that means the unit value is out of bounds.
359- SliderOutOfBounds ( rect , value ) ;
359+ SliderOutOfBounds ( rect , ref value ) ;
360360 return ;
361361 }
362362
363363 // Maintain an internal value to support a single linear continuous function
364364 EditorGUI . BeginChangeCheck ( ) ;
365- var internalValue = GUI . HorizontalSlider ( rect , ValueToSlider ( piece , value . floatValue ) , 0f , 1f ) ;
365+ var internalValue = GUI . HorizontalSlider ( rect , ValueToSlider ( piece , value ) , 0f , 1f ) ;
366366 if ( EditorGUI . EndChangeCheck ( ) )
367367 {
368368 // Ensure that the current function piece is being used to transform the value
369369 UpdatePiece ( ref piece , internalValue ) ;
370- value . floatValue = SliderToValue ( piece , internalValue ) ;
370+ value = SliderToValue ( piece , internalValue ) ;
371371 }
372372 }
373373 }
@@ -404,18 +404,15 @@ public void Setup(LightUnit unit, SerializedHDLight light, Editor owner)
404404 m_SpotReflectorEnabled = light . enableSpotReflector . boolValue ;
405405 }
406406
407- public override void Draw ( Rect rect , SerializedProperty value )
407+ public override void Draw ( Rect rect , SerializedProperty value , ref float floatValue )
408408 {
409409 // Convert the incoming unit value into Lumen as the punctual slider is always in these terms (internally)
410- value . floatValue = UnitToLumen ( value . floatValue ) ;
410+ float convertedValue = UnitToLumen ( floatValue ) ;
411411
412- base . Draw ( rect , value ) ;
413-
414- value . floatValue = LumenToUnit ( value . floatValue ) ;
415-
416- // Must apply properties here to ensure proper undo/redo functionality.
417- // The reason this is likely necessary is due to how we handle the internal unit conversion into lumen.
418- m_Light . Apply ( ) ;
412+ EditorGUI . BeginChangeCheck ( ) ;
413+ base . Draw ( rect , value , ref convertedValue ) ;
414+ if ( EditorGUI . EndChangeCheck ( ) )
415+ floatValue = LumenToUnit ( convertedValue ) ;
419416 }
420417
421418 protected override GUIContent GetLightUnitTooltip ( string baseTooltip , float value , string unit )
@@ -551,27 +548,27 @@ protected override void SetValueToPreset(SerializedProperty value, LightUnitSlid
551548 m_Settings . ApplyModifiedProperties ( ) ;
552549 }
553550
554- protected override void DoSlider ( Rect rect , SerializedProperty value , Vector2 sliderRange )
551+ protected override void DoSlider ( Rect rect , ref float value , Vector2 sliderRange )
555552 {
556- SliderWithTextureNoTextField ( rect , value , sliderRange , m_Settings ) ;
553+ SliderWithTextureNoTextField ( rect , ref value , sliderRange , m_Settings ) ;
557554 }
558555
559556 // Note: We could use the internal SliderWithTexture, however: the internal slider func forces a text-field (and no ability to opt-out of it).
560- void SliderWithTextureNoTextField ( Rect rect , SerializedProperty value , Vector2 range , LightEditor . Settings settings )
557+ void SliderWithTextureNoTextField ( Rect rect , ref float value , Vector2 range , LightEditor . Settings settings )
561558 {
562559 GUI . DrawTexture ( rect , GetKelvinGradientTexture ( settings ) ) ;
563560
564561 EditorGUI . BeginChangeCheck ( ) ;
565562
566563 // Draw the exponential slider that fits 6500K to the white point on the gradient texture.
567- var internalValue = GUI . HorizontalSlider ( rect , ValueToSlider ( value . floatValue ) , 0f , 1f , SliderStyles . k_TemperatureBorder , SliderStyles . k_TemperatureThumb ) ;
564+ var internalValue = GUI . HorizontalSlider ( rect , ValueToSlider ( value ) , 0f , 1f , SliderStyles . k_TemperatureBorder , SliderStyles . k_TemperatureThumb ) ;
568565
569566 // Map the value back into kelvin.
570- value . floatValue = SliderToValue ( internalValue ) ;
567+ value = SliderToValue ( internalValue ) ;
571568
572569 // Round to nearest since so much precision is not necessary for kelvin while sliding.
573570 if ( EditorGUI . EndChangeCheck ( ) )
574- value . floatValue = Mathf . Round ( value . floatValue ) ;
571+ value = Mathf . Round ( value ) ;
575572 }
576573 }
577574
@@ -620,20 +617,30 @@ public void Draw(HDLightType type, LightUnit lightUnit, SerializedProperty value
620617
621618 void DrawDirectionalUnitSlider ( SerializedProperty value , Rect rect )
622619 {
623- k_DirectionalLightUnitSlider . Draw ( rect , value ) ;
620+ float val = value . floatValue ;
621+ k_DirectionalLightUnitSlider . Draw ( rect , value , ref val ) ;
622+ if ( val != value . floatValue )
623+ value . floatValue = val ;
624624 }
625625
626626 void DrawPunctualLightUnitSlider ( LightUnit lightUnit , SerializedProperty value , Rect rect , SerializedHDLight light , Editor owner )
627627 {
628628 k_PunctualLightUnitSlider . Setup ( lightUnit , light , owner ) ;
629- k_PunctualLightUnitSlider . Draw ( rect , value ) ;
629+
630+ float val = value . floatValue ;
631+ k_PunctualLightUnitSlider . Draw ( rect , value , ref val ) ;
632+ if ( val != value . floatValue )
633+ value . floatValue = val ;
630634 }
631635
632636 public void DrawExposureSlider ( SerializedProperty value , Rect rect )
633637 {
634638 using ( new EditorGUI . IndentLevelScope ( - EditorGUI . indentLevel ) )
635639 {
636- k_ExposureSlider . Draw ( rect , value ) ;
640+ float val = value . floatValue ;
641+ k_ExposureSlider . Draw ( rect , value , ref val ) ;
642+ if ( val != value . floatValue )
643+ value . floatValue = val ;
637644 }
638645 }
639646
@@ -642,7 +649,11 @@ public void DrawTemperatureSlider(LightEditor.Settings settings, SerializedPrope
642649 using ( new EditorGUI . IndentLevelScope ( - EditorGUI . indentLevel ) )
643650 {
644651 k_TemperatureSlider . Setup ( settings ) ;
645- k_TemperatureSlider . Draw ( rect , value ) ;
652+
653+ float val = value . floatValue ;
654+ k_TemperatureSlider . Draw ( rect , value , ref val ) ;
655+ if ( val != value . floatValue )
656+ value . floatValue = val ;
646657 }
647658 }
648659 }
0 commit comments