コード例 #1
0
    private void TranslateUDP(EN_UDP_PACKET_TYPE type, byte[] bytes)
    {
        if (type == EN_UDP_PACKET_TYPE.TRANSFORM)
        {
            EN_PacketTransform packet = EN_Protocol.BytesToObject <EN_PacketTransform>(bytes);

            GameObject go = EN_NetworkObject.Find(packet.packet_network_id);
            if (go != null)
            {
                go.GetComponent <EN_SyncTransformClient>().Translate(packet.tX, packet.tY, packet.tZ, packet.rX, packet.rY, packet.rZ, packet.vX, packet.vY, packet.vZ);
            }
        }
    }
コード例 #2
0
    private void TranslateTCP(EN_TCP_PACKET_TYPE type, byte[] bytes)
    {
        if (type == EN_TCP_PACKET_TYPE.CONNECT)
        {
            // Someone connected and we want to establish who it is
            EN_PacketConnect packet = EN_Protocol.BytesToObject <EN_PacketConnect>(bytes);

            if (packet.packet_client_guid.Equals(EN_ClientSettings.CLIENT_GUID) == true)
            {
                packet.packet_client_name += " (you)";
            }

            AddClient(packet.packet_client_guid, packet.packet_client_name);
        }
        if (type == EN_TCP_PACKET_TYPE.GAME_STATE)
        {
            EN_PacketGameState packet = EN_Protocol.BytesToObject <EN_PacketGameState>(bytes);
        }
        if (type == EN_TCP_PACKET_TYPE.SPAWN_OBJECT)
        {
            EN_PacketSpawnObject packet = EN_Protocol.BytesToObject <EN_PacketSpawnObject>(bytes);
            Vector3    pos = new Vector3(packet.tX, packet.tY, packet.tZ);
            Quaternion rot = Quaternion.Euler(packet.rX, packet.rY, packet.rZ);
            GameObject go  = Instantiate(EN_NetworkPrefabs.Prefab(packet.packet_prefab), pos, rot);
            go.AddComponent <EN_NetworkObject>().network_id = packet.packet_network_id;

            EN_NetworkObject.Add(packet.packet_network_id, go);

            ConsoleMessage(string.Format("Spawned {0} with network ID {1}", go.name, packet.packet_network_id));
        }
        if (type == EN_TCP_PACKET_TYPE.REMOVE_OBJECT)
        {
            EN_PacketRemoveObject packet = EN_Protocol.BytesToObject <EN_PacketRemoveObject>(bytes);

            GameObject go = EN_NetworkObject.Find(packet.packet_network_id);
            string     n  = go.name;
            EN_NetworkObject.Remove(packet.packet_network_id);
            Destroy(go);

            ConsoleMessage(string.Format("Removed {0} with network ID {1}", n, packet.packet_network_id));
        }
    }