GetXPropertyValue (Unity)
- Declaration
public static Color GetColorPropertyValue(this CavrnusSpaceConnection spaceConn, string containerName, string propertyName)
public static float GetFloatPropertyValue(this CavrnusSpaceConnection spaceConn, string containerName, string propertyName)
public static bool GetBoolPropertyValue(this CavrnusSpaceConnection spaceConn, string containerName, string propertyName)
public static string GetStringPropertyValue(this CavrnusSpaceConnection spaceConn, string containerName, string propertyName)
public static Vector4 GetVectorPropertyValue(this CavrnusSpaceConnection spaceConn, string containerName, string propertyName)
public static CavrnusTransformData GetTransformPropertyValue(this CavrnusSpaceConnection spaceConn, string containerName, string propertyName)
- Description
Gets the current property value.
This provides a snapshot of the current Property value. This may return a default value as defined by DefineXPropertyDefaultValue, a value that has been posted by a user using PostXPropertyUpdate, or empty default data if neither of the former is present.
Note that while it is sometimes useful to get the current value, a more common use case is to call BindXPropertyValue which will give you an event any time the property value changes. This is a more efficient way of keeping your scene objects up-to-date with the server than, say calling GetXPropertyValue in an Update()
loop.
- Sample
using CavrnusSdk.API;
using UnityEngine;
public class ManageObjectColor : MonoBehaviour
{
public Material MyMaterial;
private const string ContainerName = "MyMaterial";
private const string PropertyName = "color";
private void Start()
{
CavrnusFunctionLibrary.AwaitAnySpaceConnection(spaceConn => OnConnectedToSpace(spaceConn));
}
private void OnConnectedToSpace(CavrnusSpaceConnection spaceConn)
{
//Compare my state to the server, and post an update if out-of-sync
Color serverPropertyValue = spaceConn.GetColorPropertyValue(ContainerName, PropertyName);
if (!serverPropertyValue.Equals(MyMaterial.color))
spaceConn.PostColorPropertyUpdate(ContainerName, PropertyName, MyMaterial.color);
}
}