unity中使用protobuf(兼容ios平台) - Go语言中文社区

unity中使用protobuf(兼容ios平台)


导出ios平台的注意:把工程设置为.Net 2.0 subset (否则ios平台不能运行)

下载protobuf-net源码http://download.csdn.net/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;  
    //    }  
} 



版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qwezcl/article/details/51321963
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-04-19 12:47:20
  • 阅读 ( 1462 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