导出ios平台的注意:把工程设置为.Net 2.0 subset (否则ios平台不能运行)
下载protobuf-net源码http://download.youkuaiyun.com/detail/qwezcl/9510727
建立一个新的文件smcs.rsp ,内容是-unsafe
把protobuf-net源码拷贝unity工程中
例子:
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine.UI;
using AOT;
using ProtoBuf;
public class Test2 : MonoBehaviour {
void Start () {
Test test=new Test();
test.id=10;
test.data="ssssss用户家";
byte[] data;
using (MemoryStream ms = new MemoryStream())
{
Serializer.Serialize<Test>(ms, test);
data = new byte[ms.Length];
ms.Position= 0;
ms.Read(data, 0, data.Length);
Debug.Log(data.Length+"-----");
}
using(MemoryStream ms = new MemoryStream()){
ms.Write(data,0,data.Length);
ms.Position = 0;
Test chatMsg = Serializer.Deserialize<Test>(ms);
Debug.Log(chatMsg.data);
Debug.Log(chatMsg.data+chatMsg.id);
}
}
// Update is called once per frame
void Update () {
}
}
[ProtoContract]
public struct Test {
[ProtoMember(1)]
public int id;
[ProtoMember(2)]
public string data;
// public List<String> data
// {
// get;
// set;
// }
}