Runtime Spawner 1.5.0
Generic Runtime spawn and instance pooling system for spawning random AI agents around a map. Works with ANY AI system easily.
Loading...
Searching...
No Matches
PunBootstrap Class Referencesealed

Minimal Photon PUN 2 bootstrap for sample/demo scenes. More...

Inheritance diagram for PunBootstrap:

Public Member Functions

void ConnectOrStart ()
 Connects to Photon if needed; otherwise directly joins/creates a room. Wire this to a UI button for quick testing.
 
override void OnConnectedToMaster ()
 
override void OnDisconnected (DisconnectCause cause)
 
override void OnJoinedRoom ()
 
override void OnLeftRoom ()
 
override void OnPlayerEnteredRoom (Player newPlayer)
 
override void OnPlayerLeftRoom (Player otherPlayer)
 
override void OnMasterClientSwitched (Player newMasterClient)
 

Private Member Functions

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.
 

Private Attributes

RuntimeSpawner spawner
 
GameObject playerPrefab
 
GameObject[] punPrefabsToRegister
 
int prewarmEach = 8
 
Transform playerSpawnPoint
 
CinemachineVirtualCamera vcam
 
TMP_InputField roomNameInput
 
Button connectButton
 
Button leaveButton
 
TMP_Text statusLabel
 
string defaultRoomName = "MegacrushPUNSample"
 
byte maxPlayers = 8
 
GameObject _localPlayerGO
 
bool _spawnerStartedOnce
 
PUNPoolPrefabProvider _provider
 Shared provider assigned to PhotonNetwork.PrefabPool at runtime. Used to register and prewarm prefabs for pooled network instantiation.
 

Detailed Description

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:

  1. Drop this component into a scene and assign references (player prefab, optional spawner, camera, UI).
  2. Ensure your prefabs have a PUNPrefabKey (recommended) or rely on the prefab name as the key.
  3. 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.

Member Function Documentation

◆ 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
msgA human-readable status message.

Member Data Documentation

◆ _localPlayerGO

GameObject PunBootstrap._localPlayerGO
private

◆ _provider

PUNPoolPrefabProvider PunBootstrap._provider
private

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

RuntimeSpawner PunBootstrap.spawner
private

◆ statusLabel

TMP_Text PunBootstrap.statusLabel
private

◆ vcam

CinemachineVirtualCamera PunBootstrap.vcam
private

The documentation for this class was generated from the following file: