2

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..

David
  • 15,894
  • 22
  • 55
  • 66
Azamat
  • 53
  • 9

1 Answers1

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.

thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110