How do I serialize an array of characters to a file? The whole reason I’m doing it is so that you can’t just open up the file and edit the data but what I’m about to tell you shows otherwise. I create an array of characters and set arr[0] to ‘a’, arr[1] to ‘b’, and arr[2] to ‘c’. I then use .NET to serialize the array. I run it, open it and the file and it looks like this:
As stated above I don’t want someone to just open up the file and edit the data but this clearly shows it’s possible.
Script:
using UnityEngine;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class derp : MonoBehaviour{
public char[] arr = new char[3];
void Start(){
arr[0] = 'a';
arr[1] = 'b';
arr[2] = 'c';
FileStream stream = new FileStream(Application.dataPath+"/testing.wld", FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, arr);
stream.Close();
}
}
How do I fix this? Thanks.