API reference

AnchorPrefabSpawner Class

Extends MonoBehaviour
Manages the spawning of prefabs based on anchor data within a scene, providing various customization options for scaling, alignment, and selection modes.

Protected Fields

_random : Random
Signature
Random _random

Fields

onPrefabSpawned : UnityEvent
Signature
UnityEvent onPrefabSpawned
PrefabsToSpawn : List< AnchorPrefabGroup >
The list of AnchorPrefabGroup configurations that determine how prefabs are spawned based on anchor data.
Signature
List<AnchorPrefabGroup> PrefabsToSpawn
SeedValue : int
Signature
int SeedValue
SpawnOnStart : MRUK.RoomFilter
Signature
MRUK.RoomFilter SpawnOnStart

Properties

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

Protected Methods

ClearPrefab ( go )
Destroys the specified GameObject, effectively removing the prefab from the scene.
Signature
virtual void ClearPrefab(GameObject go)
Parameters
go: GameObject  The GameObject to be destroyed.
Returns
void
ClearPrefab ( anchorInfo )
Clears the gameobject associated with the anchor.
Useful when receiving an event that a specific anchor has been removed
Signature
virtual void ClearPrefab(MRUKAnchor anchorInfo)
Parameters
anchorInfo: MRUKAnchor  The anchor reference
Returns
void
ClearPrefabs ( room )
Clears all the spawned gameobjects from this AnchorPrefabSpawner in the given room.
Signature
virtual void ClearPrefabs(MRUKRoom room)
Parameters
room: MRUKRoom  The room from where to remove all the spawned objects
Returns
void
ClearPrefabs ()
Clears all the gameobjects created with the PrefabSpawner.
Signature
virtual void ClearPrefabs()
Returns
void
ReceiveAnchorCreatedEvent ( anchorInfo )
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.
Signature
virtual void ReceiveAnchorCreatedEvent(MRUKAnchor anchorInfo)
Parameters
anchorInfo: MRUKAnchor  The anchor that has been created.
Returns
void
ReceiveAnchorRemovedCallback ( anchorInfo )
Responds to the event of an anchor being removed from the scene.
This method clears all prefabs spawned by this spawner.
Signature
virtual void ReceiveAnchorRemovedCallback(MRUKAnchor anchorInfo)
Parameters
anchorInfo: MRUKAnchor  The anchor that has been removed.
Returns
void
ReceiveAnchorUpdatedCallback ( anchorInfo )
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.
Signature
virtual void ReceiveAnchorUpdatedCallback(MRUKAnchor anchorInfo)
Parameters
anchorInfo: MRUKAnchor  The anchor that has been updated.
Returns
void
ReceiveCreatedRoom ( room )
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.
Signature
virtual void ReceiveCreatedRoom(MRUKRoom room)
Parameters
room: MRUKRoom  The room that has been created.
Returns
void
ReceiveRemovedRoom ( room )
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.
Signature
virtual void ReceiveRemovedRoom(MRUKRoom room)
Parameters
room: MRUKRoom  The room that has been removed.
Returns
void
RegisterAnchorUpdates ( room )
Registers the anchor update events for a specific room.
This method starts listening for anchor creation, removal, and update events within the specified room.
Signature
virtual void RegisterAnchorUpdates(MRUKRoom room)
Parameters
room: MRUKRoom  The room for which to register anchor update events.
Returns
void
SpawnPrefab ( anchorInfo )
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.
Signature
virtual void SpawnPrefab(MRUKAnchor anchorInfo)
Parameters
anchorInfo: MRUKAnchor  The anchor based on which the prefab will be spawned.
Returns
void
SpawnPrefabs ( clearPrefabs )
Spawns prefabs according to the settings.
Signature
virtual void SpawnPrefabs(bool clearPrefabs=true)
Parameters
clearPrefabs: bool  Clear already existing prefabs before.
Returns
void
SpawnPrefabs ( room , clearPrefabs )
Creates gameobjects for the given room.
Signature
virtual void SpawnPrefabs(MRUKRoom room, bool clearPrefabs=true)
Parameters
room: MRUKRoom  The room reference
clearPrefabs: bool  clear all before adding them again
Returns
void
UnRegisterAnchorUpdates ( room )
Unregisters the anchor update events for a specific room.
This method stops listening for anchor creation, removal, and update events within the specified room.
Signature
virtual void UnRegisterAnchorUpdates(MRUKRoom room)
Parameters
room: MRUKRoom  The room for which to unregister anchor update events.
Returns
void

