docs.unity3d.com

    Sample | Integrate Storage in a Unity project

    You can use the Storage sample to retrieve the Digital Twin workspaces and scenes that a user can access. You can view the workspaces associated with your Unity ID and information about these workspaces, along with the scenes for those workspaces.

    Prerequisites

    To use the Storage sample, you require the following:

    • An installed Storage package
    • An installed Identity package
    • A valid Unity ID
    • A number of Digital Twin workspaces and scenes associated to your Unity ID

    Note: While the Storage package doesn't depend on the Identity package, the Identity package is used in the sample to control the authentication flow.

    Installation

    To install the sample, follow these steps:

    1. In your Unity project, go to Window > Package Manager > Digital Twins Storage.
    2. Expand Samples and select Import beside the Workspaces and Scenes sample. Screenshot of the Package Manager's Storage samples

      After the import process completes, you can view the imported assets under the Assets/Samples/Digital Twins Storage folder.

    Run the sample

    To run the sample, follow these steps:

    1. In your Unity project, go to File > Open Scene.
    2. Go to Assets/Samples/Digital Twins Storage/<package-version>/Workspaces and Scenes/WorkspacesAndScenes.unity and run the scene.
    3. In the Game view, select Login if you are logged out. Note: If you've previously logged in, the sample automatically logs you in so you can proceed to step 6.
    4. Log into the browser window that launches with your Unity ID account.
    5. Return to the sample scene to confirm that you are logged in. The Workspaces section lists the workspaces associated with your account.
    6. Select a workspace from the Workspaces section to see information about that workspace. Screenshot of the Workspaces and Workspace Info sections

    7. Select a scene from the Scenes section to see information about that scene. Screenshot of the Scenes and Scene Info sections

    Main components

    This section describes the scripts that make up the Storage sample.

    Workspaces and scenes sample script

    The WorkspacesAndScenesSample class is the main script for the sample and shows how to retrieve workspaces and scenes through an IWorkspaceProvider and IWorkspace. View the PopulateWorkspaces() and PopulateScenes() methods to see how this information is retrieved and fed to the sample's ContentScroller UI.

    This sample uses an IAuthenticator to receive events when the user is logged in or out. Refer to the Identity package for details about user authentication.

    To open the workspaces and scenes sample script, go to the Assets/Samples/Digital Twins Storage/<package-version>/Workspaces and Scenes/Scripts/WorkspacesAndScenesSample.cs file.

    Platform services script

    The PlatformServices class initializes and disposes of the IWorkspaceProvider and its dependencies. The PlatformServices class exposes the provider through a property so any component that needs to retrieve workspace information can use this provider.

    The PlatformServices class has two accompanying classes called PlatformServicesInitialization and PlatformServicesShutdown that call the initialization and shutdown methods through Unity's standard Monobehaviour methods Awake() and OnDestroy().

    To open the platform services script, go to the Assets/Samples/Digital Twins Storage/<package-version>/Common/Scripts/PlatformServices.cs file.

    Login manager script

    The LoginManager class is responsible for the user login. Refer to the Identity package and its samples for details about user authentication.

    To open the login manager script, go to the Assets/Samples/Digital Twins Storage/<package-version>/Common/Scripts/LoginManager.cs file.

    Troubleshoot

    This section describes issues you might have while using the Storage sample.

    Receives the Missing dependency to com.digital-twins.identity package console error

    If you don't have the Identity package installed, you receive the following error in your console: error CS1029: #error: 'Missing dependency to com.digital-twins.identity package.'

    Use the Package Manager to add the Identity package to your project.

    Can't view any workspaces or scenes

    Make sure you have successfully created at least one Digital Twins scene through the Digital Twins Asset Manager on the Digital Twins Portal.

    Automatic browser redirection doesn't work

    If you run the sample in the Unity Editor, you should see the following page after you successfully login through your browser.

    Screenshot of a successful login

    If you aren't automatically redirected to the Editor and nothing happens when you select Launch Application, return to the Editor. This should continue the authentication process.

    Mouse input isn't registered

    This sample isn't created to run with the Input System package. If you're using this package in your project, your mouse selections may not be detected.

    To fix this, set your project to support both the built-in input system and the Input System package: go to Edit > Project Settings > Player and set Active Input Handling to Both.

    Screenshot of the Active Input Handling field

    Copyright © Unity Technologies
    Generated by DocFX
    on
    Terms of use