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
parentTransformParent 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
prefabPrefabRefPrefab reference from GamePrefabs
localPositionVector3Local position relative to parent
localRotationQuaternionLocal rotation
networkedboolWhether 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.
enableComponentsboolWhether to enable MonoBehaviour components (default: false)
onReadyAction<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
prefabPrefabRefPrefab reference
localPositionVector3Local position
localRotationQuaternionLocal 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
prefabPrefabRefPrefab reference for items
startPositionVector3Starting position
spacingfloatSpacing between items
countintNumber of items to place
baseRotationQuaternionBase rotation for items
rotationVariancefloatRandom 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
localPositionVector3Local position for the doors
localRotationQuaternionLocal rotation
openingHoursTextstringText to display for opening hours
doorMaterialMaterialOptional material for door panels
onServerReadyAction<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
prefabPrefabRefPrefab reference from GamePrefabs
localPositionVector3Local position relative to parent
localRotationQuaternionLocal rotation
componentNamesstring[]Array of component type names to enable
networkedboolWhether 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