Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #457 from parjohns/patch-2
Browse files Browse the repository at this point in the history
10151.md
  • Loading branch information
Jeehut authored Dec 5, 2023
2 parents 7072664 + ff7ee90 commit 795aec5
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions content/notes/wwdc22/10151.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
contributors: parjohns
---

# Apple Accessibility Plug-in for Unity Developers

This presentation involves a plugin available on Unity's GitHub.

https://github.com/apple/unityplugins

## Accessibility Elements
In this demo, cards can be flipped by tapping the button. However, VoiceOver would not read the text on the screen and an external switch would not tap the button.
![Example-Card-Game][0]

[0]: ../../../images/notes/wwdc22/10151/0.jpg

The text, cards, and button need to be accessibility elements so the user can understand what is on the screen.
![Elements][1]

[1]: ../../../images/notes/wwdc22/10151/1.JPG

If the app supports multiple languages, the labels should also be localized.


With the labels added as accessibility elements, VoiceOver would now be able to read what is on the screen. However it would be unable to tell that there is a button.

By adding an accessibility trait, VoiceOver would read the button as "Flip Button" and an external switch would be able to control the button.

![Elements][2]

[2]: ../../../images/notes/wwdc22/10151/2.JPG

There are many different types of traits, full list can be found here:

https://developer.apple.com/documentation/uikit/uiaccessibilitytraits


In this example, the cards would need a `value` trait to be able to provide the face value of the cards.

![Value][3]

[3]: ../../../images/notes/wwdc22/10151/3.JPG

### Unity Implementation

Accessibility elements are added using the `Accessibility Node` component. This component is added to any gameObject that the user wishes to add accessibility for. The script provides the following fields:
- Traits
- Label
- Value
- Hint
- Identifier

![Script][4]

[4]: ../../../images/notes/wwdc22/10151/4.JPG
Buttons in Unity UI already have the `Accessibility Node` component by default.

Creating custom C# scripts using Apple's Accessibility requires `using Apple.Accessibility`

In this example, the accessibility information is returned in the `accessibilityValueDelegate` lambda expression.
```
using Apple.Accessibility;
public class AccessibleCard : MonoBehaviour
{
public PlayingCard cardType;
public bool isCovered;
void Start()
{
var accessibilityNode = GetComponent<AccessibilityNode>();
accessibilityNode.accessibilityValueDelegate = () => {
if (isCovered) {
return "covered";
}
if (cardType == PlayingCard.AceOfSpades) {
return "Ace of Spades";
}
}
}
}
```
## Dynamic Type
Dynamic Type allows users to adjust their font size.

To implement this in Unity, a new C# script can be made. The script can subscribe to the `onPreferredTextSizesChanged` event, and modify its font size when new events occur.

```
public class DynamicCardFaces : MonoBehaviour
{
public Material RegularMaterial;
public Material LargeMaterial;
void OnEnable()
{
AccessibilitySettings.onPreferredTextSizesChanged += _settingsChanged;
}
void _settingsChanged()
{
GetComponent<Text>().textSize = (int)(originalSize * AccessibilitySettings.PreferredContentSizeMultiplier);
}
}
```

In a similar way, the face of the cards could also be modified during these accessibility events.
```
void _settingsChanged()
{
var shouldUseLarge = AccessibilitySettings.PreferredContentSizeCategory >=
ContentSizeCategory.AccessibilityMedium;
GetComponent<Renderer>().material = shouldUseLarge ? RegularMaterial :
LargeMaterial;
}
```
![Value][5]

[5]: ../../../images/notes/wwdc22/10151/5.JPG
![Value][6]

[6]: ../../../images/notes/wwdc22/10151/6.JPG
## UI Accommodations

### Reduce Transparency
- Turns transparent objects more opaque
- Helps improve legibility
- Can be checked with `AccessibilitySettings.IsReduceTransparencyEnabled`

![Reduce-Transparency][8]

[8]: ../../../images/notes/wwdc22/10151/8.jpg

### Increase Contrast
- Colors stand out more
- Makes controls easier to recognize
- Can be checked with `AccessibilitySettings.IsIncreaseContrastEnabled`

![Increase-Contrast][7]

[7]: ../../../images/notes/wwdc22/10151/9.jpg

### Reduce Motion
- Animations should be removed if this is enabled
- Can be checked with `AccessibilitySettings.IsReduceMotionEnabled`

Binary file added images/notes/wwdc22/10151/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/2.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/3.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/4.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/5.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/6.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notes/wwdc22/10151/9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 795aec5

Please sign in to comment.