1.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using ProtoBuf;
public class my30 : MonoBehaviour
{
// Use this for initialization
void Start()
{
//myUser user = new myUser();
//user.ID = 100;
//user.Username = "siki";
//user.Password = "123456";
//user.Levl = 100;
//user._UserType = myUser.UserType.Master;
//FileStream fs = File.Create(Application.dataPath + "/user.bin");
//Serializer.Serialize<myUser>(fs, user);
//fs.Close();
myUser user = null;
using (var fs = File.OpenRead(Application.dataPath + "/user.bin"))
{
user= Serializer.Deserialize<myUser>(fs);
}
print(user.ID);
print(user._UserType);
print(user.Username);
print(user.Password);
print(user.Levl);
}
// Update is called once per frame
void Update()
{
}
}
2.
using System.Collections; using System.Collections.Generic; using UnityEngine; using ProtoBuf; [ProtoContract] public class myUser { [ProtoMember(1)] public int ID { get; set; } [ProtoMember(2)] public string Username { get; set; } [ProtoMember(3)] public string Password { get; set; } [ProtoMember(4)] public int Levl { get; set; } [ProtoMember(5)] public UserType _UserType { get; set; } public enum UserType { Master, Warrior } }