Skip to content

Commit 0c3d47e

Browse files
author
Bianca Marina Stana
committed
Updated the accessibility code to Unity 6.3
1 parent eace475 commit 0c3d47e

19 files changed

+1041
-362
lines changed

Assets/Scripts/Controls/MultiSelectDropdown.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using Unity.Samples.ScreenReader;
65
using UnityEngine;
76
using UnityEngine.UI;
87
using UnityEngine.Events;
98
using UnityEngine.EventSystems;
109
using TMPro;
11-
using UnityEngine.Accessibility;
1210

1311
namespace Unity.Samples.Controls
1412
{
@@ -1032,21 +1030,6 @@ public void Show()
10321030
continue;
10331031
}
10341032

1035-
if (i == 0)
1036-
{
1037-
var acc = item.GetComponentInChildren<AccessibleToggle>();
1038-
1039-
if (acc != null)
1040-
{
1041-
acc.label = data.text;
1042-
1043-
if (acc.node != null)
1044-
{
1045-
AssistiveSupport.notificationDispatcher.SendLayoutChanged(acc.node);
1046-
}
1047-
}
1048-
}
1049-
10501033
// Automatically set up a toggle state change listener.
10511034
item.toggle.isOn = values.Contains(i);
10521035
item.toggle.onValueChanged.AddListener(_ => OnSelectItem(item.toggle));
@@ -1144,8 +1127,6 @@ public void Show()
11441127
m_Template.gameObject.SetActive(false);
11451128
itemTemplate.gameObject.SetActive(false);
11461129

1147-
AccessibilityManager.GetService<UGuiAccessibilityService>().RebuildHierarchy();
1148-
11491130
m_Blocker = CreateBlocker(rootCanvas);
11501131
}
11511132

Assets/Scripts/Gameplay/GameViewController.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void OnLetterCardsChanged()
146146

147147
if (Gameplay.instance != null && Gameplay.instance.state != Gameplay.State.Stopped)
148148
{
149-
this.DelayRefreshHierarchy(AccessibilityManager.GetService<UGuiAccessibilityService>());
149+
AccessibilityManager.GetService<UGuiAccessibilityService>()?.RebuildHierarchy();
150150

151151
Invoke(nameof(MoveAccessibilityFocusOnClue), 1f);
152152
}
@@ -165,7 +165,7 @@ bool OnLetterCardSelected()
165165

166166
// When a letter card is selected, deactivate all accessibility nodes except the ones corresponding to
167167
// the letter cards to allow the selected card to be moved correctly.
168-
AccessibilityManager.GetService<UGuiAccessibilityService>().ActivateOtherAccessibilityNodes(false, letterCardContainer);
168+
AccessibilityManager.GetService<UGuiAccessibilityService>()?.ActivateOtherAccessibilityNodes(false, letterCardContainer);
169169

170170
letterCard.SetDraggingVisuals(true);
171171
SetLetterCardsAccessibilityLabel(false);
@@ -174,7 +174,7 @@ bool OnLetterCardSelected()
174174
{
175175
m_AccessibilitySelectedCard = null;
176176

177-
AccessibilityManager.GetService<UGuiAccessibilityService>().ActivateOtherAccessibilityNodes(true, letterCardContainer);
177+
AccessibilityManager.GetService<UGuiAccessibilityService>()?.ActivateOtherAccessibilityNodes(true, letterCardContainer);
178178

179179
letterCard.SetDraggingVisuals(false);
180180
SetLetterCardsAccessibilityLabel(true);
@@ -234,7 +234,7 @@ void OnNodeFocusChanged(AccessibilityNode node)
234234
{
235235
if (node != null)
236236
{
237-
var element = AccessibilityManager.GetService<UGuiAccessibilityService>().GetAccessibleElementForNode(node);
237+
var element = AccessibilityManager.GetService<UGuiAccessibilityService>()?.GetAccessibleElementForNode(node);
238238
m_AccessibilityFocusedCard = element != null ? element.GetComponent<LetterCard>() : null;
239239
MoveSelectedCard();
240240
}
@@ -313,23 +313,23 @@ void MoveCard(bool shouldMoveLeft, int count)
313313
// we need to recreate the whole hierarchy instead.
314314
if (Application.platform == RuntimePlatform.IPhonePlayer)
315315
{
316-
AccessibilityManager.GetService<UGuiAccessibilityService>().RebuildHierarchy();
316+
AccessibilityManager.GetService<UGuiAccessibilityService>()?.RebuildHierarchy();
317317
m_WasHierarchyRefreshed = true;
318318

319319
// Add the node count to the element ID to match the ID of the node in the refreshed hierarchy,
320320
// ensuring consistent focus even after rebuilding.
321321
var nodeToFocusId = element.node.id + AccessibilityManager.hierarchy.rootNodes.Count;
322322
nodeToFocusId += shouldMoveLeft ? -count : count;
323323

324-
this.DelayFocusOnNode(nodeToFocusId);
324+
StartCoroutine(this.FocusOnNode(nodeToFocusId));
325325
}
326326
else
327327
{
328328
AccessibilityManager.hierarchy.MoveNode(element.node, element.node.parent,
329329
element.transform.GetSiblingIndex());
330330

331331
// Only refresh the frames for now to leave the announcement request to be handled.
332-
this.DelayRefreshNodeFrames();
332+
StartCoroutine(this.RefreshNodeFrames());
333333

334334
AssistiveSupport.notificationDispatcher.SendLayoutChanged(element.node);
335335
}

Assets/Scripts/Gameplay/PauseScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void OnEnable()
2828
{
2929
// The pause screen is presented over the gameplay screen like a modal view, so all accessibility nodes
3030
// outside the pause screen should be deactivated while it is open.
31-
AccessibilityManager.GetService<UGuiAccessibilityService>().ActivateOtherAccessibilityNodes(false, transform);
31+
AccessibilityManager.GetService<UGuiAccessibilityService>()?.ActivateOtherAccessibilityNodes(false, transform);
3232

3333
// When the pause screen opens, move the accessibility focus to its status text (which is also the first
3434
// accessibility node on the pause screen).

0 commit comments

Comments
 (0)