net.dreditor.ui.menus 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,260 +1,260 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using System;
3
- using System.Collections;
4
- using TMPro;
5
- using UnityEngine;
6
- using UnityEngine.InputSystem;
7
-
8
- namespace DREditor.UI.Menus
9
- {
10
- /// <summary>
11
- ///
12
- /// </summary>
13
- [ClassHeader("")]
14
- public class ScrollDescription : MonoBehaviour
15
- {
16
- /// <summary>
17
- ///
18
- /// </summary>
19
- [Tooltip("")]
20
- [SerializeField] protected InputActionReference navigate = null;
21
-
22
-
23
- /// <summary>
24
- ///
25
- /// </summary>
26
- [Header("")]
27
- [Divider]
28
- [Tooltip("")]
29
- [SerializeField] protected RectTransform maskBox = null;
30
-
31
- /// <summary>
32
- ///
33
- /// </summary>
34
- [Tooltip("")]
35
- [SerializeField] protected RectTransform controlBox = null;
36
-
37
- /// <summary>
38
- ///
39
- /// </summary>
40
- [Tooltip("")]
41
- [SerializeField] protected TMP_Text textBox = null;
42
-
43
-
44
- /// <summary>
45
- ///
46
- /// </summary>
47
- [Header("")]
48
- [Divider]
49
- [Tooltip("")]
50
- [SerializeField] protected ScrollDirection inputDirection = ScrollDirection.Horizontal;
51
-
52
- /// <summary>
53
- ///
54
- /// </summary>
55
- [Tooltip("")]
56
- [SerializeField] protected ScrollDirection scrollUIDirection = ScrollDirection.Vertical;
57
-
58
- /// <summary>
59
- ///
60
- /// </summary>
61
- [Space]
62
-
63
- [Tooltip("")]
64
- [SerializeField] protected float scrollValue = 5f;
65
-
66
- /// <summary>
67
- ///
68
- /// </summary>
69
- [Space]
70
-
71
- [Tooltip("")]
72
- [SerializeField] protected GameObject scrollControlUI = null;
73
-
74
-
75
- /// <summary>
76
- ///
77
- /// </summary>
78
- protected Canvas canvas = null;
79
-
80
- /// <summary>
81
- ///
82
- /// </summary>
83
- protected bool textGreaterThanMaskBounds = false;
84
-
85
- /// <summary>
86
- ///
87
- /// </summary>
88
- protected Vector2 stickDirection = Vector2.zero;
89
-
90
-
91
- /// <summary>
92
- ///
93
- /// </summary>
94
- protected virtual void OnEnable() => textBox.OnPreRenderText += CheckScrollableOnTextChange;
95
-
96
- /// <summary>
97
- ///
98
- /// </summary>
99
- protected virtual void OnDisable() => textBox.OnPreRenderText -= CheckScrollableOnTextChange;
100
-
101
- /// <summary>
102
- ///
103
- /// </summary>
104
- protected virtual void Start() => canvas = GetComponentInParent<Canvas>();
105
-
106
- /// <summary>
107
- ///
108
- /// </summary>
109
- protected virtual void Update() => CheckScrollInput();
110
-
111
-
112
- /// <summary>
113
- ///
114
- /// </summary>
115
- protected virtual void CheckScrollInput()
116
- {
117
- if (EvaluateScrollUI())
118
- ScrollUI();
119
- }
120
-
121
- /// <summary>
122
- ///
123
- /// </summary>
124
- /// <returns></returns>
125
- protected virtual bool EvaluateScrollUI()
126
- {
127
- if (!canvas.enabled)
128
- textGreaterThanMaskBounds = false;
129
-
130
- if (!textGreaterThanMaskBounds || !navigate.action.IsPressed())
131
- return false;
132
-
133
- stickDirection = navigate.action.ReadValue<Vector2>();
134
-
135
- bool isInputDirection = InputAxisValue(stickDirection) != 0;
136
-
137
- bool notDiagonal = InverseAxisValue(stickDirection, inputDirection) == 0;
138
-
139
- return textGreaterThanMaskBounds && isInputDirection && notDiagonal;
140
- }
141
-
142
- /// <summary>
143
- ///
144
- /// </summary>
145
- protected virtual void ScrollUI()
146
- {
147
- if (InputAxisValue(stickDirection) > 0 && OnTopMaskEdge())
148
- ScrollTextBoxUI(scrollValue);// Move Up/Right
149
-
150
- if (InputAxisValue(stickDirection) < 0 && OnBottomMaskEdge())
151
- ScrollTextBoxUI(scrollValue * -1);// Move Down/Left
152
- }
153
-
154
- /// <summary>
155
- ///
156
- /// </summary>
157
- /// <returns></returns>
158
- protected virtual bool OnTopMaskEdge()
159
- => !(SubtractMovePositionSize(textBox.rectTransform) + scrollValue >= SubtractMovePositionSize(maskBox));
160
-
161
- /// <summary>
162
- ///
163
- /// </summary>
164
- /// <returns></returns>
165
- protected virtual bool OnBottomMaskEdge()
166
- => !(ScrollAxisValue(textBox.rectTransform.position) - scrollValue <= ScrollAxisValue(maskBox.position));
167
-
168
- /// <summary>
169
- ///
170
- /// </summary>
171
- /// <param name="moveBoxAmount"></param>
172
- protected virtual void ScrollTextBoxUI(float moveBoxAmount)
173
- {
174
- var xPos = scrollUIDirection == ScrollDirection.Horizontal ? controlBox.position.x + moveBoxAmount : controlBox.position.x;
175
-
176
- var yPos = scrollUIDirection == ScrollDirection.Vertical ? controlBox.position.y + moveBoxAmount : controlBox.position.y;
177
-
178
- controlBox.position = new Vector3(xPos, yPos, 0);
179
- }
180
-
181
- /// <summary>
182
- ///
183
- /// </summary>
184
- /// <param name="textInfo"></param>
185
- protected virtual void CheckScrollableOnTextChange(TMP_TextInfo textInfo)
186
- {
187
- controlBox.position = maskBox.position;
188
-
189
- textGreaterThanMaskBounds = ScrollAxisValue(textBox.rectTransform.sizeDelta) > ScrollAxisValue(maskBox.sizeDelta);
190
-
191
- StartCoroutine(BufferScrollControlsActive());
192
- }
193
-
194
- /// <summary>
195
- ///
196
- /// </summary>
197
- /// <returns></returns>
198
- /// <remarks></remarks>
199
- protected virtual IEnumerator BufferScrollControlsActive()
200
- {
201
- yield return new WaitForEndOfFrame();
202
-
203
- yield return null;
204
-
205
- if (scrollControlUI != null)
206
- scrollControlUI.SetActive(textGreaterThanMaskBounds);
207
-
208
- yield break;
209
- }
210
-
211
- /// <summary>
212
- ///
213
- /// </summary>
214
- /// <param name="dir"></param>
215
- /// <returns></returns>
216
- protected virtual float InputAxisValue(Vector2 dir) => AxisValue(dir, inputDirection);
217
-
218
- /// <summary>
219
- ///
220
- /// </summary>
221
- /// <param name="dir"></param>
222
- /// <returns></returns>
223
- protected virtual float ScrollAxisValue(Vector2 dir) => AxisValue(dir, scrollUIDirection);
224
-
225
- /// <summary>
226
- ///
227
- /// </summary>
228
- /// <param name="dir"></param>
229
- /// <param name="direction"></param>
230
- /// <returns></returns>
231
- protected float AxisValue(Vector2 dir, ScrollDirection direction)
232
- => direction == ScrollDirection.Horizontal ? dir.x : dir.y;
233
-
234
- /// <summary>
235
- ///
236
- /// </summary>
237
- /// <param name="dir"></param>
238
- /// <param name="direction"></param>
239
- /// <returns></returns>
240
- protected float InverseAxisValue(Vector2 dir, ScrollDirection direction)
241
- => direction == ScrollDirection.Horizontal ? dir.y : dir.x;
242
-
243
- /// <summary>
244
- ///
245
- /// </summary>
246
- /// <param name="box"></param>
247
- /// <returns></returns>
248
- protected float SubtractMovePositionSize(RectTransform box) => ScrollAxisValue(box.position) - ScrollAxisValue(box.sizeDelta);
249
- }
250
-
251
- /// <summary>
252
- ///
253
- /// </summary>
254
- /// <remarks></remarks>
255
- [Serializable]
256
- public enum ScrollDirection
257
- {
258
- Horizontal, Vertical
259
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using System;
3
+ using System.Collections;
4
+ using TMPro;
5
+ using UnityEngine;
6
+ using UnityEngine.InputSystem;
7
+
8
+ namespace DREditor.UI.Menus
9
+ {
10
+ /// <summary>
11
+ ///
12
+ /// </summary>
13
+ [ClassHeader("")]
14
+ public class ScrollDescription : MonoBehaviour
15
+ {
16
+ /// <summary>
17
+ ///
18
+ /// </summary>
19
+ [Tooltip("")]
20
+ [SerializeField] protected InputActionReference navigate = null;
21
+
22
+
23
+ /// <summary>
24
+ ///
25
+ /// </summary>
26
+ [Header("")]
27
+ [Divider]
28
+ [Tooltip("")]
29
+ [SerializeField] protected RectTransform maskBox = null;
30
+
31
+ /// <summary>
32
+ ///
33
+ /// </summary>
34
+ [Tooltip("")]
35
+ [SerializeField] protected RectTransform controlBox = null;
36
+
37
+ /// <summary>
38
+ ///
39
+ /// </summary>
40
+ [Tooltip("")]
41
+ [SerializeField] protected TMP_Text textBox = null;
42
+
43
+
44
+ /// <summary>
45
+ ///
46
+ /// </summary>
47
+ [Header("")]
48
+ [Divider]
49
+ [Tooltip("")]
50
+ [SerializeField] protected ScrollDirection inputDirection = ScrollDirection.Horizontal;
51
+
52
+ /// <summary>
53
+ ///
54
+ /// </summary>
55
+ [Tooltip("")]
56
+ [SerializeField] protected ScrollDirection scrollUIDirection = ScrollDirection.Vertical;
57
+
58
+ /// <summary>
59
+ ///
60
+ /// </summary>
61
+ [Space]
62
+
63
+ [Tooltip("")]
64
+ [SerializeField] protected float scrollValue = 5f;
65
+
66
+ /// <summary>
67
+ ///
68
+ /// </summary>
69
+ [Space]
70
+
71
+ [Tooltip("")]
72
+ [SerializeField] protected GameObject scrollControlUI = null;
73
+
74
+
75
+ /// <summary>
76
+ ///
77
+ /// </summary>
78
+ protected Canvas canvas = null;
79
+
80
+ /// <summary>
81
+ ///
82
+ /// </summary>
83
+ protected bool textGreaterThanMaskBounds = false;
84
+
85
+ /// <summary>
86
+ ///
87
+ /// </summary>
88
+ protected Vector2 stickDirection = Vector2.zero;
89
+
90
+
91
+ /// <summary>
92
+ ///
93
+ /// </summary>
94
+ protected virtual void OnEnable() => textBox.OnPreRenderText += CheckScrollableOnTextChange;
95
+
96
+ /// <summary>
97
+ ///
98
+ /// </summary>
99
+ protected virtual void OnDisable() => textBox.OnPreRenderText -= CheckScrollableOnTextChange;
100
+
101
+ /// <summary>
102
+ ///
103
+ /// </summary>
104
+ protected virtual void Start() => canvas = GetComponentInParent<Canvas>();
105
+
106
+ /// <summary>
107
+ ///
108
+ /// </summary>
109
+ protected virtual void Update() => CheckScrollInput();
110
+
111
+
112
+ /// <summary>
113
+ ///
114
+ /// </summary>
115
+ protected virtual void CheckScrollInput()
116
+ {
117
+ if (EvaluateScrollUI())
118
+ ScrollUI();
119
+ }
120
+
121
+ /// <summary>
122
+ ///
123
+ /// </summary>
124
+ /// <returns></returns>
125
+ protected virtual bool EvaluateScrollUI()
126
+ {
127
+ if (!canvas.enabled)
128
+ textGreaterThanMaskBounds = false;
129
+
130
+ if (!textGreaterThanMaskBounds || !navigate.action.IsPressed())
131
+ return false;
132
+
133
+ stickDirection = navigate.action.ReadValue<Vector2>();
134
+
135
+ bool isInputDirection = InputAxisValue(stickDirection) != 0;
136
+
137
+ bool notDiagonal = InverseAxisValue(stickDirection, inputDirection) == 0;
138
+
139
+ return textGreaterThanMaskBounds && isInputDirection && notDiagonal;
140
+ }
141
+
142
+ /// <summary>
143
+ ///
144
+ /// </summary>
145
+ protected virtual void ScrollUI()
146
+ {
147
+ if (InputAxisValue(stickDirection) > 0 && OnTopMaskEdge())
148
+ ScrollTextBoxUI(scrollValue);// Move Up/Right
149
+
150
+ if (InputAxisValue(stickDirection) < 0 && OnBottomMaskEdge())
151
+ ScrollTextBoxUI(scrollValue * -1);// Move Down/Left
152
+ }
153
+
154
+ /// <summary>
155
+ ///
156
+ /// </summary>
157
+ /// <returns></returns>
158
+ protected virtual bool OnTopMaskEdge()
159
+ => !(SubtractMovePositionSize(textBox.rectTransform) + scrollValue >= SubtractMovePositionSize(maskBox));
160
+
161
+ /// <summary>
162
+ ///
163
+ /// </summary>
164
+ /// <returns></returns>
165
+ protected virtual bool OnBottomMaskEdge()
166
+ => !(ScrollAxisValue(textBox.rectTransform.position) - scrollValue <= ScrollAxisValue(maskBox.position));
167
+
168
+ /// <summary>
169
+ ///
170
+ /// </summary>
171
+ /// <param name="moveBoxAmount"></param>
172
+ protected virtual void ScrollTextBoxUI(float moveBoxAmount)
173
+ {
174
+ var xPos = scrollUIDirection == ScrollDirection.Horizontal ? controlBox.position.x + moveBoxAmount : controlBox.position.x;
175
+
176
+ var yPos = scrollUIDirection == ScrollDirection.Vertical ? controlBox.position.y + moveBoxAmount : controlBox.position.y;
177
+
178
+ controlBox.position = new Vector3(xPos, yPos, 0);
179
+ }
180
+
181
+ /// <summary>
182
+ ///
183
+ /// </summary>
184
+ /// <param name="textInfo"></param>
185
+ protected virtual void CheckScrollableOnTextChange(TMP_TextInfo textInfo)
186
+ {
187
+ controlBox.position = maskBox.position;
188
+
189
+ textGreaterThanMaskBounds = ScrollAxisValue(textBox.rectTransform.sizeDelta) > ScrollAxisValue(maskBox.sizeDelta);
190
+
191
+ StartCoroutine(BufferScrollControlsActive());
192
+ }
193
+
194
+ /// <summary>
195
+ ///
196
+ /// </summary>
197
+ /// <returns></returns>
198
+ /// <remarks></remarks>
199
+ protected virtual IEnumerator BufferScrollControlsActive()
200
+ {
201
+ yield return new WaitForEndOfFrame();
202
+
203
+ yield return null;
204
+
205
+ if (scrollControlUI != null)
206
+ scrollControlUI.SetActive(textGreaterThanMaskBounds);
207
+
208
+ yield break;
209
+ }
210
+
211
+ /// <summary>
212
+ ///
213
+ /// </summary>
214
+ /// <param name="dir"></param>
215
+ /// <returns></returns>
216
+ protected virtual float InputAxisValue(Vector2 dir) => AxisValue(dir, inputDirection);
217
+
218
+ /// <summary>
219
+ ///
220
+ /// </summary>
221
+ /// <param name="dir"></param>
222
+ /// <returns></returns>
223
+ protected virtual float ScrollAxisValue(Vector2 dir) => AxisValue(dir, scrollUIDirection);
224
+
225
+ /// <summary>
226
+ ///
227
+ /// </summary>
228
+ /// <param name="dir"></param>
229
+ /// <param name="direction"></param>
230
+ /// <returns></returns>
231
+ protected float AxisValue(Vector2 dir, ScrollDirection direction)
232
+ => direction == ScrollDirection.Horizontal ? dir.x : dir.y;
233
+
234
+ /// <summary>
235
+ ///
236
+ /// </summary>
237
+ /// <param name="dir"></param>
238
+ /// <param name="direction"></param>
239
+ /// <returns></returns>
240
+ protected float InverseAxisValue(Vector2 dir, ScrollDirection direction)
241
+ => direction == ScrollDirection.Horizontal ? dir.y : dir.x;
242
+
243
+ /// <summary>
244
+ ///
245
+ /// </summary>
246
+ /// <param name="box"></param>
247
+ /// <returns></returns>
248
+ protected float SubtractMovePositionSize(RectTransform box) => ScrollAxisValue(box.position) - ScrollAxisValue(box.sizeDelta);
249
+ }
250
+
251
+ /// <summary>
252
+ ///
253
+ /// </summary>
254
+ /// <remarks></remarks>
255
+ [Serializable]
256
+ public enum ScrollDirection
257
+ {
258
+ Horizontal, Vertical
259
+ }
260
260
  }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 15dc8e89cf461dc459972ace81e69b9a
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 15dc8e89cf461dc459972ace81e69b9a
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: