File tree Expand file tree Collapse file tree 2 files changed +34
-8
lines changed
Assets/JCSUnity/Scripts/UI/Slider
docs/ScriptReference/UI/Slider Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -43,29 +43,49 @@ public class JCS_SliderTextDisplay : JCS_TextObject
4343
4444 /* Functions */
4545
46- private void Awake ( )
46+ private void OnEnable ( )
4747 {
4848 AddListener ( ) ;
4949 }
5050
51+ private void OnDisable ( )
52+ {
53+ RemoveListener ( ) ;
54+ }
55+
56+ #if UNITY_EDITOR
5157 private void OnValidate ( )
5258 {
53- AddListener ( ) ;
59+ Refresh ( ) ;
5460 }
61+ #endif
5562
5663 private void AddListener ( )
5764 {
58- if ( mSlider == null )
59- return ;
60-
61- mSlider . onValueChanged . AddListener ( delegate { OnValueChanged ( ) ; } ) ;
65+ mSlider ? . onValueChanged . AddListener ( OnValueChanged ) ;
6266
6367 // Call once.
64- OnValueChanged ( ) ;
68+ Refresh ( ) ;
69+ }
70+
71+ private void RemoveListener ( )
72+ {
73+ mSlider ? . onValueChanged . RemoveListener ( OnValueChanged ) ;
74+ }
75+
76+ private void OnValueChanged ( float val )
77+ {
78+ Refresh ( ) ;
6579 }
6680
67- private void OnValueChanged ( )
81+ /// <summary>
82+ /// Refresh the text once.
83+ /// </summary>
84+ public void Refresh ( )
6885 {
86+ if ( mSlider == null )
87+ return ;
88+
6989 text = string . Format ( mFormat ,
7090 Math . Round ( mSlider . value , mRoundPlace ) ,
7191 Math . Round ( mSlider . maxValue , mRoundPlace ) ,
Original file line number Diff line number Diff line change @@ -9,3 +9,9 @@ Text that display slider's value.
99| mSlider | To update the text along with this slider's value. |
1010| mFormat | Format text to display. |
1111| mRoundPlace | Place you want to round the decimal. |
12+
13+ ## Functions
14+
15+ | Name | Description |
16+ | :--------| :-----------------------|
17+ | Refresh | Refresh the text once. |
You can’t perform that action at this time.
0 commit comments