Skip to content

Commit 62075a6

Browse files
author
Bianca Marina Stana
committed
Cleaned up some more code
1 parent 0e915aa commit 62075a6

File tree

6 files changed

+35
-90
lines changed

6 files changed

+35
-90
lines changed

Assets/Scripts/Gameplay/GameViewController.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -308,30 +308,20 @@ void MoveCard(bool shouldMoveLeft, int count)
308308
// Announce that the card was moved.
309309
AssistiveSupport.notificationDispatcher.SendAnnouncement(announcement);
310310

311-
// On iOS, the accessibility hierarchy is flattened. This means that nodes don't have parents or
312-
// children, so functions that require them (like AccessibilityHierarchy.MoveNode) won't work. Hence,
313-
// we need to recreate the whole hierarchy instead.
314-
if (Application.platform == RuntimePlatform.IPhonePlayer)
315-
{
316-
AccessibilityManager.GetService<UGuiAccessibilityService>()?.RebuildHierarchy();
317-
m_WasHierarchyRefreshed = true;
311+
AssistiveSupport.activeHierarchy.MoveNode(element.node, element.node.parent,
312+
element.transform.GetSiblingIndex());
318313

319-
// Add the node count to the element ID to match the ID of the node in the refreshed hierarchy,
320-
// ensuring consistent focus even after rebuilding.
321-
var nodeToFocusId = element.node.id + AccessibilityManager.hierarchy.rootNodes.Count;
322-
nodeToFocusId += shouldMoveLeft ? -count : count;
314+
// Only refresh the frames for now to leave the announcement request to be handled.
315+
StartCoroutine(RefreshNodeFrames());
323316

324-
StartCoroutine(this.FocusOnNode(nodeToFocusId));
325-
}
326-
else
327-
{
328-
AccessibilityManager.hierarchy.MoveNode(element.node, element.node.parent,
329-
element.transform.GetSiblingIndex());
317+
AssistiveSupport.notificationDispatcher.SendLayoutChanged(element.node);
318+
return;
330319

331-
// Only refresh the frames for now to leave the announcement request to be handled.
332-
StartCoroutine(this.RefreshNodeFrames());
320+
IEnumerator RefreshNodeFrames()
321+
{
322+
yield return new WaitForEndOfFrame();
333323

334-
AssistiveSupport.notificationDispatcher.SendLayoutChanged(element.node);
324+
AssistiveSupport.activeHierarchy?.RefreshNodeFrames();
335325
}
336326
}
337327
}

Assets/Scripts/Screen Reader/AccessibilityService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Unity.Samples.ScreenReader
88
public abstract class AccessibilityService
99
{
1010
/// <summary>
11-
/// The accessibility sub hierarchy that this service operates on.
11+
/// The accessibility sub-hierarchy that this service operates on.
1212
/// </summary>
1313
public AccessibilitySubHierarchy hierarchy { get; set; }
1414

Assets/Scripts/Screen Reader/AccessibilitySubHierarchy.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44
namespace Unity.Samples.ScreenReader
55
{
66
/// <summary>
7-
/// This represents a sub hierarchy of an AccessibilityHierarchy created from a specific node that is used
8-
/// as root for the sub hierarchy.
7+
/// This represents a sub-hierarchy of an AccessibilityHierarchy created from a specific node that is used
8+
/// as root for the sub-hierarchy.
99
/// </summary>
1010
public struct AccessibilitySubHierarchy
1111
{
1212
/// <summary>
13-
/// The main accessibility hierarchy that this sub hierarchy belongs to.
13+
/// The main accessibility hierarchy that this sub-hierarchy belongs to.
1414
/// </summary>
1515
public AccessibilityHierarchy mainHierarchy { get; private set; }
1616

1717
/// <summary>
18-
/// Returns the node used as root for this sub hierarchy.
18+
/// Returns the node used as root for this sub-hierarchy.
1919
/// </summary>
2020
public AccessibilityNode rootNode { get; private set; }
2121

2222
/// <summary>
23-
/// Returns true if this sub hierarchy is valid.
23+
/// Returns true if this sub-hierarchy is valid.
2424
/// </summary>
2525
public bool isValid => mainHierarchy != null;
2626

2727
/// <summary>
28-
/// Constructs a sub hierarchy from the specified hierarchy and root node.
28+
/// Constructs a sub-hierarchy from the specified hierarchy and root node.
2929
/// </summary>
3030
/// <param name="mainHierarchy"></param>
3131
/// <param name="rootNode"></param>
@@ -43,13 +43,13 @@ public AccessibilitySubHierarchy(AccessibilityHierarchy mainHierarchy, Accessibi
4343
throw new System.ArgumentException("The root node must belong to the main hierarchy.", nameof(rootNode));
4444
}
4545

46-
// Note: if the root element is null then the sub hierarchy represents the whole hierarchy.
46+
// Note: if the root element is null then the sub-hierarchy represents the whole hierarchy.
4747
this.mainHierarchy = mainHierarchy;
4848
this.rootNode = rootNode;
4949
}
5050

5151
/// <summary>
52-
/// Disposes the sub hierarchy removing the root node from the main hierarchy.
52+
/// Disposes the sub-hierarchy removing the root node from the main hierarchy.
5353
/// </summary>
5454
public void Dispose()
5555
{
@@ -63,7 +63,7 @@ public void Dispose()
6363
}
6464

6565
/// <summary>
66-
/// Returns true if the specified node belongs to this sub hierarchy.
66+
/// Returns true if the specified node belongs to this sub-hierarchy.
6767
/// </summary>
6868
/// <param name="node"></param>
6969
/// <returns></returns>
@@ -79,7 +79,7 @@ public bool ContainsNode(AccessibilityNode node)
7979
return false;
8080
}
8181

82-
// We know the node is in the main hierarchy, now we need to check if it's part of this sub hierarchy.
82+
// We know the node is in the main hierarchy, now we need to check if it's part of this sub-hierarchy.
8383
var parentNode = node.parent;
8484

8585
while (parentNode != null)
@@ -96,7 +96,7 @@ public bool ContainsNode(AccessibilityNode node)
9696
}
9797

