onActorJoined

Event

Event that is triggered initially upon connection for all actors who are in the server, and then when a new actor joins the server.

Remarks

This event is triggered for all actors, even those that had already joined before the local actor joined the server. You can use wasAlreadyJoined to determine if the actor was already joined or not. Note that this is also triggered for the local actor when the local actor joins the server.

Returns IActorService.ActorJoinedDelegate

Examples

int cookieCount = 0;

private void OnEnable()
{
SpatialBridge.actorService.onActorJoined += HandleActorJoined;
}

private void OnDisable()
{
SpatialBridge.actorService.onActorJoined -= HandleActorJoined;
}

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 CollectCookies(int cookies)
{
cookieCount += cookies;
SpatialBridge.actorService.localActor.SetCustomProperty("cookies", cookieCount);
}
int cookieCount = 0;

private void OnEnable()
{
SpatialBridge.actorService.onActorJoined += HandleActorJoined;
}

private void OnDisable()
{
SpatialBridge.actorService.onActorJoined -= HandleActorJoined;
}

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 CollectCookies(int cookies)
{
cookieCount += cookies;
SpatialBridge.actorService.localActor.SetCustomProperty("cookies", cookieCount);
}