Skip to content

Commit 38980a3

Browse files
committed
feat: Handle value change on min/max value on text slider
1 parent c8196e7 commit 38980a3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Assets/JCSUnity/Scripts/UI/Slider/JCS_SliderTextDisplay.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public class JCS_SliderTextDisplay : JCS_TextObject
2020
{
2121
/* Variables */
2222

23+
public Action onRefresh = null;
24+
25+
// Record for last min value.
26+
private float mMinVal = 0;
27+
28+
// Record for last max value.
29+
private float mMaxVal = 0;
30+
2331
[Separator("Runtime Variables (JCS_TextSliderDisplay)")]
2432

2533
[Tooltip("To update the text along with this slider's value.")]
@@ -53,6 +61,14 @@ private void OnDisable()
5361
RemoveListener();
5462
}
5563

64+
private void Update()
65+
{
66+
if (mSlider == null)
67+
return;
68+
69+
HandleMinMaxValueChanged();
70+
}
71+
5672
#if UNITY_EDITOR
5773
private void OnValidate()
5874
{
@@ -90,6 +106,21 @@ public void Refresh()
90106
Math.Round(mSlider.value, mRoundPlace),
91107
Math.Round(mSlider.maxValue, mRoundPlace),
92108
Math.Round(mSlider.minValue, mRoundPlace));
109+
110+
onRefresh?.Invoke();
111+
}
112+
113+
private void HandleMinMaxValueChanged()
114+
{
115+
if (mMinVal != mSlider.minValue ||
116+
mMaxVal != mSlider.maxValue)
117+
{
118+
mMinVal = mSlider.minValue;
119+
mMaxVal = mSlider.maxValue;
120+
121+
// Handle min/max value change.
122+
Refresh();
123+
}
93124
}
94125
}
95126
}

0 commit comments

Comments
 (0)