Пример #1
0
        public void StartHost(GameObject canvas)
        {
            canvas.SetActive(false);

            Debug.LogError("starting host");

            netListener = new EventBasedNetListener();
            netListener.PeerConnectedEvent += (client) =>
            {
                Debug.LogError($"Connected to client: {client}");
                Debug.LogError("Sending InitialTickPacket");
                SendPacket(new InitialTickPacket {
                    tick = Tick
                }, DeliveryMethod.ReliableUnordered);
            };

            netListener.ConnectionRequestEvent += (request) =>
            {
                request.Accept();
            };

            netListener.NetworkReceiveEvent += (peer, reader, deliveryMethod) =>
            {
                packetProcessor.ReadAllPackets(reader);
            };

            packetProcessor = new NetPacketProcessor();
            writer          = new NetDataWriter();
            PacketRegistrar.RegisterPackets(packetProcessor);

            netManager = new NetManager(netListener);
            netManager.Start(12345);

            ticking = true;
        }
Пример #2
0
        public void StartClient(GameObject canvas)
        {
            canvas.SetActive(false);

            Debug.LogError("starting client");

            netListener = new EventBasedNetListener();
            netListener.PeerConnectedEvent += (server) =>
            {
                Debug.LogError($"Connected to server: {server}");
            };

            netListener.ConnectionRequestEvent += (request) =>
            {
                request.Accept();
            };

            netListener.NetworkReceiveEvent += (peer, reader, deliveryMethod) =>
            {
                packetProcessor.ReadAllPackets(reader);
            };

            packetProcessor = new NetPacketProcessor();
            writer          = new NetDataWriter();
            PacketRegistrar.RegisterPackets(packetProcessor);

            netManager = new NetManager(netListener);
            netManager.Start();
            netManager.Connect("localhost", 12345, "");

            connected = true;
        }