Beispiel #1
0
    private IEnumerator SendObjectsToClient_Coroutine(NetPeer peer, NetDataWriter writer)
    {
        Dictionary <int, GameObject> .Enumerator enumerator = spawnedObjects.GetEnumerator();

        while (enumerator.MoveNext())
        {
            int        instanceID = enumerator.Current.Key;
            GameObject obj        = enumerator.Current.Value;
            int        maxAmount  = spawnedObjects.Count;

            WorldObject objWorld = obj.GetComponent <WorldObject>();

            if (obj != null && objWorld != null)
            {
                Packet02CreateWorldObject createObject = new Packet02CreateWorldObject(instanceID, objWorld.UNIQUE_ID, obj.transform.position, obj.transform.eulerAngles, maxAmount);
                // Create and send data
                createObject.Serialize(writer);
                peer.Send(writer, DeliveryMethod.ReliableUnordered);
            }

            yield return(null);
        }

        enumerator.Dispose();
        yield return(0);
    }
Beispiel #2
0
    public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
    {
        int packetID = reader.GetInt();

        switch (packetID)
        {
        case 2:
            Packet02CreateWorldObject worldPacket = new Packet02CreateWorldObject();
            worldPacket.Deserialize(reader);
            worldPacket.ExecuteClientSide();
            break;

        case 3:
            Packet03CreatePlayer createPlayer = new Packet03CreatePlayer();
            createPlayer.Deserialize(reader);
            createPlayer.ExecuteClientSide();
            break;

        case 4:
            Packet04PlayerMove playerMove = new Packet04PlayerMove();
            playerMove.Deserialize(reader);
            playerMove.ExecuteClientSide();
            break;
        }
    }