Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit f1f3f8f

Browse files
Update release from development
2 parents 8462536 + 383e19f commit f1f3f8f

16 files changed

+526
-300
lines changed

Editor/UIExtensionsMenuOptions.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ static public void AddAutoCompleteComboBox(MenuCommand menuCommand)
806806
//Setup Template
807807
itemTemplate.name = "ItemTemplate";
808808
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
809-
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
809+
itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10,0);
810+
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
810811
var itemTemplateButton = itemTemplate.GetComponent<Button>();
811812
itemTemplateButton.transition = Selectable.Transition.None;
812813
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
@@ -902,7 +903,8 @@ static public void AddComboBox(MenuCommand menuCommand)
902903
//Setup Template
903904
itemTemplate.name = "ItemTemplate";
904905
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
905-
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
906+
itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0);
907+
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
906908
var itemTemplateButton = itemTemplate.GetComponent<Button>();
907909
itemTemplateButton.transition = Selectable.Transition.None;
908910
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
@@ -1002,7 +1004,8 @@ static public void AddDropDownList(MenuCommand menuCommand)
10021004
//Setup Template
10031005
itemTemplate.name = "ItemTemplate";
10041006
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
1005-
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
1007+
itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0);
1008+
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
10061009
var itemTemplateButton = itemTemplate.GetComponent<Button>();
10071010
itemTemplateButton.transition = Selectable.Transition.None;
10081011
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();

Runtime/Scripts/Controls/Accordion/AccordionElement.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ protected override void OnValidate()
6262
}
6363

