Exemple #1
0
    public void RPC_Despawn(NetIncomingMessage msg, int objectId)
    {
        var net_actor = NetworkActorRegistry.GetById(objectId);

        NetworkRemoteCallSender.CallOnServer("RPC_RequestObjectDeregistration", net_actor.actor_id);
        NetworkActorRegistry.UnregisterActor(net_actor);
        GameObject.Destroy(net_actor.gameObject);
    }
Exemple #2
0
 public void Update()
 {
     if (Input.GetKeyDown(KeyCode.P))
     {
         NetworkRemoteCallSender.CallOnServer("RPC_RequestSpawn", "Prefabs/PlayerPrefab", new Vector3(UnityEngine.Random.Range(-5, 5), 0, 0), Quaternion.identity);
     }
     if (Input.GetKeyDown(KeyCode.O))
     {
         NetworkRemoteCallSender.CallOnServer("RPC_RequestDespawn");
     }
 }
Exemple #3
0
    public void RPC_Spawn(NetIncomingMessage msg, byte hostId, int objectId, string prefabName, Vector3 pos, Quaternion rot)
    {
        var game_object = (GameObject)GameObject.Instantiate(Resources.Load(prefabName), pos, rot);
        var net_actor   = game_object.GetComponent <NetworkActor>();

        net_actor.host_id     = hostId;
        net_actor.actor_id    = objectId;
        net_actor.is_owner    = LidPeer.instance.host_id == hostId;
        net_actor.prefab_name = prefabName;

        NetworkRemoteCallSender.CallOnServer("RPC_RequestObjectRegistration", net_actor.actor_id);
        NetworkActorRegistry.RegisterActor(net_actor);
    }
Exemple #4
0
    public void RPC_RequestDespawn(NetIncomingMessage msg)
    {
        var client_info = GetClientInfo(msg);

        if (client_info.has_spawned)
        {
            client_info.has_spawned = false;
            var net_actor = NetworkActorRegistry.GetById(client_info.actor_id);
            GameObject.Destroy(net_actor.gameObject);
            if (connected_clients.Count > 1)
            {
                NetworkRemoteCallSender.CallOnAllClients("RPC_Despawn", client_info.actor_id);
            }
        }
    }
Exemple #5
0
    public void RPC_RequestObjects(NetIncomingMessage msg)
    {
        var client = GetClientInfo(msg);

        foreach (var obj in NetworkActorRegistry.Objects)
        {
            if (obj != null)
            {
                NetworkRemoteCallSender.CallOnClient(
                    client, "RPC_Spawn",
                    obj.host_id, obj.actor_id, obj.prefab_name,
                    obj.transform.position, obj.transform.rotation
                    );
            }
        }
    }
Exemple #6
0
    protected override void OnStatusChanged(NetIncomingMessage nim)
    {
        switch (nim.SenderConnection.Status)
        {
        case NetConnectionStatus.Connected:
            var newclient = GetClientInfo(nim);
            connected_clients.Add(newclient);
            NetworkRemoteCallSender.CallOnClient(newclient, "RPC_Hello", newclient.host_id);
            break;

        case NetConnectionStatus.Disconnected:
            RPC_RequestDespawn(nim);
            connected_clients.Remove(GetClientInfo(nim));
            break;
        }
    }
Exemple #7
0
    public void RPC_RequestSpawn(NetIncomingMessage msg, string prefab_name, Vector3 pos, Quaternion rot)
    {
        var client_info = GetClientInfo(msg);
        var game_object = (GameObject)GameObject.Instantiate(Resources.Load(prefab_name), pos, rot);
        var obj         = game_object.GetComponent <NetworkActor>();

        obj.host_id          = client_info.host_id;
        client_info.actor_id = obj.actor_id = actor_id_counter++;
        obj.is_owner         = false;
        obj.owner            = client_info;
        obj.prefab_name      = prefab_name;

        client_info.has_spawned = true;

        NetworkRemoteCallSender.CallOnAllClients(
            "RPC_Spawn",
            obj.host_id, obj.actor_id, obj.prefab_name,
            obj.transform.position, obj.transform.rotation
            );
    }
Exemple #8
0
 public void RPC_Hello(NetIncomingMessage nim, byte host_id)
 {
     this.host_id = host_id;
     NetworkRemoteCallSender.CallOnServer("RPC_RequestObjects");
 }