diff --git a/content/notes/wwdc22/10151.md b/content/notes/wwdc22/10151.md new file mode 100644 index 00000000..05b2cf34 --- /dev/null +++ b/content/notes/wwdc22/10151.md @@ -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.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().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().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` + diff --git a/images/notes/wwdc22/10151/0.jpg b/images/notes/wwdc22/10151/0.jpg new file mode 100644 index 00000000..23cf9e15 Binary files /dev/null and b/images/notes/wwdc22/10151/0.jpg differ diff --git a/images/notes/wwdc22/10151/1.JPG b/images/notes/wwdc22/10151/1.JPG new file mode 100644 index 00000000..b0c4ba15 Binary files /dev/null and b/images/notes/wwdc22/10151/1.JPG differ diff --git a/images/notes/wwdc22/10151/2.JPG b/images/notes/wwdc22/10151/2.JPG new file mode 100644 index 00000000..d5465403 Binary files /dev/null and b/images/notes/wwdc22/10151/2.JPG differ diff --git a/images/notes/wwdc22/10151/3.JPG b/images/notes/wwdc22/10151/3.JPG new file mode 100644 index 00000000..ea016dbd Binary files /dev/null and b/images/notes/wwdc22/10151/3.JPG differ diff --git a/images/notes/wwdc22/10151/4.JPG b/images/notes/wwdc22/10151/4.JPG new file mode 100644 index 00000000..4ba90adf Binary files /dev/null and b/images/notes/wwdc22/10151/4.JPG differ diff --git a/images/notes/wwdc22/10151/5.JPG b/images/notes/wwdc22/10151/5.JPG new file mode 100644 index 00000000..67630bcc Binary files /dev/null and b/images/notes/wwdc22/10151/5.JPG differ diff --git a/images/notes/wwdc22/10151/6.JPG b/images/notes/wwdc22/10151/6.JPG new file mode 100644 index 00000000..aa4359bf Binary files /dev/null and b/images/notes/wwdc22/10151/6.JPG differ diff --git a/images/notes/wwdc22/10151/7.png b/images/notes/wwdc22/10151/7.png new file mode 100644 index 00000000..d8a083ab Binary files /dev/null and b/images/notes/wwdc22/10151/7.png differ diff --git a/images/notes/wwdc22/10151/8.jpg b/images/notes/wwdc22/10151/8.jpg new file mode 100644 index 00000000..1016a8d1 Binary files /dev/null and b/images/notes/wwdc22/10151/8.jpg differ diff --git a/images/notes/wwdc22/10151/9.jpg b/images/notes/wwdc22/10151/9.jpg new file mode 100644 index 00000000..2100ca33 Binary files /dev/null and b/images/notes/wwdc22/10151/9.jpg differ