A lightweight package that makes creating colocation experiences easier using a shared origin.
- Getting Started (Photon)
- Technical Information
- Additional Networking Solutions
- Extend Coordinate Providers
- Troubleshooting
- Tips
This package can be installed by cloning or unzipping this repository into your projects Packages
folder or by importing the package using the Package Manager, by doing the following:
- Copy the git URL from this project Code Url.
- Inside of your Unity project, open the Package Manager.
- Select the + button and click Add packages from git URL.
- Paste the project URL copied in step one and then click Add.
This section includes steps to create a multi-user experience using Photon and sample scripts provided in the package.
After Adding the Network Anchors package to the package manager, you will be able to install the examples via the package manager by selecting the package and expanding the dropdown title Samples.
- Open the Player Settings Window
- Select MagicLeap/Manifest settings
- Enable the PcfRead, Internet and Camera Capture.
- Add downloading PUN 2 from the asset store and importing it into your project.
- Define the your Photon credentials in using the PUN Wizard or PUN Server settings.
- To enable the photon example scripts, navigate to the Player Settings (Edit > Project Settings , then click Player).
- Under the Other Settings section, add PHOTON to the Scripting Define Symbols. Do this for each of your target platforms settings (Standalone and Lumin).
- From the menu select File> New Scene. Then select the Basic (Built-in) template.
- Replace the existing main camera with the Magic Leap Camera Prefab located under
Packages/Magic Leap SDK/Tools/Prefabs
. - Save the new scene, name it
NetworkAnchorsExample
.
- Create an empty GameObject named
PhotonController
- Add the
Simple Photon Room
andSimple Photon Lobby
components. - Set the Simple Photon Room's
Photon User Prefab
to theSimplePhotonUser
prefab located under/Assets/Samples/Network Anchors/1.1.0/Examples/PhotonExample/Resources/
- Create an empty GameObject called
NetworkAnchor
- Set the transform's position to
0, 0, 1
and the rotation to0, 18, 0
. - Add the
Network Anchor Service
component to the object. - Then and the
Network Anchor Localizer
component. - Use the Network Anchor's Localizer's
OnAnchorPlaced
event to visualize when the anchor has been created/localized:- Create a cube as a child of the object
- Set the scale to
0.3, 0.3, 0.3
and disable it. - Select the NetworkAnchor
- Create a new OnAnchorPlaced event
- Set the event target as the Cube and the event as
GameObject.SetActive
, set it to true.
- Add the MultiPlatformCoordinateProvider prefab from
/Assets/Samples/Network Anchors/1.1.0/Examples/PhotonExample/Prefabs
into the scene.
- Create an empty GameObject called PunNetworkAnchorController
- Add the
PhotonNetworkAnchorController
component. - Set the fields with the objects in your scene.
- Select the Main Camera Prefab and add the
Magic Leap Network Anchor Example
component. - Set the Network Anchor Localizer field to target the Network Anchor object in your scene.
- Save your example scene.
- From the Project settings, enable the Internet privileges.
- Set your project's project Identification Information.
- Target your developer certificate in the project settings.
- Deploy to device.
Magic Leap
To create or find a network anchor on the Magic Leap Headsets, press the trigger on the controller.
When Auto Search for Image is disabled on the MLCoordinateProvider, Image tracking can be initialized using by pressing the trigger on the Controller. When initialized, the Magic Leap will try to locate an Image target for 1 minute.
Desktop
If you are running the game on your Desktop, without Zero Iteration, enable Force Standalone
on the MultiPlatformCoordinateProvider object in your scene. You can then enter play mode and hit spacebar. Localizing on your desktop will preserve the network anchors position even when the owner of the network anchor leaves.
Network Anchor Service
The entry point for localization requests. When information is requested, the services appends any required data (such as the players coordinates) and then invokes the BroadcastNetworkEvent.
Note: In order to make this solution flexible, the service does not communicate with the network directly. The network events should be caught, then relayed to your preferred network solution. Network events are sent as a json string.
Network Anchor Service
Sends user input to the service and responds to the Network Anchor Service's localization events.
IGenericCoordinateProvider
An interface that needs to be implemented per platform so that the service can retrieve the platform's coordinates using a generic class.
StandaloneCoordinateProvider
Implements IGenericCoordinateProvider and returns a remote players coordinates by first requesting them through the NetworkAnchor service, and then using them as it's own. This may be changed to use image targets in the future.
MLGenericCoordinateProvider
Implements IGenericCoordinateProvider and returns the Magic Leap's PCFs as a Generic Coordinate.
The samples folder contains a script called GenericNetworkAnchorController
. This script can be used as a template for integrating other network solutions such as Mirror.
- To make sure that player position's spawn properly, make sure that remote players are created as a child of the network anchor and transmit their local position.
- The network anchor service is only responsible for aligning the network anchor position across devices. Logic for creating and syncing transforms will have to be configured individually.
Additional Coordinate providers can be added by implementing the IGenericCoordinateProvider
interface. The samples folder includes a MultiPlatformCoordinateProvider
which demonstrates a rudimentary way on providing the correct provider to the network service at runtime.
Coordinate providers are located in Packages/com.magicleap.spectatorview.networkanchors/Runtime/Providers/
. The provided scripts implement the RequestCoordinateReferences
as an Async Task
. This is so that the task can be waited on until initialization is complete. View MLGenericCoordinateProvider
to learn more.
If the headsets cannot localize, follow the following troubleshooting steps.
- Make sure that you do not press Skip when initializing the headset, and that the headset showed a confirmation that the location was recognized.
- Enable the Shared World feature in the devices Settings > Privacy menu.
- Restart your headset.
If you do not expect to localize with mobile devices, you can disable searching for an image target to make localization faster. To do this:
- Select the MultiPlatformCoordinateProvider prefab then select the MLGenericCoordinateProvier child object.
- In the inspector, disable Auto Search for Image.
Note : Image scanning can still be triggered using an external script. See the MagicLeapNetworkAnchorExample.cs script for reference.