I just watched that video on Unity 3D
Then I went to find the data file in question that was suppose to be serialized with binary and apparently unreadable. I opened it with MS-Wordpad and it is very readable. It is clearly simple text. Am I missing something here?
Thanks for your replys.
Here is my code:
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class GameController : MonoBehaviour {
public static GameController control;
public string firstname;
public string lastname;
public string number;
public string height;
public string weight;
public string shoots;
public string color;
void Awake () {
if (control == null) {
DontDestroyOnLoad (gameObject);
control = this;
} else if (control != this) {
Destroy (gameObject);
}
GameController.control.Load ();
}
public void Save()
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (Application.persistentDataPath + “/LH3sgK3h.dat”);
PlayerData data = new PlayerData ();
data.firstname = firstname;
data.lastname = lastname;
data.number = number;
data.height = height;
data.weight = weight;
data.shoots = shoots;
data.color = color;
bf.Serialize (file, data);
file.Close ();
}
public void Load()
{
if (File.Exists(Application.persistentDataPath + “/LH3sgK3h.dat”))
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + “/LH3sgK3h.dat”, FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize (file);
file.Close ();
firstname = data.firstname;
lastname = data.lastname;
number = data.number;
height = data.height;
weight = data.weight;
shoots = data.shoots;
color = data.color;
}
}
public void Reset()
{
if (File.Exists(Application.persistentDataPath + “/LH3sgK3h.dat”))
{
FileStream file = File.Delete (Application.persistentDataPath + “/LH3sgK3h.dat”);
}
}
}
[Serializable]
class PlayerData
{
public string firstname;
public string lastname;
public string number;
public string height;
public string weight;
public string shoots;
public string color;
}