6464
LayoutElement le = this.gameObject.GetComponent<LayoutElement>();
65-
66-
if (le != null)
65+
66+
if (le != null && m_Accordion != null)
6767
{
6868
if (this.isOn)
6969
{
@@ -98,8 +98,8 @@ public void OnValueChanged(bool state)
9898
return;
9999

100100
Accordion.Transition transition = (this.m_Accordion != null) ? this.m_Accordion.transition : Accordion.Transition.Instant;
101-
102-
if (transition == Accordion.Transition.Instant)
101+
102+
if (transition == Accordion.Transition.Instant && m_Accordion != null)
103103
{
104104
if (state)
105105
{

Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class AutoCompleteComboBox : MonoBehaviour
1919
public Color disabledTextColor;
2020
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
2121

22+
/// <summary>
23+
/// Contains the included items. To add and remove items to/from this list, use the <see cref="AddItem(string)"/>,
24+
/// <see cref="RemoveItem(string)"/> and <see cref="SetAvailableOptions(List{string})"/> methods as these also execute
25+
/// the required methods to update to the current collection.
26+
/// </summary>
2227
public List<string> AvailableOptions;
2328

2429
//private bool isInitialized = false;
@@ -36,7 +41,7 @@ public class AutoCompleteComboBox : MonoBehaviour
3641
private RectTransform _scrollPanelRT;
3742
private RectTransform _scrollBarRT;
3843
private RectTransform _slidingAreaRT;
39-
// private RectTransform scrollHandleRT;
44+
private RectTransform _scrollHandleRT;
4045
private RectTransform _itemsPanelRT;
4146
private Canvas _canvas;
4247
private RectTransform _canvasRT;
@@ -104,6 +109,9 @@ public bool InputColorMatching{
104109

105110
public AutoCompleteSearchType autocompleteSearchType = AutoCompleteSearchType.Linq;
106111

112+
[SerializeField]
113+
private bool _displayPanelAbove = false;
114+
107115
private bool _selectionIsValid = false;
108116

109117
[System.Serializable]
@@ -129,13 +137,15 @@ public void Awake()
129137
{
130138
Initialize();
131139
}
140+
132141
public void Start()
133142
{
134143
if (SelectFirstItemOnStart && AvailableOptions.Count > 0) {
135144
ToggleDropdownPanel (false);
136145
OnItemClicked (AvailableOptions [0]);
137146
}
138-
}
147+
RedrawPanel();
148+
}
139149

140150
private bool Initialize()
141151
{
@@ -155,7 +165,7 @@ private bool Initialize()
155165
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
156166
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
157167
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
158-
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
168+
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
159169
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
160170
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
161171

@@ -182,39 +192,75 @@ private bool Initialize()
182192
_panelItems = new List<string>();
183193

184194
RebuildPanel();
185-
//RedrawPanel(); - causes an initialisation failure in U5
186195
return success;
187196
}
188197

198+
/// <summary>
199+
/// Adds the item to <see cref="this.AvailableOptions"/> if it is not a duplicate and rebuilds the panel.
200+
/// </summary>
201+
/// <param name="item">Item to add.</param>
189202
public void AddItem(string item)
190203
{
191-
AvailableOptions.Add(item);
192-
RebuildPanel();
204+
if (!this.AvailableOptions.Contains(item))
205+
{
206+
this.AvailableOptions.Add(item);
207+
this.RebuildPanel();
208+
}
209+
else
210+
{
211+
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(AddItem)}: items may only exists once. '{item}' can not be added.");
212+
}
193213
}
194214

215+
/// <summary>
216+
/// Removes the item from <see cref="this.AvailableOptions"/> and rebuilds the panel.
217+
/// </summary>
218+
/// <param name="item">Item to remove.</param>
195219
public void RemoveItem(string item)
196220
{
197-
AvailableOptions.Remove(item);
198-
RebuildPanel();
221+
if (this.AvailableOptions.Contains(item))
222+
{
223+
this.AvailableOptions.Remove(item);
224+
this.RebuildPanel();
225+
}
199226
}
200227

228+
/// <summary>
229+
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
230+
/// </summary>
231+
/// <param name="newOptions">New entries.</param>
201232
public void SetAvailableOptions(List<string> newOptions)
202233
{
203-
AvailableOptions.Clear();
204-
AvailableOptions = newOptions;
205-
RebuildPanel();
234+
var uniqueOptions = newOptions.Distinct().ToList();
235+
if (newOptions.Count != uniqueOptions.Count)
236+
{
237+
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Count - uniqueOptions.Count} duplicates.");
238+
}
239+
240+
this.AvailableOptions.Clear();
241+
this.AvailableOptions = uniqueOptions;
242+
this.RebuildPanel();
206243
}
207244

245+
/// <summary>
246+
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
247+
/// </summary>
248+
/// <param name="newOptions">New entries.</param>
208249
public void SetAvailableOptions(string[] newOptions)
209250
{
210-
AvailableOptions.Clear();
251+
var uniqueOptions = newOptions.Distinct().ToList();
252+
if (newOptions.Length != uniqueOptions.Count)
253+
{
254+
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Length - uniqueOptions.Count} duplicates.");
255+
}
211256

257+
this.AvailableOptions.Clear();
212258
for (int i = 0; i < newOptions.Length; i++)
213259
{
214-
AvailableOptions.Add(newOptions[i]);
260+
this.AvailableOptions.Add(newOptions[i]);
215261
}
216262

217-
RebuildPanel();
263+
this.RebuildPanel();
218264
}
219265

220266
public void ResetItems()
@@ -264,7 +310,7 @@ private void RebuildPanel()
264310
if (i < AvailableOptions.Count)
265311
{
266312
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
267-
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value
313+
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
268314

269315
Button itemBtn = itemObjs[i].GetComponent<Button>();
270316
itemBtn.onClick.RemoveAllListeners();
@@ -331,7 +377,9 @@ private void RedrawPanel()
331377
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
332378

333379
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
334-
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
380+
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
381+
new Vector2(0, DropdownOffset + _rectTransform.sizeDelta.y * _panelItems.Count - 1) :
382+
new Vector2(0, -_rectTransform.sizeDelta.y);
335383

336384
//make the overlay fill the screen
337385
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@@ -354,6 +402,7 @@ private void RedrawPanel()
354402

355403
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
356404
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
405+
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
357406

358407
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
359408
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

Runtime/Scripts/Controls/ComboBox/ComboBox.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public class ComboBox : MonoBehaviour
2121
[SerializeField]
2222
private int _itemsToDisplay;
2323

24+
//Sorting disabled as it causes issues.
25+
//[SerializeField]
26+
//private bool _sortItems = true;
27+
2428
[SerializeField]
25-
private bool _sortItems = true;
29+
private bool _displayPanelAbove = false;
2630

2731
[System.Serializable]
2832
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string>
@@ -45,7 +49,7 @@ public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string>
4549
private RectTransform _scrollPanelRT;
4650
private RectTransform _scrollBarRT;
4751
private RectTransform _slidingAreaRT;
48-
// private RectTransform scrollHandleRT;
52+
private RectTransform _scrollHandleRT;
4953
private RectTransform _itemsPanelRT;
5054
private Canvas _canvas;
5155
private RectTransform _canvasRT;
@@ -88,6 +92,11 @@ public void Awake()
8892
Initialize();
8993
}
9094

95+
public void Start()
96+
{
97+
RedrawPanel();
98+
}
99+
91100
private bool Initialize()
92101
{
93102
bool success = true;
@@ -104,7 +113,7 @@ private bool Initialize()
104113
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
105114
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
106115
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
107-
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
116+
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
108117
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
109118
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
110119

@@ -181,7 +190,7 @@ private void RebuildPanel()
181190
{
182191
_panelItems.Add(option.ToLower());
183192
}
184-
if(_sortItems) _panelItems.Sort();
193+
//if(_sortItems) _panelItems.Sort();
185194

186195
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
187196
panelObjects.Clear();
@@ -202,7 +211,7 @@ private void RebuildPanel()
202211
if (i < AvailableOptions.Count)
203212
{
204213
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
205-
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value
214+
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
206215

207216
Button itemBtn = itemObjs[i].GetComponent<Button>();
208217
itemBtn.onClick.RemoveAllListeners();
@@ -268,7 +277,9 @@ private void RedrawPanel()
268277
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
269278

270279
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
271-
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
280+
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
281+
new Vector2(0, _rectTransform.sizeDelta.y * ItemsToDisplay - 1) :
282+
new Vector2(0, -_rectTransform.sizeDelta.y);
272283

273284
//make the overlay fill the screen
274285
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@@ -291,6 +302,7 @@ private void RedrawPanel()
291302

292303
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
293304
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
305+
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
294306

295307
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
296308
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

Runtime/Scripts/Controls/ComboBox/DropDownList.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DropDownList : MonoBehaviour
3131
private RectTransform _scrollPanelRT;
3232
private RectTransform _scrollBarRT;
3333
private RectTransform _slidingAreaRT;
34-
// private RectTransform scrollHandleRT;
34+
private RectTransform _scrollHandleRT;
3535
private RectTransform _itemsPanelRT;
3636
private Canvas _canvas;
3737
private RectTransform _canvasRT;
@@ -57,7 +57,6 @@ public float ScrollBarWidth
5757
// private int scrollOffset; //offset of the selected item
5858
private int _selectedIndex = -1;
5959

60-
6160
[SerializeField]
6261
private int _itemsToDisplay;
6362
public int ItemsToDisplay
@@ -72,6 +71,9 @@ public int ItemsToDisplay
7271

7372
public bool SelectFirstItemOnStart = false;
7473

74+
[SerializeField]
75+
private bool _displayPanelAbove = false;
76+
7577
[System.Serializable]
7678
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<int> {
7779
}
@@ -86,6 +88,7 @@ public void Start()
8688
ToggleDropdownPanel (false);
8789
OnItemClicked (0);
8890
}
91+
RedrawPanel();
8992
}
9093

9194
private bool Initialize()
@@ -103,7 +106,7 @@ private bool Initialize()
103106
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
104107
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
105108
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
106-
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
109+
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
107110
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
108111
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
109112

@@ -332,7 +335,9 @@ private void RedrawPanel()
332335
_mainButton.txt.rectTransform.offsetMax = new Vector2(4, 0);
333336

334337
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
335-
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
338+
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
339+
new Vector2(0, _rectTransform.sizeDelta.y * ItemsToDisplay - 1) :
340+
new Vector2(0, -_rectTransform.sizeDelta.y);
336341

337342
//make the overlay fill the screen
338343
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@@ -355,6 +360,7 @@ private void RedrawPanel()
355360

356361
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
357362
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
363+
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
358364

359365
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
360366
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

Runtime/Scripts/Controls/RangeSlider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,10 @@ public override void OnPointerDown(PointerEventData eventData)
563563
{
564564
//outside the handles, move the entire slider along
565565
UpdateDrag(eventData, eventData.pressEventCamera);
566-
interactionState = InteractionState.Bar;
566+
if (eventData.pointerCurrentRaycast.gameObject == m_FillRect.gameObject)
567+
{
568+
interactionState = InteractionState.Bar;
569+
}
567570
if (transition == Transition.ColorTint)
568571
{
569572
targetGraphic = m_FillImage;
@@ -578,6 +581,7 @@ public virtual void OnDrag(PointerEventData eventData)
578581
{
579582
return;
580583
}
584+
581585
UpdateDrag(eventData, eventData.pressEventCamera);
582586
}
583587

Runtime/Scripts/Controls/SegmentedControl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public int selectedSegmentIndex
7373
value = Math.Max(value, -1);
7474
value = Math.Min(value, segments.Length - 1);
7575

76+
if (m_selectedSegmentIndex == value)
77+
{
78+
return;
79+
}
80+
7681
m_selectedSegmentIndex = value;
7782

7883
if (selectedSegment)

0 commit comments

Comments
 (0)