-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vector3Surrogate.cs
37 lines (35 loc) · 1.01 KB
/
Vector3Surrogate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Runtime.Serialization;
using UnityEngine;
public class Vector3Surrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
Vector3 vector3 = (Vector3)obj;
info.AddValue("x", vector3.x);
info.AddValue("y", vector3.y);
info.AddValue("z", vector3.z);
}
public object SetObjectData(
object obj,
SerializationInfo info,
StreamingContext context,
ISurrogateSelector selector)
{
Vector3 vector3 = (Vector3)obj;
try
{
vector3.x = (float)info.GetDecimal("x");
vector3.y = (float)info.GetDecimal("y");
vector3.z = (float)info.GetDecimal("z");
}
catch
{
Debug.Log((object)"Failed to load vector data, setting to starting pos");
vector3.x = 88.21f;
vector3.y = 16.41f;
vector3.z = -139.86f;
}
return (object)vector3;
}
}