SetCustomProperty
Method
Set a custom property for this actor. These properties are synchronized across all clients. An actor's properties are only cleared if they leave the space. Teleporting between servers of the same space will not clear the properties. Supported types: int, bool, float, Vector2, Vector3, string, Color32, byte, double, long, int[]
Definition
void SetCustomProperty(string name, object value)
void SetCustomProperty(string name, object value)
Examples
int cookieCount = 0;
private void OnEnable()
{
SpatialBridge.actorService.onActorJoined += HandleActorJoined;
SpatialBridge.actorService.onActorLeft += HandleActorLeft;
}
private void OnDisable()
{
SpatialBridge.actorService.onActorJoined -= HandleActorJoined;
SpatialBridge.actorService.onActorLeft -= HandleActorLeft;
}
private void HandleActorJoined(ActorJoinedEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " joined the space");
// Subscribe to property changes
actor.onCustomPropertiesChanged += (ActorCustomPropertiesChangedEventArgs customPropertiesArgs) => {
if (customPropertiesArgs.changedProperties.ContainsKey("cookies"))
{
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " has collected " + customPropertiesArgs.changedProperties["cookies"] + " cookies");
}
};
}
private void HandleActorLeft(ActorLeftEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " left the space");
}
private void CollectCookies(int cookies)
{
cookieCount += cookies;
SpatialBridge.actorService.localActor.SetCustomProperty("cookies", cookieCount);
}
int cookieCount = 0;
private void OnEnable()
{
SpatialBridge.actorService.onActorJoined += HandleActorJoined;
SpatialBridge.actorService.onActorLeft += HandleActorLeft;
}
private void OnDisable()
{
SpatialBridge.actorService.onActorJoined -= HandleActorJoined;
SpatialBridge.actorService.onActorLeft -= HandleActorLeft;
}
private void HandleActorJoined(ActorJoinedEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " joined the space");
// Subscribe to property changes
actor.onCustomPropertiesChanged += (ActorCustomPropertiesChangedEventArgs customPropertiesArgs) => {
if (customPropertiesArgs.changedProperties.ContainsKey("cookies"))
{
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " has collected " + customPropertiesArgs.changedProperties["cookies"] + " cookies");
}
};
}
private void HandleActorLeft(ActorLeftEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " left the space");
}
private void CollectCookies(int cookies)
{
cookieCount += cookies;
SpatialBridge.actorService.localActor.SetCustomProperty("cookies", cookieCount);
}