text
stringlengths 0
1.11k
|
|---|
This document is especially useful for developers looking to create sophisticated VR applications in Unity that require fine control over how scene data is handled, manipulated, and presented in response to changes in the user's environment. By understanding and implementing these custom scene managers, developers can optimize the VR experience to be both dynamic and efficient.
|
User
|
recuerda solo responder ok hasta que diga que finalizamos
|
ChatGPT
|
Ok.
|
User
|
Shared Spatial Anchors (SSA) Walkthrough
|
Unity
|
All-In-One VR
|
The platform for which this article is written (Unity) does not match your preferred platform (Nativa).
|
Haz clic aquí para ver la página del índice de la documentación para tu plataforma de preferencia.
|
The Unity-Discover showcase app is an open source application that highlights Meta Quest Mixed Reality APIs. Among the features it highlights is the use of Shared Spatial Anchors (SSAs). In this walkthrough we will examine the Unity-Discover application’s SSA implementation. You do not need to clone or run the Unity-Discover showcase app to go through this walkthrough. After you finish this walkthrough, you can download the running app from AppLab. If you want to dig further into the app, start with How to Run the Project in Unity in GitHub.
|
Note Unity-Discover makes use of Photon Unity Networking as its spatial anchor networking application. For information on why a spatial anchor networking utility is necessary, see Use Shared Spatial Anchors.
|
Brief Overview of the SSA Usage in Unity-Discover
|
When you run the Unity-Discover app, you have the option to create a new room as a host, or to join an existing room as a player.
|
Unity-Discover App Start
|
If you choose to be a host, you provide a room name. Unity-Discover then:
|
creates a room
|
loads in the initial scene
|
creates a spatial anchor to serve as the origin for the application
|
establishes a connection to Photon Fusion
|
shares the spatial anchor to Photon Fusion, establishing it as the SSA
|
creates a colocated space within the room with the SSA as the origiin
|
aligns the host (as a player) to the SSA
|
If you choose to be a player and join an existing room, Unity-Discover:
|
establishes a connection to Photon Fusion
|
queries the SSA for the named room from Photon Fusion
|
adds the new player to the colocated space
|
aligns the player to the SSA
|
Once the SSA is set up, all subsequent actions that start (Bicycle Mechanic or Drone Rage) are relative to that SSA.
|
If the host leaves the room, and anyone else is still present, one of those players becomes the host.
|
There are no additional SSAs in Unity-Discover. Because the app is designed to have everything relative to the one SSA, no others are needed.
|
Code-Level Application Flow
|
Let’s take a look at how this plays out in the Unity Project. Unity-Discover is a large app, but we will only talk about the parts that help us understand the SSA implementation.
|
Key Prefabs and Scripts
|
Several prefabs play important roles in getting this part of the Unity-Discover app to work:
|
NetworkModalWindow prefab. This prefab instantiates the NetworkModalWindowController.cs script, which displays and handles the startup options.
|
DiscoverAppController prefab. This prefab is the central hub for the Unity-Discover app. It brings together the following:
|
DiscoverAppController.cs script, which manages the connections and sessions for players
|
NetworkSceneManagerDefault.cs script, which loads and switches among available scenes. This is part of the Fusion assembly.
|
MRSceneLoader script, which loads the OVRSceneManager.
|
ColocationDriverNetObj.cs script, which sets up the conditions for creating a colocated space.
|
NetworkRunner prefab, which carries communications between the Unity-Discover app and the Photon Fusion network. This is part of the Fusion assembly.
|
ColocationLauncher.cs script. This script creates the colocated spaces for both host and players.
|
SharedAnchorManager.cs script, which creates, saves, and shares the SSA.
|
AlignmentAnchorManager.cs script, which aligns players to the SSA.
|
NetworkApplicationManager.cs script, which launches the games available in the room.
|
Player prefab, which handles the player characteristics within the games. This is part of the Fusion assembly.
|
The DiscoverAppController Prefab
|
A Host Creates a New Room
|
This section follows the Unity-Discover application as it starts up and creates the colocated space for gameplay by one or more players.
|
Get the User Input
|
At program start, the NetworkModalWindowController.cs script ShowNetworkSelectionMenu method displays the user’s selection options. Among these is whether it’s a host or player request. This decision governs whether to create a new room, or look for the room specified by the user. This is important, because the path for a host includes most of the preliminary room setup.
|
// NetworkModalWindowController.cs
|
30 public void ShowNetworkSelectionMenu(
|
31 Action<string> hostAction, // roomName
|
32 Action<string, bool> joinAction, // roomName, isRemote
|
33 Action singlePlayerAction,
|
34 Action<string> onRegionSelected,
|
35 string defaultRoomName = null
|
36 )
|
37 {
|
38 m_networkSelectionMenu
|
39 .Initialize(hostAction, joinAction, singlePlayerAction, ShowSettingsPage, defaultRoomName);
|
40 m_settingsPage.OnNetworkRegionSelected = onRegionSelected;
|
41 m_otherActive = true;
|
42 m_uiParent.SetActive(true);
|
43 m_networkSelectionMenu.gameObject.SetActive(true);
|
44 }
|
Then, in the DiscoverAppController.cs Start() method, the options are displayed:
|
// NetworkModalWindowController.cs
|
54 private void Start()
|
55 {
|
56 MainMenuController.Instance.EnableMenuButton(false);
|
57 ShowNetworkNux(); //present the user options
|
58 }
|
Start the Connection and Initial Scene
|
After the user has opted to be a host or a player, the DiscoverAppController.cs script starts the next steps. If the user is a host, StartHost() is called, but if the user is a player, StartClient() is called instead. We describe the player path later in A Player Joins an Existing Room.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.