Skip to content

Commit eace475

Browse files
author
Bianca Marina Stana
committed
Cleaned up some code
# Conflicts: # Assets/Resources/UITk/MainView.uxml # Assets/Scripts/Controls/MultiSelectDropdown.cs # Assets/Scripts/Localization/LocalizedStringList.cs # Assets/Scripts/Screen Reader/AccessibilityManager.cs # Assets/Scripts/Screen Reader/AccessibilityService.cs # Assets/Scripts/Screen Reader/UGUI/UGuiAccessibilityService.cs # Assets/Scripts/UITk/Controls/StackView.cs
1 parent c407f0c commit eace475

File tree

7 files changed

+73
-70
lines changed

7 files changed

+73
-70
lines changed

Assets/Scripts/Controls/MultiSelectDropdown.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ protected override void Awake()
613613
{
614614
return;
615615
}
616-
#endif
616+
#endif // UNITY_EDITOR
617617

618618
if (m_CaptionImage)
619619
{
@@ -645,7 +645,7 @@ protected override void OnValidate()
645645

646646
RefreshShownValue();
647647
}
648-
#endif
648+
#endif // UNITY_EDITOR
649649

650650
protected override void OnDisable()
651651
{
@@ -1335,7 +1335,12 @@ void AlphaFadeList(float duration, float start, float end)
13351335
return;
13361336
}
13371337

1338-
var tween = new FloatTween {duration = duration, startValue = start, targetValue = end};
1338+
var tween = new FloatTween
1339+
{
1340+
duration = duration,
1341+
startValue = start,
1342+
targetValue = end
1343+
};
13391344
tween.AddOnChangedCallback(SetAlpha);
13401345
tween.ignoreTimeScale = true;
13411346
GetOrCreateAlphaTweenRunner().StartTween(tween);

Assets/Scripts/Localization/LocalizedStringList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected override BindingResult Update(in BindingContext context)
2222
{
2323
LocaleOverride = LocalizationSettings.ProjectLocale;
2424
}
25-
#endif
25+
#endif // UNITY_EDITOR
2626

2727
if (!CurrentLoadingOperationHandle.IsDone)
2828
{

Assets/Scripts/Screen Reader/AccessibilityManager.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ public class AccessibilityManager : MonoBehaviour
2727
/// </summary>
2828
AccessibilityHierarchy m_Hierarchy;
2929

30-
/// <summary>
31-
/// The instance of the AccessibilityManager in the scene.
32-
/// </summary>
33-
public static AccessibilityManager instance => s_Instance;
34-
3530
/// <summary>
3631
/// Tracks the previous screen orientation (portrait/landscape) to allow the layout to be recalculated on
3732
/// orientation changes. This is necessary for the calculated accessibility frames to be correct.
@@ -52,11 +47,6 @@ public static AccessibilityHierarchy hierarchy
5247
}
5348
}
5449

55-
/// <summary>
56-
/// Returns the list of registered accessibility services.
57-
/// </summary>
58-
public static IReadOnlyList<AccessibilityService> services => s_Instance?.m_RegisteredServices.AsReadOnly();
59-
6050
/// <summary>
6151
/// Event triggered when the hierarchy is refreshed to allow components to be able to execute actions when that
6252
/// happens (e.g. focusing the dropdown after it opens).

Assets/Scripts/Screen Reader/AccessibilityService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public abstract class AccessibilityService
1616
/// The priority of the service. Higher priority services will have their nodes added to the accessibility
1717
/// hierarchy first.
1818
/// </summary>
19-
public int servicePriority { get; protected set; }
19+
public int servicePriority { get; }
2020

2121
/// <summary>
2222
/// The name of the system
2323
/// </summary>
24-
public string serviceName { get; protected set; }
24+
public string serviceName { get; }
2525

2626
/// <summary>
2727
/// Constructor for the accessibility service.

Assets/Scripts/Screen Reader/UGUI/AccessibleToggle.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,32 @@ protected override void UnbindFromControl()
8282
{
8383
if (m_Toggle != null)
8484
{
85-
selected -= OnSelected;
86-
8785
m_Toggle.onValueChanged.RemoveListener(UpdateValue);
86+
87+
selected -= OnSelected;
8888
}
8989
}
9090

