Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Bolt;
using UdpKit;
//using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class ListOfIntToken : IProtocolToken
{
public List intList;
public int byteArraySize;
public void Read(UdpPacket packet)
{
byteArraySize = packet.ReadInt();
var objectBytes = packet.ReadByteArray(byteArraySize);
var mStream = new MemoryStream();
var binFormatter = new BinaryFormatter();
mStream.Write(objectBytes, 0, objectBytes.Length);
mStream.Position = 0;
intList = binFormatter.Deserialize(mStream) as List;
}
public void Write(UdpPacket packet)
{
var binFormatter = new BinaryFormatter();
var mStream = new MemoryStream();
binFormatter.Serialize(mStream, intList);
//byte[] bytes = userId.Select(x => (byte)x).ToArray();
var byteArray = mStream.ToArray();
byteArraySize = byteArray.Length;
packet.WriteInt(byteArraySize);
packet.WriteByteArray(byteArray);
}
}
Код: Выделить всё
WriteПодробнее здесь: https://stackoverflow.com/questions/650 ... with-event