API reference
API reference
Select your platform
No SDKs available
No versions available

AnchorPrefabSpawner Class

Extends MonoBehaviour, ICustomAnchorPrefabSpawner
Manages the spawning of prefabs based on anchor data within a scene, providing various customization options for scaling, alignment, and selection modes.
This class extends the ICustomAnchorPrefabSpawner interface, which can be used together with AnchorPrefabSpawnerUtilities to provide custom implementations of the prefab spawning logic.

Member Enumerations

Enumeration ScalingMode

Defines the scaling modes available for adjusting prefab sizes to fit the anchor's dimensions.
The scaling mode determines how the prefab will be resized to match the anchor's size. It is defined for each AnchorPrefabGroup and can be set to one of the following options:
When using he ScalingMode.Custom the CustomPrefabScaling method must be implemented in a custom class that extends this class or the ICustomPrefabScaling interface.
Stretch
Stretch each axis to exactly match the size of the Plane/Volume.
UniformScaling
Scale each axis by the same amount to maintain the correct aspect ratio.
UniformXZScale
Scale the X and Z axes uniformly but the Y scale can be different.
NoScaling
Don't perform any scaling.
Custom
Custom logic, extend this class and override CustomPrefabScaling with your own implementation.

Enumeration AlignMode

Defines the alignment modes available for positioning prefabs relative to the anchor's dimensions.
The alignment mode determines how the prefab will be positioned within the anchor area. It is defined for each AnchorPrefabGroup and can be set to one of the following options:
When using he AlignMode.Custom the CustomPrefabAlignment method must be implemented in a custom class that extends this class or the ICustomPrefabScaling interface.
Automatic
For volumes align to the base, for planes align to the center.
Bottom
Align the bottom of the prefab with the bottom of the volume or plane.
Center
Align the center of the prefab with the center of the volume or plane.
NoAlignment
Don't add any local offset to the prefab.
Custom
Custom logic, extend this class and override CustomPrefabAlignment with your own implementation.

Enumeration SelectionMode

Defines the selection modes available for choosing prefabs from a list.
The selection mode determines which prefab will be spawned when multiple options are available. It is defined for each AnchorPrefabGroup and can be set to one of the following options:
When using he SelectionMode.Custom the CustomPrefabSelection method must be implemented in a custom class that extends this class or the ICustomPrefabScaling interface.
Random
Randomly choose a prefab from the list every time.
ClosestSize
Choose the prefab that has the smallest difference between its size and the one of the anchor.
Custom
Custom logic, extend this class and override CustomPrefabSelection with your own implementation.

Fields

"When the scene data is loaded, this controls what room(s) the prefabs will spawn in.
Specify a seed value for consistent prefab selection (0 = Random).
Event triggered when a prefab is spawned.
This event will be deprecated in a future version.
The list of AnchorPrefabGroup configurations that determine how prefabs are spawned based on anchor data.

Properties

Gets a dictionary that maps MRUKAnchor instances to their corresponding spawned GameObjects.
This should be treated as read-only, do not modify the contents.
Use AnchorPrefabSpawnerObjects property instead.

Protected Fields

Random _random[Get]

Protected Functions

Handles the event when a room is removed from the scene.
This method clears all prefabs associated with the room and unregisters updates for anchors within the room.
Parameters
room
The room that has been removed.
Unregisters the anchor update events for a specific room.
This method stops listening for anchor creation, removal, and update events within the specified room.
Parameters
room
The room for which to unregister anchor update events.
Registers the anchor update events for a specific room.
This method starts listening for anchor creation, removal, and update events within the specified room.
Parameters
room
The room for which to register anchor update events.
Responds to the event of an anchor being updated within the scene.
This method clears existing prefabs and triggers the spawning of new prefabs based on the updated anchor information, provided that updates are being tracked and the anchor or its parent room is not marked as untracked.
Parameters
anchorInfo
The anchor that has been updated.
Responds to the event of an anchor being removed from the scene.
This method clears all prefabs spawned by this spawner.
Parameters
anchorInfo
The anchor that has been removed.
Responds to the event of a new anchor being created within the scene.
This method triggers the spawning of prefabs if the anchor's room is being tracked and updates are enabled.
Parameters
anchorInfo
The anchor that has been created.
Responds to the event of a new room being created within the scene.
This method triggers the spawning of prefabs and registers for anchor updates within the room, provided that room updates are being tracked and the configuration is set to handle all rooms.
Parameters
room
The room that has been created.
Clears all the previously spawned gameobjects from this AnchorPrefabSpawner instance in the given room.
Parameters
room
The room from where to remove all the spawned objects.
Destroys the specified GameObject, effectively removing the prefab from the scene and removing it from the AnchorPrefabSpawnerObjects dictionary.
Parameters
go
The GameObject to be destroyed.
Clears the gameobject associated with the anchor.
Useful when receiving an event that a specific anchor has been removed
Parameters
anchorInfo
The anchor reference
Clears all the gameobjects created by this AnchorPrefabSpawner instance for all rooms.
Spawns prefabs for all the rooms in the scene.
This method will iterate through all the rooms in the scene and spawn prefabs for each anchor in the room according to the AnchorPrefabGroup configuration of each label.
Parameters
clearPrefabs
Clear already existing prefabs before.
Spawns prefabs for all the rooms in the scene.
This method will spawn prefabs for each anchor in the room according to the AnchorPrefabGroup configurations of each label.
Parameters
room
The room reference
clearPrefabs
clear all before adding them again
Spawns a prefab based on the provided anchor information.
This method determines the appropriate prefab to spawn based on the anchor's label, checks for existing instances, and configures the spawned prefab's position, scale, and orientation according to the anchor's properties and predefined settings.
Parameters
anchorInfo
The anchor based on which the prefab will be spawned.

Member Functions

Initializes a new instance of the Random class using the specified seed.
either the seed value or the current system tick count is used.
Parameters
seed
The seed value to initialize the random number generator. If zero, the seed will be set to the current system tick count.
Custom logic for selecting a prefab.
Extend this class and override this method with your custom logic. All AnchorPrefabGroup with SelectionMode set to Custom will use this method.
Parameters
anchor
The anchor information.
prefabs
The list of prefabs to choose from.
Returns
The selected prefab GameObject.
Custom logic for scaling a prefab's volume.
Extend this class and override this method with your custom logic. All AnchorPrefabGroup with ScalingMode set to Custom will use this method.
Parameters
localScale
The local scale vector.
Returns
The adjusted scale vector.
Custom logic for scaling a prefab's plane rectangle.
Extend this class and override this method with your custom logic.
Parameters
localScale
The local scale vector.
Returns
The adjusted scale vector.
Custom logic for aligning a prefab within a volume.
Extend this class and override this method with your custom logic. All AnchorPrefabGroup with AlignMode set to Custom will use this method.
Parameters
anchorVolumeBounds
The bounds of the anchor volume.
prefabBounds
The optional bounds of the prefab.
Returns
The adjusted position vector.
Custom logic for aligning a prefab within a plane rectangle.
Extend this class and override this method with your custom logic. All AnchorPrefabGroup with AlignMode set to Custom will use this method.
Parameters
anchorPlaneRect
The rectangle of the anchor plane.
prefabBounds
The optional bounds of the prefab.
Returns
The adjusted position vector.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon