Minimal Photon PUN 2 bootstrap for sample/demo scenes.
More...
|
| void | Awake () |
| | Initializes UI, assigns the PUN prefab pool provider, and performs an initial prefab registration pass.
|
| |
| void | JoinOrCreateRoom () |
| | Attempts to join an existing room or create a new one using the configured defaults.
|
| |
| void | LeaveRoom () |
| | Leaves the current room (if in room) or disconnects from Photon (if only connected).
|
| |
| void | RegisterAllPrefabs () |
| | Registers player + explicit prefabs and auto-registers all Runtime Spawner–referenced prefabs in the scene. Also logs the registry for debugging (optional).
|
| |
| void | BindCameraToLocalPlayerIfMine () |
| | If this client owns the spawned player, binds the Cinemachine virtual camera to follow/look at it.
|
| |
| void | TryStartSpawnerIfMaster () |
| | Starts RuntimeSpawner only on the Master Client, once per session. Sets the player on the spawner so distance/culling features target the local master player.
|
| |
| void | UpdateStatusUI (string msg) |
| | Updates UI widgets (TMP label, connect/leave buttons) and writes to the console.
|
| |
Minimal Photon PUN 2 bootstrap for sample/demo scenes.
Responsibilities:
-
Connects to Photon and joins/creates a room.
-
Spawns a local player via PhotonNetwork.Instantiate(string, Vector3, Quaternion, byte).
-
Binds a CinemachineVirtualCamera to the local player (if assigned).
-
Runs RuntimeSpawner only on the Master Client to maintain single authority.
-
Registers all Runtime Spawner prefabs with PUNPoolPrefabProvider so PUN can instantiate from your pool.
Usage:
-
Drop this component into a scene and assign references (player prefab, optional spawner, camera, UI).
-
Ensure your prefabs have a PUNPrefabKey (recommended) or rely on the prefab name as the key.
-
On play, press the connect button (or call ConnectOrStart from your own UI).
Notes:
-
Prefabs are pooled via PUNPoolPrefabProvider; no
Resources usage is required.
-
RuntimeSpawner starts only on the Master Client; when the master changes, the bootstrap stops/starts it accordingly.
-
PhotonNetwork.AutomaticallySyncScene is left
false for simplicity in this sample.
◆ Awake()
| void PunBootstrap.Awake |
( |
| ) |
|
|
private |
Initializes UI, assigns the PUN prefab pool provider, and performs an initial prefab registration pass.
◆ BindCameraToLocalPlayerIfMine()
| void PunBootstrap.BindCameraToLocalPlayerIfMine |
( |
| ) |
|
|
private |
If this client owns the spawned player, binds the Cinemachine virtual camera to follow/look at it.
◆ ConnectOrStart()
| void PunBootstrap.ConnectOrStart |
( |
| ) |
|
Connects to Photon if needed; otherwise directly joins/creates a room. Wire this to a UI button for quick testing.
◆ JoinOrCreateRoom()
| void PunBootstrap.JoinOrCreateRoom |
( |
| ) |
|
|
private |
Attempts to join an existing room or create a new one using the configured defaults.
◆ LeaveRoom()
| void PunBootstrap.LeaveRoom |
( |
| ) |
|
|
private |
Leaves the current room (if in room) or disconnects from Photon (if only connected).
◆ OnConnectedToMaster()
| override void PunBootstrap.OnConnectedToMaster |
( |
| ) |
|
◆ OnDisconnected()
| override void PunBootstrap.OnDisconnected |
( |
DisconnectCause | cause | ) |
|
◆ OnJoinedRoom()
| override void PunBootstrap.OnJoinedRoom |
( |
| ) |
|
◆ OnLeftRoom()
| override void PunBootstrap.OnLeftRoom |
( |
| ) |
|
◆ OnMasterClientSwitched()
| override void PunBootstrap.OnMasterClientSwitched |
( |
Player | newMasterClient | ) |
|
◆ OnPlayerEnteredRoom()
| override void PunBootstrap.OnPlayerEnteredRoom |
( |
Player | newPlayer | ) |
|
◆ OnPlayerLeftRoom()
| override void PunBootstrap.OnPlayerLeftRoom |
( |
Player | otherPlayer | ) |
|
◆ RegisterAllPrefabs()
| void PunBootstrap.RegisterAllPrefabs |
( |
| ) |
|
|
private |
Registers player + explicit prefabs and auto-registers all Runtime Spawner–referenced prefabs in the scene. Also logs the registry for debugging (optional).
◆ TryStartSpawnerIfMaster()
| void PunBootstrap.TryStartSpawnerIfMaster |
( |
| ) |
|
|
private |
Starts RuntimeSpawner only on the Master Client, once per session. Sets the player on the spawner so distance/culling features target the local master player.
◆ UpdateStatusUI()
| void PunBootstrap.UpdateStatusUI |
( |
string | msg | ) |
|
|
private |
Updates UI widgets (TMP label, connect/leave buttons) and writes to the console.
- Parameters
-
| msg | A human-readable status message. |
◆ _localPlayerGO
| GameObject PunBootstrap._localPlayerGO |
|
private |
◆ _provider
Shared provider assigned to PhotonNetwork.PrefabPool at runtime. Used to register and prewarm prefabs for pooled network instantiation.
◆ _spawnerStartedOnce
| bool PunBootstrap._spawnerStartedOnce |
|
private |
◆ connectButton
| Button PunBootstrap.connectButton |
|
private |
◆ defaultRoomName
| string PunBootstrap.defaultRoomName = "MegacrushPUNSample" |
|
private |
◆ leaveButton
| Button PunBootstrap.leaveButton |
|
private |
◆ maxPlayers
| byte PunBootstrap.maxPlayers = 8 |
|
private |
◆ playerPrefab
| GameObject PunBootstrap.playerPrefab |
|
private |
◆ playerSpawnPoint
| Transform PunBootstrap.playerSpawnPoint |
|
private |
◆ prewarmEach
| int PunBootstrap.prewarmEach = 8 |
|
private |
◆ punPrefabsToRegister
| GameObject [] PunBootstrap.punPrefabsToRegister |
|
private |
◆ roomNameInput
| TMP_InputField PunBootstrap.roomNameInput |
|
private |
◆ spawner
◆ statusLabel
| TMP_Text PunBootstrap.statusLabel |
|
private |
◆ vcam
| CinemachineVirtualCamera PunBootstrap.vcam |
|
private |
The documentation for this class was generated from the following file:
- D:/projects/Asset Store Packages/com.pixelwizards.runtimespawner/Samples~/RuntimeSpawnerPUNSample/Code/Runtime/Bootstrap/PUNBootstrap.cs