8
8
using UnityExplorer . Helpers ;
9
9
using UnityExplorer . UI ;
10
10
11
- // Basically just to fix an issue with Scrollbars, instead we use a Slider as the scrollbar.
12
- public class SliderScrollbar
11
+ namespace UnityExplorer . UI . Shared
13
12
{
14
- internal static readonly List < SliderScrollbar > Instances = new List < SliderScrollbar > ( ) ;
13
+ // Basically just to fix an issue with Scrollbars, instead we use a Slider as the scrollbar.
14
+ public class SliderScrollbar
15
+ {
16
+ internal static readonly List < SliderScrollbar > Instances = new List < SliderScrollbar > ( ) ;
15
17
16
- public bool IsActive { get ; private set ; }
18
+ public bool IsActive { get ; private set ; }
17
19
18
- internal readonly Scrollbar m_scrollbar ;
19
- internal readonly Slider m_slider ;
20
- internal readonly RectTransform m_scrollRect ;
20
+ internal readonly Scrollbar m_scrollbar ;
21
+ internal readonly Slider m_slider ;
22
+ internal readonly RectTransform m_scrollRect ;
21
23
22
- public SliderScrollbar ( Scrollbar scrollbar , Slider slider )
23
- {
24
- Instances . Add ( this ) ;
24
+ internal InputFieldScroller m_parentInputScroller ;
25
25
26
- this . m_scrollbar = scrollbar ;
27
- this . m_slider = slider ;
28
- this . m_scrollRect = scrollbar . transform . parent . GetComponent < RectTransform > ( ) ;
26
+ public SliderScrollbar ( Scrollbar scrollbar , Slider slider )
27
+ {
28
+ Instances . Add ( this ) ;
29
29
30
- this . m_scrollbar . onValueChanged . AddListener ( this . OnScrollbarValueChanged ) ;
31
- this . m_slider . onValueChanged . AddListener ( this . OnSliderValueChanged ) ;
30
+ this . m_scrollbar = scrollbar ;
31
+ this . m_slider = slider ;
32
+ this . m_scrollRect = scrollbar . transform . parent . GetComponent < RectTransform > ( ) ;
32
33
33
- this . RefreshVisibility ( ) ;
34
- this . m_slider . Set ( 1f , false ) ;
35
- }
34
+ this . m_scrollbar . onValueChanged . AddListener ( this . OnScrollbarValueChanged ) ;
35
+ this . m_slider . onValueChanged . AddListener ( this . OnSliderValueChanged ) ;
36
36
37
- internal bool CheckDestroyed ( )
38
- {
39
- if ( ! m_slider || ! m_scrollbar )
40
- {
41
- Instances . Remove ( this ) ;
42
- return true ;
37
+ this . RefreshVisibility ( ) ;
38
+ this . m_slider . Set ( 1f , false ) ;
43
39
}
44
40
45
- return false ;
46
- }
41
+ internal bool CheckDestroyed ( )
42
+ {
43
+ if ( ! m_slider || ! m_scrollbar )
44
+ {
45
+ Instances . Remove ( this ) ;
46
+ return true ;
47
+ }
47
48
48
- internal void Update ( )
49
- {
50
- this . RefreshVisibility ( ) ;
51
- }
49
+ return false ;
50
+ }
52
51
53
- internal void RefreshVisibility ( )
54
- {
55
- if ( ! m_slider . gameObject . activeInHierarchy )
52
+ internal void Update ( )
56
53
{
57
- IsActive = false ;
58
- return ;
54
+ this . RefreshVisibility ( ) ;
59
55
}
60
56
61
- bool shouldShow = ! Mathf . Approximately ( this . m_scrollbar . size , 1 ) ;
62
- var obj = this . m_slider . handleRect . gameObject ;
63
-
64
- if ( IsActive != shouldShow )
57
+ internal void RefreshVisibility ( )
65
58
{
66
- IsActive = shouldShow ;
67
- obj . SetActive ( IsActive ) ;
59
+ if ( ! m_slider . gameObject . activeInHierarchy )
60
+ {
61
+ IsActive = false ;
62
+ return ;
63
+ }
64
+
65
+ bool shouldShow = ! Mathf . Approximately ( this . m_scrollbar . size , 1 ) ;
66
+ var obj = this . m_slider . handleRect . gameObject ;
68
67
69
- if ( IsActive )
70
- this . m_slider . Set ( this . m_scrollbar . value , false ) ;
71
- else
72
- m_slider . Set ( 1f , false ) ;
68
+ if ( IsActive != shouldShow )
69
+ {
70
+ IsActive = shouldShow ;
71
+ obj . SetActive ( IsActive ) ;
72
+
73
+ if ( IsActive )
74
+ this . m_slider . Set ( this . m_scrollbar . value , false ) ;
75
+ else
76
+ m_slider . Set ( 1f , false ) ;
77
+ }
73
78
}
74
- }
75
79
76
- public void OnScrollbarValueChanged ( float _value )
77
- {
78
- if ( this . m_slider . value != _value )
79
- this . m_slider . Set ( _value , false ) ;
80
- }
80
+ public void OnScrollbarValueChanged ( float _value )
81
+ {
82
+ if ( this . m_slider . value != _value )
83
+ this . m_slider . Set ( _value , false ) ;
84
+ }
81
85
82
- public void OnSliderValueChanged ( float _value )
83
- {
84
- this . m_scrollbar . value = _value ;
85
- }
86
+ public void OnSliderValueChanged ( float _value )
87
+ {
88
+ this . m_scrollbar . value = _value ;
89
+ }
86
90
87
- #region UI CONSTRUCTION
91
+ #region UI CONSTRUCTION
88
92
89
- public static GameObject CreateSliderScrollbar ( GameObject parent , out Slider slider )
90
- {
91
- GameObject sliderObj = UIFactory . CreateUIObject ( "Slider" , parent , UIFactory . thinSize ) ;
92
-
93
- GameObject bgObj = UIFactory . CreateUIObject ( "Background" , sliderObj ) ;
94
- GameObject fillAreaObj = UIFactory . CreateUIObject ( "Fill Area" , sliderObj ) ;
95
- GameObject fillObj = UIFactory . CreateUIObject ( "Fill" , fillAreaObj ) ;
96
- GameObject handleSlideAreaObj = UIFactory . CreateUIObject ( "Handle Slide Area" , sliderObj ) ;
97
- GameObject handleObj = UIFactory . CreateUIObject ( "Handle" , handleSlideAreaObj ) ;
98
-
99
- Image bgImage = bgObj . AddComponent < Image > ( ) ;
100
- bgImage . type = Image . Type . Sliced ;
101
- bgImage . color = new Color ( 0.05f , 0.05f , 0.05f , 1.0f ) ;
102
-
103
- RectTransform bgRect = bgObj . GetComponent < RectTransform > ( ) ;
104
- bgRect . anchorMin = Vector2 . zero ;
105
- bgRect . anchorMax = Vector2 . one ;
106
- bgRect . sizeDelta = Vector2 . zero ;
107
- bgRect . offsetMax = new Vector2 ( - 10f , 0f ) ;
108
-
109
- RectTransform fillAreaRect = fillAreaObj . GetComponent < RectTransform > ( ) ;
110
- fillAreaRect . anchorMin = new Vector2 ( 0f , 0.25f ) ;
111
- fillAreaRect . anchorMax = new Vector2 ( 1f , 0.75f ) ;
112
- fillAreaRect . anchoredPosition = new Vector2 ( - 5f , 0f ) ;
113
- fillAreaRect . sizeDelta = new Vector2 ( - 20f , 0f ) ;
114
-
115
- Image fillImage = fillObj . AddComponent < Image > ( ) ;
116
- fillImage . type = Image . Type . Sliced ;
117
- fillImage . color = Color . clear ;
118
-
119
- fillObj . GetComponent < RectTransform > ( ) . sizeDelta = new Vector2 ( 10f , 0f ) ;
120
-
121
- RectTransform handleSlideRect = handleSlideAreaObj . GetComponent < RectTransform > ( ) ;
122
- handleSlideRect . anchorMin = new Vector2 ( 0f , 0f ) ;
123
- handleSlideRect . anchorMax = new Vector2 ( 1f , 1f ) ;
124
- handleSlideRect . offsetMin = new Vector2 ( 15f , 30f ) ;
125
- handleSlideRect . offsetMax = new Vector2 ( - 15f , 0f ) ;
126
- handleSlideRect . sizeDelta = new Vector2 ( - 30f , - 30f ) ;
127
-
128
- Image handleImage = handleObj . AddComponent < Image > ( ) ;
129
- handleImage . color = new Color ( 0.5f , 0.5f , 0.5f , 1.0f ) ;
130
-
131
- var handleRect = handleObj . GetComponent < RectTransform > ( ) ;
132
- handleRect . sizeDelta = new Vector2 ( 15f , 30f ) ;
133
- handleRect . offsetMin = new Vector2 ( - 13f , - 28f ) ;
134
- handleRect . offsetMax = new Vector2 ( 3f , - 2f ) ;
135
-
136
- var sliderBarLayout = sliderObj . AddComponent < LayoutElement > ( ) ;
137
- sliderBarLayout . minWidth = 25 ;
138
- sliderBarLayout . flexibleWidth = 0 ;
139
- sliderBarLayout . minHeight = 30 ;
140
- sliderBarLayout . flexibleHeight = 5000 ;
141
-
142
- slider = sliderObj . AddComponent < Slider > ( ) ;
143
- slider . fillRect = fillObj . GetComponent < RectTransform > ( ) ;
144
- slider . handleRect = handleObj . GetComponent < RectTransform > ( ) ;
145
- slider . targetGraphic = handleImage ;
146
- slider . direction = Slider . Direction . BottomToTop ;
147
- UIFactory . SetDefaultColorTransitionValues ( slider ) ;
148
-
149
- return sliderObj ;
150
- }
93
+ public static GameObject CreateSliderScrollbar ( GameObject parent , out Slider slider )
94
+ {
95
+ GameObject sliderObj = UIFactory . CreateUIObject ( "Slider" , parent , UIFactory . thinSize ) ;
96
+
97
+ GameObject bgObj = UIFactory . CreateUIObject ( "Background" , sliderObj ) ;
98
+ GameObject fillAreaObj = UIFactory . CreateUIObject ( "Fill Area" , sliderObj ) ;
99
+ GameObject fillObj = UIFactory . CreateUIObject ( "Fill" , fillAreaObj ) ;
100
+ GameObject handleSlideAreaObj = UIFactory . CreateUIObject ( "Handle Slide Area" , sliderObj ) ;
101
+ GameObject handleObj = UIFactory . CreateUIObject ( "Handle" , handleSlideAreaObj ) ;
102
+
103
+ Image bgImage = bgObj . AddComponent < Image > ( ) ;
104
+ bgImage . type = Image . Type . Sliced ;
105
+ bgImage . color = new Color ( 0.05f , 0.05f , 0.05f , 1.0f ) ;
106
+
107
+ RectTransform bgRect = bgObj . GetComponent < RectTransform > ( ) ;
108
+ bgRect . anchorMin = Vector2 . zero ;
109
+ bgRect . anchorMax = Vector2 . one ;
110
+ bgRect . sizeDelta = Vector2 . zero ;
111
+ bgRect . offsetMax = new Vector2 ( - 10f , 0f ) ;
112
+
113
+ RectTransform fillAreaRect = fillAreaObj . GetComponent < RectTransform > ( ) ;
114
+ fillAreaRect . anchorMin = new Vector2 ( 0f , 0.25f ) ;
115
+ fillAreaRect . anchorMax = new Vector2 ( 1f , 0.75f ) ;
116
+ fillAreaRect . anchoredPosition = new Vector2 ( - 5f , 0f ) ;
117
+ fillAreaRect . sizeDelta = new Vector2 ( - 20f , 0f ) ;
118
+
119
+ Image fillImage = fillObj . AddComponent < Image > ( ) ;
120
+ fillImage . type = Image . Type . Sliced ;
121
+ fillImage . color = Color . clear ;
122
+
123
+ fillObj . GetComponent < RectTransform > ( ) . sizeDelta = new Vector2 ( 10f , 0f ) ;
124
+
125
+ RectTransform handleSlideRect = handleSlideAreaObj . GetComponent < RectTransform > ( ) ;
126
+ handleSlideRect . anchorMin = new Vector2 ( 0f , 0f ) ;
127
+ handleSlideRect . anchorMax = new Vector2 ( 1f , 1f ) ;
128
+ handleSlideRect . offsetMin = new Vector2 ( 15f , 30f ) ;
129
+ handleSlideRect . offsetMax = new Vector2 ( - 15f , 0f ) ;
130
+ handleSlideRect . sizeDelta = new Vector2 ( - 30f , - 30f ) ;
131
+
132
+ Image handleImage = handleObj . AddComponent < Image > ( ) ;
133
+ handleImage . color = new Color ( 0.5f , 0.5f , 0.5f , 1.0f ) ;
134
+
135
+ var handleRect = handleObj . GetComponent < RectTransform > ( ) ;
136
+ handleRect . sizeDelta = new Vector2 ( 15f , 30f ) ;
137
+ handleRect . offsetMin = new Vector2 ( - 13f , - 28f ) ;
138
+ handleRect . offsetMax = new Vector2 ( 3f , - 2f ) ;
139
+
140
+ var sliderBarLayout = sliderObj . AddComponent < LayoutElement > ( ) ;
141
+ sliderBarLayout . minWidth = 25 ;
142
+ sliderBarLayout . flexibleWidth = 0 ;
143
+ sliderBarLayout . minHeight = 30 ;
144
+ sliderBarLayout . flexibleHeight = 5000 ;
145
+
146
+ slider = sliderObj . AddComponent < Slider > ( ) ;
147
+ slider . fillRect = fillObj . GetComponent < RectTransform > ( ) ;
148
+ slider . handleRect = handleObj . GetComponent < RectTransform > ( ) ;
149
+ slider . targetGraphic = handleImage ;
150
+ slider . direction = Slider . Direction . BottomToTop ;
151
+ UIFactory . SetDefaultColorTransitionValues ( slider ) ;
152
+
153
+ return sliderObj ;
154
+ }
151
155
152
- #endregion
153
- }
156
+ #endregion
157
+ }
154
158
155
159
#if MONO
156
160
public static class SliderExtensions
@@ -175,4 +179,5 @@ public static void Set(this Slider slider, float value, bool invokeCallback)
175
179
SetMethod . Invoke ( slider , new object [ ] { value , invokeCallback } ) ;
176
180
}
177
181
}
178
- #endif
182
+ #endif
183
+ }
0 commit comments