Protobuf-net和Unity3D类型 [英] Protobuf-net and Unity3D types

查看:112
本文介绍了Protobuf-net和Unity3D类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Unity3d中的 protobuf-net 有疑问. 是否可以序列化unity3d类型:GameObject. 例如,我在类属性中具有GameObject类型,该类已序列化/反序列化吗?

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;}  // ???
}

对不起,我的英语.

推荐答案

您必须告诉protobuf-net您要序列化的类和属性.由于您无法用属性修饰GameObject,因此有不同的方法来实现.

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.

例如,您可以使用RuntimeTypeModel.Default进行此操作,这里是类Point的示例,它设置了要序列化的属性XY.

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");

在这种情况下,您的GameObject必须具有默认的构造函数.

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

这篇关于Protobuf-net和Unity3D类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