SpatialTemplateRole
An interface for defining roles that you assign to the participants of a group activity.
Declaration
protocol SpatialTemplateRole : Hashable, SendableOverview
Adopt the SpatialTemplateRole interface in a custom enum and use it with your custom spatial template. Roles are an optional way for you to assign a purpose to participants with a spatial Persona. For example, a spatial template for a game might define roles for the opposing teams. When a participant joins an activity, assign one of your custom roles to place them in a specific seat of your template. Seats in the template are available only to participants with spatial Personas.
The following example shows a spatial template for a table tennis game with two teams. The first four seats are for the players of the team, and the last seat is for a spectator. When participants request a role for the red or blue team, the template assigns them to the first available seat in the array with that role.
struct SimpleTableTennis: SpatialTemplate {
enum Role: String, SpatialTemplateRole {
case blueTeam
case redTeam
}
var elements: [any SpatialTemplateElement] = [
.seat(position: .app.offsetBy(x: -1, z: -3), role: Role.blueTeam),
.seat(position: .app.offsetBy(x: -1, z: 3), role: Role.redTeam),
.seat(position: .app.offsetBy(x: 1, z: -3), role: Role.blueTeam),
.seat(position: .app.offsetBy(x: 1, z: 3), role: Role.redTeam),
.seat(position: .app.offsetBy(x: -2, z: 0)),
]
}