问题
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