Returns a copy of internal array of bytes the writer is using, it copies only the bytes used.
public byte[] ToArray() { byte[] destinationArray = new byte[this.m_Buffer.AsArraySegment().Count]; Array.Copy(this.m_Buffer.AsArraySegment().Array, destinationArray, this.m_Buffer.AsArraySegment().Count); return destinationArray; }
public void TestNetworkWriterSize() { var writer = new UnityEngine.Networking.NetworkWriter(); writer.Write((byte)42); byte[] bytes = writer.ToArray(); Assert.AreEqual(1, bytes.Length); }