9898
/// <summary>
99-
/// Tries to get the node with the specified id if it belongs to this sub hierarchy.
99+
/// Tries to get the node with the specified id if it belongs to this sub-hierarchy.
100100
/// </summary>
101101
/// <param name="id">The id of the node to seek</param>
102102
/// <param name="node">The node found</param>
@@ -114,7 +114,7 @@ public bool TryGetNode(int id, out AccessibilityNode node)
114114
}
115115

116116
/// <summary>
117-
/// Tries to get the node at the specified position if it belongs to this sub hierarchy.
117+
/// Tries to get the node at the specified position if it belongs to this sub-hierarchy.
118118
/// </summary>
119119
/// <param name="horizontalPosition">The x position</param>
120120
/// <param name="verticalPosition">The y position</param>
@@ -155,7 +155,7 @@ public AccessibilityNode InsertNode(int childIndex, string label = null, Accessi
155155
{
156156
if (parent != null && !ContainsNode(parent))
157157
{
158-
Debug.LogError("The specified parent node does not belong to this sub hierarchy.");
158+
Debug.LogError("The specified parent node does not belong to this sub-hierarchy.");
159159
return null;
160160
}
161161

@@ -184,7 +184,7 @@ public bool MoveNode(AccessibilityNode node, AccessibilityNode newParent, int ne
184184
}
185185

186186
/// <summary>
187-
/// Removes the specified node from this sub hierarchy.
187+
/// Removes the specified node from this sub-hierarchy.
188188
/// </summary>
189189
/// <param name="node">The node to remove</param>
190190
/// <param name="removeChildren"></param>
@@ -199,7 +199,7 @@ public void RemoveNode(AccessibilityNode node, bool removeChildren = true)
199199
}
200200

201201
/// <summary>
202-
/// Removes all nodes from this sub hierarchy.
202+
/// Removes all nodes from this sub-hierarchy.
203203
/// </summary>
204204
public void Clear()
205205
{
@@ -213,22 +213,22 @@ public void Clear()
213213
}
214214
else
215215
{
216-
// If the sub hierarchy has no root node, we clear the whole hierarchy.
216+
// If the sub-hierarchy has no root node, we clear the whole hierarchy.
217217
mainHierarchy.Clear();
218218
}
219219
}
220220

221221
/// <summary>
222-
/// Refreshes the frames of all nodes in this sub hierarchy.
222+
/// Refreshes the frames of all nodes in this sub-hierarchy.
223223
/// </summary>
224224
public void RefreshNodeFrames()
225225
{
226-
// TODO: Optimize to only refresh nodes in this sub hierarchy.
226+
// TODO: Optimize to only refresh nodes in this sub-hierarchy.
227227
mainHierarchy.RefreshNodeFrames();
228228
}
229229

230230
/// <summary>
231-
/// Returns the lowest common ancestor of the two specified nodes if they both belong to this sub hierarchy.
231+
/// Returns the lowest common ancestor of the two specified nodes if they both belong to this sub-hierarchy.
232232
/// </summary>
233233
/// <param name="firstNode">The first node</param>
234234
/// <param name="secondNode">The second node</param>

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

Lines changed: 0 additions & 34 deletions
This file was deleted.

Assets/Scripts/Screen Reader/UGUI/MonoBehaviourExtensions.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/Scripts/Screen Reader/UITk/VisualTreeAccessibilityUpdater.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum NotificationType
3737
AccessibilitySubHierarchy m_SubHierarchy;
3838

3939
/// <summary>
40-
/// The sub hierarchy this updater is managing.
40+
/// The sub-hierarchy this updater is managing.
4141
/// </summary>
4242
public AccessibilitySubHierarchy hierarchy
4343
{
@@ -569,7 +569,7 @@ void Update(VisualElement visualTree)
569569
var rootNode = m_AccessibilityService.hierarchy.AddNode(string.IsNullOrEmpty(panelName) ?
570570
visualTree.name : panelName);
571571
rootNode.role = AccessibilityRole.Container;
572-
rootNode.isActive = (Application.platform == RuntimePlatform.OSXPlayer);
572+
rootNode.isActive = Application.platform == RuntimePlatform.OSXPlayer;
573573
hierarchy = new AccessibilitySubHierarchy(m_AccessibilityService.hierarchy.mainHierarchy, rootNode);
574574
DirtyRootFrame();
575575
shouldSendNotification = true;
@@ -681,7 +681,7 @@ void UpdateAccessibilityHierarchyRecursively(VisualElement element,
681681
}
682682
}
683683

684-
// Update the model element.
684+
// Update the modal element.
685685
if (!shouldBeIgnored && modal)
686686
{
687687
currentModalElement = element;
@@ -691,8 +691,8 @@ void UpdateAccessibilityHierarchyRecursively(VisualElement element,
691691
currentModalElement = null;
692692
}
693693

694-
// Note that we still travers the children even if the parent is ignored.
695-
// It is possible that nodes for children were created and has to be destroyed and the handlers cleaned up.
694+
// Note that we still traverse the children even if the parent is ignored.
695+
// It is possible that nodes for children were created and have to be destroyed and the handlers cleaned up.
696696
foreach (var child in element.hierarchy.Children())
697697
{
698698
UpdateAccessibilityHierarchyRecursively(child, parentAccessible, forced, visible && !shouldBeIgnored);

0 commit comments

Comments
 (0)