class NetworkSpawner (Niantic.ARDK.Networking.HLAPI.Object.Unity.NetworkSpawner)

Overview

A static class that handles the replication and network spawning of NetworkedUnityObjects for all peers across the network. Also handles the network destruction of spawned objects. More…

class NetworkSpawner {
public:
    // structs

    struct SpawnMessage;

    // events

    static event NetworkObjectDestroyed();
    static event NetworkObjectSpawned();

    // methods

    static void LoadManifest(PrefabManifest manifest);
    static void NetworkDestroy(this NetworkedUnityObject networkedObject);

    static NetworkedUnityObject NetworkSpawn(
        this NetworkedUnityObject spawnObject,
        IMultipeerNetworking networking,
        Vector3? position = null,
        Quaternion? rotation = null,
        Role? startingLocalRole = null,
        NetworkId? newNetId = null,
        List<IPeer> targetPeers = null
    );

    static NetworkedUnityObject NetworkSpawn(
        this NetworkedUnityObject spawnObject,
        Vector3? position = null,
        Quaternion? rotation = null,
        Role? startingLocalRole = null,
        NetworkId? newNetId = null,
        List<IPeer> targetPeers = null
    );

    static void UnloadManifest(PrefabManifest manifest);
};

Detailed Documentation

A static class that handles the replication and network spawning of NetworkedUnityObjects for all peers across the network. Also handles the network destruction of spawned objects.

Methods

static void LoadManifest(PrefabManifest manifest)

Loads all prefabs in the PrefabManifest to prepare for network spawning. This is automatically called by the NetworkSceneSpawnManifest MonoBehaviour.

Parameters:

manifest

Manifest containing prefabs to load into memory

static void NetworkDestroy(this NetworkedUnityObject networkedObject)

Check if we are allowed to propagate the destruction message, then send it if allowed. If no one had previously destroyed the object, destroy it after sending the message. Only objects that were network spawned can be network destroyed

Parameters:

networkedObject

The object to be destroyed

static NetworkedUnityObject NetworkSpawn(
    this NetworkedUnityObject spawnObject,
    IMultipeerNetworking networking,
    Vector3? position = null,
    Quaternion? rotation = null,
    Role? startingLocalRole = null,
    NetworkId? newNetId = null,
    List<IPeer> targetPeers = null
)

Locally instantiates a prefab with given starting parameters, then sends a message across the network for all listening peers to also instantiate the same prefab.

Parameters:

spawnObject

The prefab to spawn

networking

The networking stack on which to spawn the object

position

The initial position of the object

rotation

The initial rotation of the object

startingLocalRole

The starting role of the local peer

newNetId

The network ID of the new object, will be automatically assigned if empty

targetPeers

The peers for which to spawn the object

Returns:

The spawned NetworkedUnityObject

static NetworkedUnityObject NetworkSpawn(
    this NetworkedUnityObject spawnObject,
    Vector3? position = null,
    Quaternion? rotation = null,
    Role? startingLocalRole = null,
    NetworkId? newNetId = null,
    List<IPeer> targetPeers = null
)

Locally instantiates a prefab with given starting parameters, then sends a message across the network for all listening peers to also instantiate the same prefab.

Parameters:

spawnObject

The prefab to spawn

position

The initial position of the object

rotation

The initial rotation of the object

startingLocalRole

The starting role of the local peer

newNetId

The network ID of the new object, will be automatically assigned if empty

targetPeers

The peers for which to spawn the object

Returns:

The spawned NetworkedUnityObject

static void UnloadManifest(PrefabManifest manifest)

Unloads prefabs loaded from the PrefabManifest from memory. This is called by the NetworkSceneSpawnManifest MonoBehaviour

Parameters:

manifest

Manifest containing prefabs to unload from memory