API reference

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.

Member Enumerations

Enumeration ScalingMode

Defines the scaling modes available for adjusting prefab sizes to fit the anchor's dimensions.
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.
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.
Random
No description available
ClosestSize
No description available
Custom
Custom logic, extend this class and override CustomPrefabSelection with your own implementation.

Fields

MRUK.RoomFilter SpawnOnStart[Get]
int SeedValue[Get]
UnityEvent onPrefabSpawned[Get]
The list of AnchorPrefabGroup configurations that determine how prefabs are spawned based on anchor data.

Properties

Dictionary< MRUKAnchor, GameObject > AnchorPrefabSpawnerObjects[Get]
List< GameObject > SpawnedPrefabs[Get]

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 spawned gameobjects from this AnchorPrefabSpawner 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.
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 with the PrefabSpawner.
Spawns prefabs according to the settings.
Parameters
clearPrefabs
Clear already existing prefabs before.
Creates gameobjects for the given room.
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.
Parameters
seed
The seed value to initialize the random number generator. If zero, the seed will be set to the current system tick count.
Selects a prefab based on custom logic.
This method is intended to be overridden in a class that extends AnchorPrefabSpawner with custom logic for selecting a prefab. It will be called whenever the PrefabSelection of an AnchorPrefabGroup is set to Custom.
Parameters
anchor
The anchor info to use.
prefabs
The list of prefabs to select from. Can be null.
Returns
The selected prefab.
Scales a prefab based on custom logic.
This method is intended to be overridden in a class that extends AnchorPrefabSpawner with custom logic for scaling a prefab. If not overridden, it throws a NotImplementedException.
Parameters
localScale
The local scale of the prefab.
Returns
The scaled local scale of the prefab.
Scales a prefab based on custom logic.
This method is intended to be overridden a class that extends AnchorPrefabSpawner with custom logic for scaling a prefab. If not overridden, it throws a NotImplementedException.
Parameters
localScale
The local scale of the prefab.
Returns
The scaled local scale of the prefab.
Aligns a prefab to an anchor's volume, based on custom logic.
This method is intended to be overridden a class that extends AnchorPrefabSpawner with custom logic for aligning a prefab. If not overridden, it throws a NotImplementedException.
Parameters
anchorVolumeBounds
The volume bounds of the anchor.
prefabBounds
The bounds of the prefab.
Returns
The local position of the prefab defined as the difference between the anchor's pivot and the prefab's pivot.
Aligns a prefab to an anchor's plane rect, based on custom logic.
This method is intended to be overridden a class that extends AnchorPrefabSpawner with custom logic for aligning a prefab. If not overridden, it throws a NotImplementedException.
Parameters
anchorPlaneRect
The volume bounds of the anchor.
prefabBounds
The bounds of the prefab.
Returns
The local position of the prefab defined as the difference between the anchor's pivot and the prefab's pivot.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon