Connecting Different Applications to a Cavrnus Space (Unity)

A Cavrnus Space is ultimately just data in the Cloud. This means that any number of dissimilar Applications could, in theory, connect to a single space.

This is not a common use case, but it can be highly valuable in some circumstances.

For this example, we will show a simple 2-sided experience. Once user will be in a 3d world viewing shapes. The other user will have a 2d control panel, controlling which shapes are visible.

The 3d Shape Viewer

The 3d Shape Viewer is built in a very similar way to many of our previous examples. We simply set up the visual elements of the Scene, and then add SyncVisibility components to our three shapes.

image-20240226-074404.png

Given how they are set up, this means that the data this Application is looking for is the “Visibility” bool in the Property Containers: “Cube”, “Sphere”, and “Capsule”.

The 2d Control Panel

Next, we are going to make a completely separate Control Panel Application.

For this, we will put together a very basic UI panel to show the three shapes and their visibility status:

image-20240226-080256.png

We will then hook this UI up to the Properties with a simple script:

using CavrnusSdk.API; using TMPro; using UnityEngine; public class ShapesControlPanel : MonoBehaviour { public TMP_Text CubeStatus; public TMP_Text SphereStatus; public TMP_Text CapsuleStatus; private CavrnusSpaceConnection spaceConn; void Start() { CavrnusFunctionLibrary.AwaitAnySpaceConnection(sc => OnSpaceConnected(sc)); } private void OnSpaceConnected(CavrnusSpaceConnection spaceConn) { this.spaceConn = spaceConn; //The Viewer Application defaults to them being "true" so we will as well. spaceConn.DefineBoolPropertyDefaultValue("Cube", "Visible", true); spaceConn.DefineBoolPropertyDefaultValue("Sphere", "Visible", true); spaceConn.DefineBoolPropertyDefaultValue("Capsule", "Visible", true); //Update the status text when the value changes spaceConn.BindBoolPropertyValue("Cube", "Visible", vis => CubeStatus.text = $"Cube Visible = {vis}"); spaceConn.BindBoolPropertyValue("Sphere", "Visible", vis => SphereStatus.text = $"Sphere Visible = {vis}"); spaceConn.BindBoolPropertyValue("Capsule", "Visible", vis => CapsuleStatus.text = $"Capsule Visible = {vis}"); } public void ToggleCube() { if(spaceConn == null) { Debug.LogWarning("Cannot toggle value, not yet connected to a space"); return; } bool currentVisible = spaceConn.GetBoolPropertyValue("Cube", "Visible"); spaceConn.PostBoolPropertyUpdate("Cube", "Visible", !currentVisible); } public void ToggleSphere() { if (spaceConn == null) { Debug.LogWarning("Cannot toggle value, not yet connected to a space"); return; } bool currentVisible = spaceConn.GetBoolPropertyValue("Sphere", "Visible"); spaceConn.PostBoolPropertyUpdate("Sphere", "Visible", !currentVisible); } public void ToggleCapsule() { if (spaceConn == null) { Debug.LogWarning("Cannot toggle value, not yet connected to a space"); return; } bool currentVisible = spaceConn.GetBoolPropertyValue("Capsule", "Visible"); spaceConn.PostBoolPropertyUpdate("Capsule", "Visible", !currentVisible); } }

Final Result

With this done we can now build both Applications.

The 2d Control Panel Application will see the Viewer App’s user and be able to talk to them. They can also toggle the status of the Shapes.

The View App, meanwhile, will see the Control Panel’s user, and will see their shapes Appear and Disappear in response to that user’s actions.

 

Related pages