Serialization encodes data as a stream of bytes; deserialization reads that stream back. Binary storage gives direct control over representation and can reduce save-file size, but the reader must consume fields in the same order they were written. section 7.1.1
Saving enemy data
A Unity save can use a FileStream with BinaryWriter to write an enemy count, then each enemy’s position. BinaryReader reads the values back in the same order. A short can store counts up to 32,767 using fewer bytes, but smaller types may require extra CPU work. section 7.1.1
Listing 7.5 Writing data in binary
string fileName = Application.persistentDataPath + "/DODSurvivor/gamedata.dat";
using (FileStream fs = File.Create(fileName))
using (BinaryWriter bw = new BinaryWriter(fs))
{
int numEnemies = gameData.EnemyPosition.Length;
bw.Write(numEnemies);
}See the Unity-oriented BinaryWriter example for writing an enemy count to a save file. section 7.1.1


