91-
bool OnSelected()
91+
bool IsInsideDropdown()
9292
{
93-
if (m_Toggle.IsActive() && m_Toggle.IsInteractable())
93+
var currentTransform = transform.parent;
94+
95+
// Traverse up the parent hierarchy.
96+
while (currentTransform != null)
9497
{
95-
m_Toggle.isOn = !m_Toggle.isOn;
96-
return true;
98+
// Check if the current parent has a dropdown component.
99+
if (currentTransform.GetComponent<MultiSelectDropdown>() != null ||
100+
currentTransform.GetComponent<TMP_Dropdown>() != null ||
101+
currentTransform.GetComponent<Dropdown>() != null)
102+
{
103+
return true; // Found the dropdown.
104+
}
105+
106+
// Move to the next parent.
107+
currentTransform = currentTransform.parent;
97108
}
98109

99-
return false;
110+
return false; // No dropdown found.
100111
}
101112

102113
void UpdateValue(bool newValue)
@@ -113,26 +124,15 @@ void UpdateValue(bool newValue)
113124
SetNodeProperties();
114125
}
115126

116-
bool IsInsideDropdown()
127+
bool OnSelected()
117128
{
118-
var currentTransform = transform.parent;
119-
120-
// Traverse up the parent hierarchy.
121-
while (currentTransform != null)
129+
if (m_Toggle.IsActive() && m_Toggle.IsInteractable())
122130
{
123-
// Check if the current parent has a dropdown component.
124-
if (currentTransform.GetComponent<MultiSelectDropdown>() != null ||
125-
currentTransform.GetComponent<TMP_Dropdown>() != null ||
126-
currentTransform.GetComponent<Dropdown>() != null)
127-
{
128-
return true; // Found the dropdown.
129-
}
130-
131-
// Move to the next parent.
132-
currentTransform = currentTransform.parent;
131+
m_Toggle.isOn = !m_Toggle.isOn;
132+
return true;
133133
}
134134

135-
return false; // No dropdown found.
135+
return false;
136136
}
137137
}
138138
}

Assets/Scripts/Screen Reader/UGUI/UGuiAccessibilityService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ struct HierarchyItem
3232
Dictionary<AccessibilityNode, AccessibleElement> m_ElementForNodeMap = new();
3333

3434
/// <summary>
35-
/// Tracks the previous screen orientation (portrait/landscape) to allow the layout to be recalculated on
36-
/// orientation changes. This is necessary for the calculated accessibility frames to be correct.
35+
/// Event triggered when the hierarchy is refreshed to allow components to be able to execute actions when that
36+
/// happens (e.g. focusing the dropdown after it opens).
3737
/// </summary>
38-
ScreenOrientation m_PreviousOrientation;
38+
public static event Action hierarchyRefreshed;
3939

4040
/// <summary>
4141
/// Constructor for the UGuiAccessibleSystem class.
@@ -246,8 +246,9 @@ void Traverse(Transform currentObject)
246246
// Mark the node as visited.
247247
visitedObjects.Add(currentObject);
248248

