private void Serialize() { string _filePath = Application.dataPath + "/bytes.bytes"; if (_bytesInstance == null) { _bytesInstance = new SerializableClass(); } _bytesInstance.SerializableBool = true; _bytesInstance.SerializableDouble = Random.Range(-100.0f, 100.0f); _bytesInstance.SerializableFloat = Random.Range(-100.0f, 100.0f); _bytesInstance.SerializableInt = Random.Range(-100, 100); _bytesInstance.SerializableString = Guid.NewGuid().ToString(); var stream = File.Open(_filePath, FileMode.OpenOrCreate); stream.SetLength(0); var bytes = _bytesInstance.ToSafeProtoBufBytes(); stream.Write(bytes, 0, bytes.Length); stream.Close(); Debug.Log(string.Format("save result:{0},({1}bytes)", _bytesInstance, bytes.Length)); }
private void Awake() { _bytesInstance = DeSerialize(); }