Beispiel #1
0
        public void Read(NetPacketReader reader, int frame, bool discardOutOfOrderPackets)
        {
            NetDebug.Log($"Receiving packet with remote frame <b>{frame}</b> at local frame <b>{world.Frame}</b>", LogType.Packet);

            if (!arbiter)
            {
                world.Frame = frame;

                int inputLength     = reader.GetInt();
                int statefulsLength = reader.GetInt();
                int fieldsLength    = reader.GetInt();

                ReadInput(reader, inputLength);
                ReadStateful(reader, statefulsLength, frame, discardOutOfOrderPackets);
                ReadFields(reader, fieldsLength, frame, discardOutOfOrderPackets);
            }
            else
            {
                int inputLength = reader.GetInt();
                ReadInput(reader, inputLength);
            }

            if (!reader.EndOfData)
            {
                NetDebug.LogError($"ReadState method did not read all bytes from the NetPacketReader; it is intended to always consume all bytes, regardless of whether the data is applied to the StatefulWorld.");
            }
        }
Beispiel #2
0
        public void AssignOwnership(StatefulObject statefulObject, int peerId)
        {
            if (role == Role.Server)
            {
                NetDataWriter writer = new NetDataWriter();
                writer.Put((byte)PacketType.Ownership);
                writer.Put(statefulObject.ID);

                NetPeer peer = netManager.ConnectedPeerList.Where(x => x.Id == peerId - 1).First();
                peer.Send(writer, DeliveryMethod.ReliableUnordered);
            }
            else
            {
                NetDebug.LogError("Attempting to assign ownership with a non-server peer.");
            }
        }