Methods

CustomPrefabAlignment ( anchorVolumeBounds , prefabBounds )
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.
Signature
virtual Vector3 CustomPrefabAlignment(Bounds anchorVolumeBounds, Bounds? prefabBounds)
Parameters
anchorVolumeBounds: Bounds  The volume bounds of the anchor.
prefabBounds: Bounds?  The bounds of the prefab.
Returns
Vector3  The local position of the prefab defined as the difference between the anchor's pivot and the prefab's pivot.
CustomPrefabAlignment ( anchorPlaneRect , prefabBounds )
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.
Signature
virtual Vector3 CustomPrefabAlignment(Rect anchorPlaneRect, Bounds? prefabBounds)
Parameters
anchorPlaneRect: Rect  The volume bounds of the anchor.
prefabBounds: Bounds?  The bounds of the prefab.
Returns
Vector3  The local position of the prefab defined as the difference between the anchor's pivot and the prefab's pivot.
CustomPrefabScaling ( localScale )
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.
Signature
virtual Vector3 CustomPrefabScaling(Vector3 localScale)
Parameters
localScale: Vector3  The local scale of the prefab.
Returns
Vector3  The scaled local scale of the prefab.
CustomPrefabScaling ( localScale )
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.
Signature
virtual Vector2 CustomPrefabScaling(Vector2 localScale)
Parameters
localScale: Vector2  The local scale of the prefab.
Returns
Vector2  The scaled local scale of the prefab.
CustomPrefabSelection ( anchor , prefabs )
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.
Signature
virtual GameObject CustomPrefabSelection(MRUKAnchor anchor, List< GameObject > prefabs)
Parameters
anchor: MRUKAnchor  The anchor info to use.
prefabs: List< GameObject >  The list of prefabs to select from. Can be null.
Returns
GameObject  The selected prefab.
InitializeRandom ( seed )
Initializes a new instance of the Random class using the specified seed.
Signature
void InitializeRandom(ref int seed)
Parameters
seed: ref int  The seed value to initialize the random number generator. If zero, the seed will be set to the current system tick count.
Returns
void

Inner Struct

AnchorPrefabGroup Struct

Extends IEquatable< AnchorPrefabGroup >
Represents a group of prefabs associated with specific scene labels, along with settings for how they should be spawned.

Fields

Alignment : AlignMode
Signature
AlignMode Alignment
CalculateFacingDirection : bool
Signature
bool CalculateFacingDirection
IgnorePrefabSize : bool
Signature
bool IgnorePrefabSize
Signature
MRUKAnchor.SceneLabels Labels
MatchAspectRatio : bool
Signature
bool MatchAspectRatio
Prefabs : List< GameObject >
Signature
List<GameObject> Prefabs
PrefabSelection : SelectionMode
Signature
SelectionMode PrefabSelection
Scaling : ScalingMode
Signature
ScalingMode Scaling

Inner Enums

ScalingMode Enum

Defines the scaling modes available for adjusting prefab sizes to fit the anchor's dimensions.

Enumeration Constants

MemberDescription
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.

AlignMode Enum

Defines the alignment modes available for positioning prefabs relative to the anchor's dimensions.

Enumeration Constants

MemberDescription
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.

SelectionMode Enum

Defines the selection modes available for choosing prefabs from a list.

Enumeration Constants

MemberDescription
Random
ClosestSize
Custom
Custom logic, extend this class and override CustomPrefabSelection with your own implementation.