|
Runtime Spawner 1.5.1
Generic Runtime spawn and instance pooling system for spawning random AI agents around a map. Works with ANY AI system easily.
|
Photon PUN–backed implementation of IObjectFactory. More...
Public Member Functions | |
| PUNObjectFactory (bool masterOnly=true) | |
| Creates a new PUN-backed object factory. | |
| ISpawnHandle | Spawn (SpawnRequest r) |
| Spawns a networked object via PhotonNetwork.Instantiate(string, Vector3, Quaternion, byte). | |
| Task< ISpawnHandle > | SpawnAsync (SpawnRequest r) |
| Asynchronously spawns a networked object. | |
Private Attributes | |
| readonly bool | _masterOnly |
Photon PUN–backed implementation of IObjectFactory.
This factory integrates the RuntimeSpawner system with Photon Unity Networking (PUN 2.x). It performs networked instantiation and destruction using PhotonNetwork.Instantiate(string, Vector3, Quaternion, byte) and PhotonNetwork.Destroy(UnityEngine.Object), ensuring that spawned objects replicate correctly across connected clients.
The prefab name or key must be registered with your custom IPunPrefabPool implementation (for example, PUNPoolPrefabProvider). This factory resolves the prefab key automatically using PUNPoolPrefabProvider.ResolveKey(GameObject).
When _masterOnly is enabled, only the Master Client will perform spawn operations. Other clients will automatically receive the instantiated object through PUN’s replication system.
Despawning an object uses PhotonNetwork.Destroy(UnityEngine.Object), which ensures that destruction events are also synchronized across all peers.
| MegaCrush.Spawner.PunAdapter.PUNObjectFactory.PUNObjectFactory | ( | bool | masterOnly = true | ) |
Creates a new PUN-backed object factory.
| masterOnly | If true, only the Master Client will perform spawn operations. If false, all clients may instantiate objects (for local simulation or testing). |
| ISpawnHandle MegaCrush.Spawner.PunAdapter.PUNObjectFactory.Spawn | ( | SpawnRequest | r | ) |
Spawns a networked object via PhotonNetwork.Instantiate(string, Vector3, Quaternion, byte).
| r | The spawn request containing prefab, position, rotation, and optional metadata. |
null if spawning was refused (e.g., non-master client or invalid prefab). This method should be called only on the authoritative client when _masterOnly is enabled.
The returned ISpawnHandle delegates destruction to PhotonNetwork.Destroy(UnityEngine.Object), which will invoke IPunPrefabPool.Destroy(GameObject) on all peers.
Implements MegaCrush.Spawner.IObjectFactory.
| Task< ISpawnHandle > MegaCrush.Spawner.PunAdapter.PUNObjectFactory.SpawnAsync | ( | SpawnRequest | r | ) |
Asynchronously spawns a networked object.
| r | The spawn request to process. |
Photon PUN performs instantiation synchronously, so this implementation simply wraps the synchronous result in a completed Task<TResult>.
Implements MegaCrush.Spawner.IObjectFactory.
|
private |