Once your Application has Bound the relevant Properties and is displaying them, you can how allow them to Post() their own changes.
In order to do this, we recommend intercepting the user’s UI/Application interactions, and Posting the new data directly to Cavrnus instead of assigning the values inside your Application.
Here are some simple examples of how you could do that:
Await the CavrnusSpaceConnection (as usual)
Before you can do anything, you will need to wait for your Space to connect. We explain how to do this here: https://cavrnus.atlassian.net/wiki/spaces/CSM/pages/837451792/Binding+and+Displaying+Properties#Await-the-CavrnusSpaceConnection
Posting Single Property Updates
To give the most basic example of Posting a Property update, let’s assume we have a button in the UI to “Turn Object Red”.
The function that button would call would simply be this:
public void TurnObjectRed() { spaceConn.PostColorPropertyUpdate(ContainerName, PropertyName, Color.red); }
Posting Continuous Property Updates
As you will recall from our Core Concepts, every change that is ever made to a space is stored in the Journal. This is very useful for being able to view/understand the history of what has happened in a Space. However, it has limitations. Specifically, if you are Posting updates to the Journal every frame then the Journal will eventually become very big and performance will eventually be impacted.
For this, let’s take a Color Wheel as an example:
In this Color Wheel there are a lot of dials, sliders, and input fields, all modifying the same value. If a user were to click and drag across one of the sliders it could result in hundreds, perhaps even thousands of Property updates being Posted. To fix this, we recommend using Transient updates. Transient updates begin a CavrnusLivePropertyUpdate
. These updates will be sent to other users, but will not be stored in the Journal.
When the user first clicks down you can create a CavrnusLivePropertyUpdate
by calling BeginTransientColorPropertyUpdate
.
When they drag you can send out Updates by calling UpdateWithNewData
.
When they are done interacting you can call Finish
to post the final value to the Journal.
On the other hand, if somehow the interaction was invalid or ended up with bad data, you can call Cancel
any time to clear the changes and make it like it never happened.
private CavrnusLivePropertyUpdate<Color> liveColorUpdate = null; //We just clicked the Color Wheel public void BeginInteractingWithColorWheel(Color color) { if (liveColorUpdate == null) { liveColorUpdate = spaceConn.BeginTransientColorPropertyUpdate(ContainerName, PropertyName, color); } } //This will trigger every frame while the user is dragging the color wheel around public void UseColorWheel(Color color) { if (liveColorUpdate != null) { liveColorUpdate.UpdateWithNewData(color); } } //The user releases their mouse public void ReleaseColorWheel(Color color) { if(liveColorUpdate != null) { liveColorUpdate.Finish(); liveColorUpdate = null; } } //If the color wheel closed unexpectedly, we should cancel the live change as if it never happened. public void CancelColorWheel() { if (liveColorUpdate != null) { liveColorUpdate.Cancel(); liveColorUpdate = null; } }