quakeball/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs

75 lines
2.2 KiB
C#
Raw Normal View History

2020-08-07 22:09:31 +02:00
using UnityEngine;
using NeonTea.Quakeball.TeaNet.Packets;
using System.Collections.Generic;
namespace NeonTea.Quakeball.Networking.Packets {
public class MultiplePlayerUpdatesPckt : Packet {
public List<PlayerUpdatePckt> Updates = new List<PlayerUpdatePckt>();
public MultiplePlayerUpdatesPckt() { }
public MultiplePlayerUpdatesPckt(List<NetPlayer> players) {
foreach (NetPlayer p in players) {
if (p.Controlled == null) {
continue;
}
2020-08-07 23:59:51 +02:00
Updates.Add(p.Controlled.CreateUpdatePacket(p.Id));
2020-08-07 22:09:31 +02:00
}
}
public override void Read(ByteBuffer buffer) {
Updates.Clear();
int count = buffer.ReadInt();
for (int i = 0; i < count; i++) {
PlayerUpdatePckt pckt = new PlayerUpdatePckt();
pckt.Read(buffer);
Updates.Add(pckt);
}
}
public override void Write(ByteBuffer buffer) {
buffer.Write(Updates.Count);
foreach (PlayerUpdatePckt p in Updates) {
p.Write(buffer);
}
}
}
2020-08-07 23:57:11 +02:00
public class MultipleSyncsPckt : Packet {
2020-08-08 00:21:02 +02:00
public List<PlayerSyncPacket> Syncs = new List<PlayerSyncPacket>();
2020-08-07 23:57:11 +02:00
public MultipleSyncsPckt() { }
public MultipleSyncsPckt(List<NetPlayer> players) {
foreach (NetPlayer p in players) {
if (p.Controlled == null) {
continue;
}
PlayerSyncPacket pckt = p.Controlled.CreateSyncPacket(p.Id, p.Unsynced);
p.Unsynced = false;
Syncs.Add(pckt);
2020-08-07 23:57:11 +02:00
}
}
public override void Read(ByteBuffer buffer) {
2020-08-08 00:21:02 +02:00
Syncs.Clear();
2020-08-07 23:57:11 +02:00
int count = buffer.ReadInt();
for (int i = 0; i < count; i++) {
PlayerSyncPacket pckt = new PlayerSyncPacket();
pckt.Read(buffer);
2020-08-08 00:21:02 +02:00
Syncs.Add(pckt);
2020-08-07 23:57:11 +02:00
}
}
public override void Write(ByteBuffer buffer) {
2020-08-08 00:21:02 +02:00
buffer.Write(Syncs.Count);
foreach (PlayerSyncPacket p in Syncs) {
2020-08-07 23:57:11 +02:00
p.Write(buffer);
}
}
}
2020-08-07 22:09:31 +02:00
}