Protobuf-net and Unity3D types

岁酱吖の 提交于 2019-12-24 04:42:13

问题


I have question about protobuf-net in Unity3d. Is it possible to serialize unity3d types: GameObject. Example, I have in class property with type GameObject, this class serializedd/deserialized?

using ProtoBuf;
using UnityEngine;
...

[ProtoContract]  
public class Example 
{
   [ProtoMember(1)]
   public int Count {get;set;}
   [ProtoMember(2)]
   public string Name {get;set;}
   [ProtoMember(3)]
   public GameObject MyGameObject {get;set;}  // ???
}

Sorry, my english..


回答1:


You have to tell protobuf-net which classes and properties you want to serialize. As you can't decorate GameObject with attributes, there is different means to do that.

You can do this for example with RuntimeTypeModel.Default, here an example for class Point, it sets properties X and Y to be serialized.

RuntimeTypeModel.Default
       .Add(typeof(System.Windows.Point), false).Add("X", "Y");

Your GameObject will have to have a default constructor in this case.



来源:https://stackoverflow.com/questions/25987108/protobuf-net-and-unity3d-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!