|
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.
|
Implementation of IObjectFactory that spawns networked objects using Photon Fusion. More...
Public Member Functions | |
| FusionObjectFactory (NetworkRunner runner, bool serverOnly=true) | |
| Creates a new Fusion-backed object factory. | |
| ISpawnHandle | Spawn (SpawnRequest r) |
| Spawns a networked object using NetworkRunner.Spawn(NetworkObject, Vector3, Quaternion, PlayerRef). | |
| Task< ISpawnHandle > | SpawnAsync (SpawnRequest r) |
| Asynchronously spawns a networked object. | |
| void | Prewarm (SpawnEntry entry, int count) |
| Prewarms the pool for a given prefab via the runner’s INetworkObjectProvider. | |
Private Attributes | |
| readonly NetworkRunner | _runner |
| readonly bool | _serverOnly |
Implementation of IObjectFactory that spawns networked objects using Photon Fusion.
Integrates with a live NetworkRunner to perform network instantiation via NetworkRunner.Spawn(NetworkObject, Vector3, Quaternion, PlayerRef) and teardown via NetworkRunner.Despawn(NetworkObject). Spawned instances are standard Fusion NetworkObjects and replicate to clients automatically.
In typical usage, the RuntimeSpawner runs only on the authoritative instance (host/server). When serverOnly is true, client calls to Spawn(SpawnRequest) are ignored and return null; objects appear on clients through replication.
Pooling and prewarming are delegated to the runner’s INetworkObjectProvider, e.g. FusionPoolObjectProviderBehaviour (MonoBehaviour on the runner) or FusionPoolProvider (core provider passed via StartGameArgs.ObjectProvider). Those providers may internally bridge to a project-specific IPoolAdapter for prefab reuse.
| MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.FusionObjectFactory | ( | NetworkRunner | runner, |
| bool | serverOnly = true ) |
Creates a new Fusion-backed object factory.
| runner | A running NetworkRunner responsible for spawn/replication. |
| serverOnly | If true, only the authoritative host/server performs spawns. Non-authoritative callers get null and no error is logged. Set to false only with a custom flow that allows client-initiated spawns under controlled conditions. |
| void MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.Prewarm | ( | SpawnEntry | entry, |
| int | count ) |
Prewarms the pool for a given prefab via the runner’s INetworkObjectProvider.
| entry | Spawn entry referencing the prefab to prewarm. |
| count | Number of instances to prepare for reuse. |
When the runner’s NetworkRunner.ObjectProvider is FusionPoolObjectProviderBehaviour or FusionPoolProvider, this forwards to their respective Prewarm(GameObject, int) method. If the provider does not support pooling or is a different implementation, this method safely no-ops (with a one-time warning).
Requires a running runner and a valid prefab reference; invalid inputs are ignored without logging.
Implements MegaCrush.Spawner.IPrewarmableFactory.
| ISpawnHandle MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.Spawn | ( | SpawnRequest | r | ) |
Spawns a networked object using NetworkRunner.Spawn(NetworkObject, Vector3, Quaternion, PlayerRef).
| r | Spawn request containing prefab (must include NetworkObject), transform, and optional owner (as PlayerRef or PlayerRef.None). |
null if spawning is skipped/refused (no runner, missing NetworkObject, or non-authoritative when serverOnly is enabled). Requires authority when serverOnly is true (i.e., _runner must be a server/host). Clients will receive the object through Fusion replication.
The returned handle’s despawn delegates to NetworkRunner.Despawn(NetworkObject) when the caller has authority; otherwise the request is ignored.
Implements MegaCrush.Spawner.IObjectFactory.
| Task< ISpawnHandle > MegaCrush.Spawner.FusionAdapter.FusionObjectFactory.SpawnAsync | ( | SpawnRequest | r | ) |
Asynchronously spawns a networked object.
| r | The spawn request to process. |
Fusion’s spawn API is immediate; this method returns a completed task for API symmetry.
Implements MegaCrush.Spawner.IObjectFactory.
|
private |
|
private |