Table of Contents

Class PrefabPlacer

Namespace
S1MAPI.Building.Components
Assembly
S1MAPI_Mono.dll

Places network-spawnable prefabs from the game. Handles FishNet network spawning for multiplayer compatibility. Extracted from SemanticBuildingBuilder for SRP compliance.

public sealed class PrefabPlacer
Inheritance
PrefabPlacer
Inherited Members

Constructors

PrefabPlacer(Transform)

Create a new prefab placer.

public PrefabPlacer(Transform parent)

Parameters

parent Transform

Parent transform for placed prefabs

Methods

Place(PrefabRef, Vector3, Quaternion, bool, bool, Action<GameObject>?)

Place a prefab at the specified position. When networked is true, the prefab is spawned via FishNet on the server and automatically replicated to clients. On clients, returns null but queues a deferred link so the replicated object is parented to the building once it arrives via FishNet.

public GameObject? Place(PrefabRef prefab, Vector3 localPosition, Quaternion localRotation, bool networked = true, bool enableComponents = false, Action<GameObject>? onReady = null)

Parameters

prefab PrefabRef

Prefab reference from GamePrefabs

localPosition Vector3

Local position relative to parent

localRotation Quaternion

Local rotation

networked bool

Whether to spawn on network (server only). When true, returns null on clients — the server-spawned object is replicated via FishNet and automatically parented to the building hierarchy.

enableComponents bool

Whether to enable MonoBehaviour components (default: false)

onReady Action<GameObject>

Optional callback invoked on the GameObject after instantiation (server) or after the FishNet-replicated object is linked (client). Use this to configure components before sensors/triggers activate (e.g., set DoorController.AutoOpenForPlayer).

Returns

GameObject

The instantiated prefab, or null if not found or if networked and not server

PlaceItem(PrefabRef, Vector3, Quaternion)

Place an item prefab (like bongs on shelves).

public GameObject? PlaceItem(PrefabRef prefab, Vector3 localPosition, Quaternion localRotation)

Parameters

prefab PrefabRef

Prefab reference

localPosition Vector3

Local position

localRotation Quaternion

Local rotation

Returns

GameObject

The item instance or null if prefab not found

PlaceItemRow(PrefabRef, Vector3, float, int, Quaternion, float)

Place multiple items in a row (e.g., items on a shelf).

public GameObject?[] PlaceItemRow(PrefabRef prefab, Vector3 startPosition, float spacing, int count, Quaternion baseRotation, float rotationVariance = 15)

Parameters

prefab PrefabRef

Prefab reference for items

startPosition Vector3

Starting position

spacing float

Spacing between items

count int

Number of items to place

baseRotation Quaternion

Base rotation for items

rotationVariance float

Random rotation variance in degrees

Returns

GameObject[]

Array of placed items

PlaceSlidingDoors(Vector3, Quaternion, string, Material?, Action<GameObject>?)

Place sliding double doors at a wall opening. On server, spawns the door and applies customization (material, opening hours text). On clients, returns null but queues a deferred link so the FishNet-replicated door is parented to the building and receives the same customization once it arrives. See AddSlidingDoors(Vector3, Quaternion, string, Action<GameObject>?) remarks for DoorController server-gating details.

public GameObject? PlaceSlidingDoors(Vector3 localPosition, Quaternion localRotation, string openingHoursText = "6AM-6PM", Material? doorMaterial = null, Action<GameObject>? onServerReady = null)

Parameters

localPosition Vector3

Local position for the doors

localRotation Quaternion

Local rotation

openingHoursText string

Text to display for opening hours

doorMaterial Material

Optional material for door panels

onServerReady Action<GameObject>

Optional callback invoked on the door GameObject before activation, server-only. Runs after internal customization (material, opening hours text) but before Awake/OnEnable fire, so sensors see configured values. Does not fire on clients.

Returns

GameObject

The door instance on server, or null on clients / if prefab not found

PlaceWithComponents(PrefabRef, Vector3, Quaternion, string[], bool)

Place a prefab with specific components enabled by name. Useful for enabling only certain game logic (e.g., ATM, VendingMachine). When networked is true, returns null on non-server callers but the replicated object is automatically parented on clients.

public GameObject? PlaceWithComponents(PrefabRef prefab, Vector3 localPosition, Quaternion localRotation, string[] componentNames, bool networked = true)

Parameters

prefab PrefabRef

Prefab reference from GamePrefabs

localPosition Vector3

Local position relative to parent

localRotation Quaternion

Local rotation

componentNames string[]

Array of component type names to enable

networked bool

Whether to spawn on network (server only). When true, returns null on clients — the server-spawned object is replicated via FishNet and automatically parented to the building hierarchy.

Returns

GameObject

The instantiated prefab, or null if not found or if networked and not server