249-
// If the node is an AccessibleElement, add it to the list.
250249
var component = currentObject.GetComponent<AccessibleElement>();
250+
251+
// If the node is an AccessibleElement, add it to the list.
251252
if (component != null)
252253
{
253254
elements.Add(component);

Assets/Scripts/UITk/Controls/StackView.cs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using System.Linq;
52
using UnityEngine;
63
using UnityEngine.UIElements;
74

@@ -16,30 +13,33 @@ public partial class StackView : VisualElement
1613
int m_Index = -1;
1714

1815
public override VisualElement contentContainer => m_ContentContainer;
19-
20-
16+
17+
2118
[UxmlAttribute]
2219
public int index
2320
{
2421
get => m_Index;
2522
set
2623
{
2724
if (m_Index == value)
25+
{
2826
return;
29-
27+
}
28+
3029
m_Index = value;
3130
UpdateActiveViewFromIndex();
3231
indexChanged?.Invoke(m_Index);
3332
}
3433
}
35-
34+
3635
void UpdateActiveViewFromIndex()
3736
{
3837
if (m_Index < 0 || m_Index >= childCount)
3938
{
4039
activeView = null;
4140
return;
4241
}
42+
4343
activeView = this[m_Index];
4444
}
4545

@@ -48,29 +48,35 @@ public VisualElement activeView
4848
get
4949
{
5050
// Ensure the active view is valid. This is because children can be added/removed without being notified.
51-
bool needToEnsureValid = false;
52-
53-
if (m_ActiveView == null && m_Index != -1 && childCount > 0)
54-
needToEnsureValid = true;
55-
else if (m_ActiveView != null && (!Contains(m_ActiveView) || IndexOf(m_ActiveView) != m_Index))
56-
needToEnsureValid = true;
57-
51+
var needToEnsureValid = m_ActiveView == null && m_Index != -1 && childCount > 0 ||
52+
m_ActiveView != null && (!Contains(m_ActiveView) || IndexOf(m_ActiveView) != m_Index);
53+
5854
if (needToEnsureValid)
55+
{
5956
UpdateActiveViewFromIndex();
57+
}
58+
6059
return m_ActiveView;
6160
}
6261
set
6362
{
6463
var oldView = m_ActiveView;
65-
64+
6665
if (m_ActiveView == value)
66+
{
6767
return;
68+
}
69+
6870
m_ActiveView = value;
69-
71+
7072
if (panel != null)
73+
{
7174
StartTransition(oldView, m_ActiveView);
75+
}
7276
else
77+
{
7378
UpdateViews();
79+
}
7480

7581
index = IndexOf(m_ActiveView);
7682
activeViewChanged?.Invoke();
@@ -83,20 +89,21 @@ public VisualElement activeView
8389
public StackView()
8490
{
8591
AddToClassList("lsp-stack-view");
86-
92+
8793
m_ContentContainer = new VisualElement();
8894
m_ContentContainer.AddToClassList("lsp-stack-view__content-container");
8995
m_ContentContainer.style.flexGrow = 1;
9096
hierarchy.Add(m_ContentContainer);
97+
9198
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
9299
}
93-
100+
94101
void StartTransition(VisualElement from, VisualElement to)
95102
{
96103
if (from != null)
97104
{
98105
var fadeIn = from.experimental.animation.Start(
99-
(element) => element.style.opacity.value,
106+
element => element.style.opacity.value,
100107
0, 400, (element, value) =>
101108
{
102109
element.style.opacity = value;
@@ -112,9 +119,11 @@ void StartTransition(VisualElement from, VisualElement to)
112119
{
113120
to.style.display = DisplayStyle.Flex;
114121
to.style.opacity = 0.0f;
122+
115123
var fadeOut = to.experimental.animation.Start(
116-
(element) => element.style.opacity.value,
124+
element => element.style.opacity.value,
117125
1, 400, (element, value) => element.style.opacity = value);
126+
118127
fadeOut.onAnimationCompleted += () =>
119128
{
120129
};
@@ -128,26 +137,24 @@ void StartTransition(VisualElement from, VisualElement to)
128137
to.style.opacity = 1;
129138
}
130139
}
131-
140+
132141
void OnGeometryChanged(GeometryChangedEvent evt)
133142
{
134-
if (m_FirstGeometryChange )
143+
if (m_FirstGeometryChange)
135144
{
136145
m_FirstGeometryChange = false;
137146
UpdateViews();
138147
UnregisterCallback<GeometryChangedEvent>(OnGeometryChanged);
139148
}
140149
}
141-
150+
142151
public void UpdateViews()
143152
{
144153
UpdateActiveViewFromIndex();
154+
145155
foreach (var view in Children())
146156
{
147-
if (m_ActiveView != view)
148-
view.style.display = DisplayStyle.None;
149-
else
150-
view.style.display = DisplayStyle.Flex;
157+
view.style.display = m_ActiveView != view ? DisplayStyle.None : DisplayStyle.Flex;
151158
}
152159
}
153160
}

0 commit comments

Comments
 (0)