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