Update UI using AR Foundation

Code and workflows to optimize and update the UI in our AR enabled project

What you'll develop on this page

Shooting down AR player
Getting shot down by desktop player

We will update the UI to both fit better and to dynamically update the instructions shown to AR players.

Github branch link: https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/tree/UI-Updates

Updating UI

Updating the instructions

We are going to update the instructions on the bottom-left of the screen in ARPlatformInitializer.

We are going to grab each of the instructions and update it with new text once we know that the project is running on an AR platform.

  • Paste the code snippet below into ARPlatformInitializer.cs:

Updating ARPlatformInitializer
  • In MainScene drag the GameUI GameObject from Hierarchy into the Game UI Document field within the AR Platform Initializer component in Inspector when AR Session is selected in Hierarchy

Moving GameUI into ARPlatformInitializer compoinent
  • Go to the BuildSettings folder, select iOS-Build, then click "Build and Run" in Inspector

  • Then launch the app

Hitting "Build and run" for the iOS-Build
Updating instructions dynamically for AR players

Updating the styling

We are going to update the styling to update the padding in the footer and header. Currently, the curve and notch in newer iPhones cover up quite a bit at the top and bottom of the screen. Although adjusting the styling to account for newer iPhones is not required (well, none of this is), we are explaining this just to make your project a little easier to navigate. We will also update our logo to use an SVG.

6KB
Open
Moetsi Logo SVG
  • Add the SVG file to the UI folder

    • With your SVG selected go to the Inspector and select

      • "UI Toolkit Vector Image" in the drop-down list for Generated Asset Type

      • Target Resolution 2160p

      • Click "Apply"

Adding Moetsi Logo SVG to UI/ as a UI Toolkit Vector Image
  • Paste the code snippet below into TitleScreenUI USS:

Updating TitleScreenUI USS

If you want to use a different SVG (not the Moetsi logo SVG), you will need to update the name of the SVG in the .logo class.

  • Paste the code snippet below into GameUI USS:

Updating GameUI USS

Let's also update our PanelSettings (in the UI folder) to better handle mobile and desktop.

  • In Inspector, make the following updates to PanelSettings:

    • Scale Mode = Scale With Screen Size

    • Screen Match Mode = Match Width Or Height

    • Reference Resolution

      • X = 1000

      • Y = 1200

    • Screen Match Mode Parameters

      • Height = 1

Our UI dynamically updates when we change our Scale Mode to "scale with screen size." We choose "height" as the main driver because we have a more vertical UI in our app. If it is wider, it should not affect the scale of our UI, but if it is taller or shorter we would want our UI to scale.

Updating PanelSettings
  • Now build for iOS (clicking "Build and Run" in Inspector when iOS-Build is selected from the BuildSettings folder) and take a look at our new UI updates

Shooting down AR player
Getting shot down by the desktop player

Github branch link:‌

git clone https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/ git checkout 'UI-Updates'‌

That's all folks!

Hopefully this gitbook was helpful to other XR developers. We plan on keeping this gitbook updates as packages and Editors are updated.

Please reach out on Discord if you have any questions or if you would like some additional sections to cover other topics.

Last updated