-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalEntities.swift
More file actions
80 lines (60 loc) · 2.4 KB
/
GlobalEntities.swift
File metadata and controls
80 lines (60 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
RealityKit entities used throughout the app.
*/
import RealityKit
/// The root entity for entities placed during the game.
let spaceOrigin = Entity()
/// An anchor that helps calculate the position of clouds relative to the player.
let cameraAnchor = AnchorEntity(.head)
/// A container for asset names that the app loads from a bundle at runtime.
struct BundleAssets {
static let
heartBlasterScene = "HeartBlaster.usda",
heartBlasterEntity = "HeartBeam",
heartTurretScene = "HeartTurret.usda",
heartTurretEntity = "heartTurret",
heartLightScene = "Heart.usda",
heartLightEntity = "Heart",
cloudScene = "Cloud.usda",
cloudEntity = "UpdatedGrumpyScene2",
cloudParameterName = "happiness",
cloud = "Cloud.usdz",
beamName = "Beam Intermediate"
}
/// The beam entity that's displayed when the player makes a heart gesture.
var beam = Entity()
/// An entity that sits in between the beam and its parent; used to finely adjust the beam position.
let beamIntermediate = Entity()
/// The version of the beam that's attached to the purple holder.
var floorBeam = Entity()
var isFloorBeamShowing = false
// Containers for assets used throughout the game.
var globalFireworks: Entity? = nil
var globalHeart: Entity? = nil
var turret: Entity? = nil
var heart: Entity? = nil
var cloud: Entity? = nil
/// The clouds in the current round of the game.
var cloudEntities: [Entity] = []
/// A map from beam names to entities in multiplayer.
var multiBeamMap: [String: Entity] = [:]
/// Creates a beam for each player in multiplayer as they join the game and play spatially.
@MainActor
func initialBeam(for player: Player) async -> Entity {
guard let playerBeam = await loadFromRealityComposerPro(
named: BundleAssets.heartBlasterEntity,
fromSceneNamed: BundleAssets.heartBlasterScene
) else {
fatalError("Unable to load beam from Reality Composer Pro project.")
}
let handOrigin = Entity()
let multiBeamIntermediate = Entity()
handOrigin.addChild(multiBeamIntermediate)
multiBeamIntermediate.addChild(playerBeam)
spaceOrigin.addChild(handOrigin)
playerBeam.generateCollisionShapes(recursive: true)
playerBeam.name = "multibeam-\(player.name)"
return handOrigin
}