ActorCustomPropertiesChangedEventArgs

Actor Service

Struct

Arguments for the onCustomPropertiesChanged event.

Properties

changedProperties

Properties that were newly added or changed. This dictionary reference is re-pooled and re-used between events, so you should not cache it.

removedProperties

Properties that were removed. This list reference is re-pooled and re-used between events, so you should not cache it.

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);
}