Created
September 4, 2017 01:56
-
-
Save DCCoder90/902d6c82c176b5b4cf9b3743f685f173 to your computer and use it in GitHub Desktop.
A serialization surrogate to allow the serialization of Vector3's with Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Runtime.Serialization; | |
public class Vector3SerializationSurrogate : ISerializationSurrogate { | |
// Method called to serialize a Vector3 object | |
public void GetObjectData(System.Object obj, SerializationInfo info, StreamingContext context) { | |
Vector3 v3 = (Vector3)obj; | |
info.AddValue("x", v3.x); | |
info.AddValue("y", v3.y); | |
info.AddValue("z", v3.z); | |
} | |
// Method called to deserialize a Vector3 object | |
public System.Object SetObjectData(System.Object obj, SerializationInfo info, | |
StreamingContext context, ISurrogateSelector selector) { | |
Vector3 v3 = (Vector3)obj; | |
v3.x = (float)info.GetValue("x", typeof(float)); | |
v3.y = (float)info.GetValue("y", typeof(float)); | |
v3.z = (float)info.GetValue("z", typeof(float)); | |
obj = v3; | |
return obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment