Skip to content

Commit c749bc7

Browse files
committed
feat: Use tmp dropdown instead
1 parent edb7439 commit c749bc7

File tree

9 files changed

+3093
-13
lines changed

9 files changed

+3093
-13
lines changed

Assets/JCSUnity/Scripts/UI/Dropdown.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using UnityEngine;
2+
using TMPro;
3+
4+
namespace JCSUnity
5+
{
6+
/// <summary>
7+
/// A dropdown menu let you choose the screen resolution.
8+
/// </summary>
9+
[RequireComponent(typeof(TMP_Dropdown))]
10+
public class JCS_DropdownScreenResolutions : MonoBehaviour
11+
{
12+
/* Variables */
13+
14+
/* Setter & Getter */
15+
16+
/* Functions */
17+
18+
}
19+
}

Assets/JCSUnity/Scripts/UI/Dropdown/JCS_DropdownScreenResolutions.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/JCSUnity/Scripts/UI/JCS_Dropdown.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
using UnityEngine;
1111
using UnityEngine.UI;
1212
using MyBox;
13+
using TMPro;
1314

1415
namespace JCSUnity
1516
{
1617
/// <summary>
1718
/// A better version of dropdown handle for uGUI.
1819
/// </summary>
19-
[RequireComponent(typeof(Dropdown))]
20+
[RequireComponent(typeof(TMP_Dropdown))]
2021
public class JCS_Dropdown : MonoBehaviour
2122
{
2223
/* Variables */
2324

24-
private Dropdown mDropdown = null;
25+
private TMP_Dropdown mDropdown = null;
2526

2627
#if UNITY_EDITOR
2728
[Separator("Helper Variables (JCS_Dropdown)")]
@@ -63,18 +64,17 @@ [SerializeField] [Range(1, 5)]
6364

6465
/* Setter & Getter */
6566

66-
public Dropdown dropdown { get { return this.mDropdown; } }
67+
public TMP_Dropdown dropdown { get { return this.mDropdown; } }
6768
public int MaxLetters { get { return this.mMaxLetters; } set { this.mMaxLetters = value; } }
6869
public int DotCount { get { return this.mDotCount; } set { this.mDotCount = value; } }
6970
public List<string> DropdownRealTexts { get { return this.mDropdownRealTexts; } }
7071
public List<string> DropdownBackupTexts { get { return this.mDropdownBackupTexts; } }
7172

72-
7373
/* Functions */
7474

7575
private void Awake()
7676
{
77-
this.mDropdown = this.GetComponent<Dropdown>();
77+
this.mDropdown = this.GetComponent<TMP_Dropdown>();
7878
}
7979

8080
#if UNITY_EDITOR
@@ -102,6 +102,7 @@ public void UpdateDropdownData()
102102
mDropdownRealTexts.Clear();
103103

104104
int centerLetterPos = mMaxLetters / 2;
105+
105106
if (JCS_Mathf.IsOdd(mMaxLetters))
106107
centerLetterPos += 1;
107108

@@ -119,7 +120,7 @@ public void UpdateDropdownData()
119120

120121
int index = -1;
121122

122-
foreach (Dropdown.OptionData od in mDropdown.options)
123+
foreach (TMP_Dropdown.OptionData od in mDropdown.options)
123124
{
124125
++index;
125126

Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static void SetText(TMP_Text txt, string data)
157157
/// <param name="dd"> Dropdown object. </param>
158158
/// <param name="index"> item name. </param>
159159
/// <returns> Current selected text value. </returns>
160-
public static string Dropdown_GetItemValue(Dropdown dd, int index)
160+
public static string Dropdown_GetItemValue(TMP_Dropdown dd, int index)
161161
{
162162
return dd.options[index].text;
163163
}
@@ -167,7 +167,7 @@ public static string Dropdown_GetItemValue(Dropdown dd, int index)
167167
/// </summary>
168168
/// <param name="dd"> drop down object. </param>
169169
/// <returns> Current selected text value. </returns>
170-
public static string Dropdown_GetSelectedValue(Dropdown dd)
170+
public static string Dropdown_GetSelectedValue(TMP_Dropdown dd)
171171
{
172172
return Dropdown_GetItemValue(dd, dd.value);
173173
}
@@ -182,7 +182,7 @@ public static string Dropdown_GetSelectedValue(Dropdown dd)
182182
/// Index of the item value found.
183183
/// If not found, will returns -1.
184184
/// </returns>
185-
public static int Dropdown_GetItemIndex(Dropdown dd, string itemName)
185+
public static int Dropdown_GetItemIndex(TMP_Dropdown dd, string itemName)
186186
{
187187
for (int index = 0; index < dd.options.Count; ++index)
188188
{
@@ -202,7 +202,7 @@ public static int Dropdown_GetItemIndex(Dropdown dd, string itemName)
202202
/// true : found the item and set it succesfully.
203203
/// false : did not find the item, failed to set.
204204
/// </returns>
205-
public static bool Dropdown_SetSelection(Dropdown dd, string itemName)
205+
public static bool Dropdown_SetSelection(TMP_Dropdown dd, string itemName)
206206
{
207207
int index = Dropdown_GetItemIndex(dd, itemName);
208208

@@ -220,7 +220,7 @@ public static bool Dropdown_SetSelection(Dropdown dd, string itemName)
220220
/// </summary>
221221
/// <param name="dd"> dropdown object. </param>
222222
/// <param name="selection"> selection id. </param>
223-
public static void Dropdown_SetSelection(Dropdown dd, int selection)
223+
public static void Dropdown_SetSelection(TMP_Dropdown dd, int selection)
224224
{
225225
dd.value = selection;
226226
}
@@ -229,7 +229,7 @@ public static void Dropdown_SetSelection(Dropdown dd, int selection)
229229
/// Refresh the current selection.
230230
/// </summary>
231231
/// <param name="dd"> dropdown object. </param>
232-
public static void Dropdown_RefreshSelection(Dropdown dd)
232+
public static void Dropdown_RefreshSelection(TMP_Dropdown dd)
233233
{
234234
int currentSelectionId = dd.value;
235235

@@ -341,7 +341,7 @@ public static bool Dropdown_SetSelection(JCS_Dropdown dd, string itemName)
341341
public static JCS_Dropdown Dropdown_AddOption(JCS_Dropdown dd, string inText)
342342
{
343343
dd.dropdown.options.Add(
344-
new Dropdown.OptionData() { text = inText });
344+
new TMP_Dropdown.OptionData() { text = inText });
345345

346346
return dd;
347347
}

0 commit comments

Comments
 (0)