Esempio n. 1
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            EN_Protocol.SendTCP(stream, new EN_PacketMessage("Hello!"));
        }
        if (Input.GetKeyDown(KeyCode.F1))
        {
            GameObject go = Instantiate(EN_NetworkPrefabs.Prefab(EN_PREFABS.Cube), Vector3.zero, Quaternion.identity);
            go.AddComponent <EN_SyncTransform>().syncFrameRate = 10;
            go.GetComponent <EN_SyncTransformClient>().enabled = false;

            Vector3 pos = go.transform.position;
            Vector3 rot = go.transform.rotation.eulerAngles;

            EN_PacketSpawnObject packet;
            packet.packet_type       = EN_TCP_PACKET_TYPE.SPAWN_OBJECT;
            packet.packet_prefab     = EN_PREFABS.Cube;
            packet.packet_network_id = go.GetInstanceID();
            packet.tX = pos.x; packet.tY = pos.y; packet.tZ = pos.z;
            packet.rX = rot.x; packet.rY = rot.y; packet.rZ = rot.z;

            EN_Protocol.SendTCP(stream, packet);
        }
        if (Input.GetKeyDown(KeyCode.F2))
        {
            //remove
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                int id = hit.transform.gameObject.GetInstanceID();
                Destroy(hit.transform.gameObject);


                EN_PacketRemoveObject packet;
                packet.packet_type       = EN_TCP_PACKET_TYPE.REMOVE_OBJECT;
                packet.packet_network_id = id;

                EN_Protocol.SendTCP(stream, packet);
            }
        }

        udp_in.text = TrafficInUDP().ToString();
        tcp_in.text = TrafficInTCP().ToString();

        udpBytesIn = 0;
        tcpBytesIn = 0;
    }
Esempio n. 2
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            EN_Protocol.SendTCP(stream, new EN_PacketMessage("Hello!"));
        }
        if (Input.GetKeyDown(KeyCode.F1))
        {
            GameObject go = SpawnObject(EN_PREFABS.Cube, new Vector3(UnityEngine.Random.Range(-5, 5), 0, 5), Vector3.zero);

            Vector3 pos = go.transform.position;
            Vector3 rot = go.transform.rotation.eulerAngles;

            EN_PacketSpawnObject packet;
            packet.packet_type       = EN_TCP_PACKET_TYPE.SPAWN_OBJECT;
            packet.packet_prefab     = EN_PREFABS.Cube;
            packet.packet_network_id = go.GetInstanceID();
            packet.tX = pos.x; packet.tY = pos.y; packet.tZ = pos.z;
            packet.rX = rot.x; packet.rY = rot.y; packet.rZ = rot.z;

            EN_Protocol.SendTCP(stream, packet);
        }
        if (Input.GetKeyDown(KeyCode.F2))
        {
            //remove
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                int id = hit.transform.gameObject.GetInstanceID();
                Destroy(hit.transform.gameObject);


                EN_PacketRemoveObject packet;
                packet.packet_type       = EN_TCP_PACKET_TYPE.REMOVE_OBJECT;
                packet.packet_network_id = id;

                EN_Protocol.SendTCP(stream, packet);
            }
        }

        udp_in.text = TrafficInUDP().ToString();
        tcp_in.text = TrafficInTCP().ToString();

        udpBytesIn = 0;
        tcpBytesIn = 0;
    }
Esempio n. 3
0
        private void ResendStackTCP(TcpClient client)
        {
            NetworkStream stream = client.GetStream();

            // Re-broadcast all old messages
            for (int i = 0; i < packet_stack.Count; i++)
            {
                //stream.Write(BitConverter.GetBytes(packet_stack[i].Length), 0, 4);
                //stream.Write(packet_stack[i], 0, packet_stack[i].Length);
            }

            foreach (int key in objects.Keys)
            {
                EN_Protocol.SendTCP(stream, objects[key]);
            }
            for (int i = 0; i < networkIDs.Count; i++)
            {
            }
        }