docs.unity3d.com
    Show / Hide Table of Contents

    Use case: Link the Camera to the DataStreamer

    This use case outlines the basics of setting up a camera in a streaming scene. Use this use case to learn how to set the camera observer on a DataStreamer and dynamically set its Far Clipping Plane.

    Prerequisites

    To accomplish this use case, you require the following:

    • Install the Data Streaming package on a new or existing Unity project (refer to Installation).
    • Add these packages to the manifest.json:
      {
        "dependencies": {
          // Add these lines:
          // Replace "<x.y.z>" with the version you wish to install
          "com.unity.cloud.identity": "<x.y.z>",
          "com.unity.cloud.storage": "<x.y.z>"
          // Other dependencies...
        }
      }
    

    Overview

    To accomplish this use case, do the following:

    1. Upload a scene
    2. Create a cloud streaming behavior
    3. Set up a new scene
    4. Set the camera as the observer
    5. Dynamically set the camera far clipping plane.
    6. Link a custom camera as the observer.

    Upload a scene

    To upload a scene, follow these steps:

    1. Log into the Unity Cloud Portal.
    2. Select New to create a scene.

      Screen capture that displays adding a new scene

    3. Name the scene My First Scene and select Create.

    4. Select files to upload a file.

      Screen capture that displays uploading a file for your scene

    Create a cloud streaming behavior

    To create a cloud streaming behavior, follow these steps:

    1. Open your Unity project.
    2. Go to the Assets folder in the Project window.
    3. Right Click and Select Create > C# Script.
    4. Rename the new script as CloudDataStreaming.
    5. Open the CloudDataStreaming script and replace the content with the following:

    Set up a new scene

    To set up a new scene, follow these steps:

    1. Create a new scene.
    2. Create a GameObject called Streamer.
    3. Select Add Component in the Inspector window and add the Cloud Data Streaming component.
    4. Copy the Scene ID part of the scene details on the Unity Cloud Portal.
    5. Paste the Scene ID in the Cloud Data Streaming inspector field.
    6. Select Play.
    7. No geometry gets loaded.
    8. Select Stop.

    Set the camera as the observer

    As you saw in the previous steps, no meshes were loaded. This happened because the DataStreamer didn't know what to load since it's responsible for loading only what is required and it ignores geometry which is not in an observer's field of view. To fix this:

    1. Insert a m_CameraObserver field on your CloudDataStreaming Component.
    2. Insert AddObserver call in the CloudDataStreaming.Start Method.
    3. Add a Camera in your scene if one doesn't exist.
    4. Set the CloudDataStreaming Component Camera Observer value to your scene camera.
    5. Select Play to view your project load in front of the camera.*
    6. Select Stop.
    • If the scene does not load in front of the camera, select the menu item Edit / Frame Streamed Scene.

    Dynamically set the camera far clipping plane and automatically position it.

    Now that the DataStreamer knows what to load based on the camera position, you might have seen display issues when geometry were too far from the camera. When moving the camera too far from the streamed asset, you will end up having the asset disappear since the camera clipping plane value is too low.

    To prevent setting the far clipping plane to an arbitrary value, we will dynamically link its value to the distance between the camera and the asset.

    1. Go to the Assets folder in the Project window.
    2. Go to Add (+) > C# Script.
    3. Rename the new script as CameraSetup.
    4. Open the CameraSetup script and replace the content with the following:
    5. Insert a m_CameraSetup field on your CloudDataStreaming Component.
    6. Insert SetView call in the CloudDataStreaming.Start Method.
    7. Select the scene camera.
    8. Select Add Component in the Inspector window and add the CameraSetup component.
    9. Set the CameraSetup Component Camera value to your scene camera.
    10. Set the CloudDataStreaming Component CameraSetup value to the newly created CameraSetup component.
    11. Select Play to view your project load in front of the camera.
    12. The camera will initialize itself to a default position.
    13. Select the scene camera.
    14. Move the camera and look at the far clipping plane value getting updated.
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023