Created
November 11, 2020 02:16
-
-
Save wallstop/0322247dbe1e9c6b8593acfbddcff8a7 to your computer and use it in GitHub Desktop.
Vector3Converter
This file contains 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 System; | |
using Assets.Scripts.Core.Extension; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using UnityEngine; | |
namespace Assets.Scripts.Core.Serialization.JsonConverters | |
{ | |
public sealed class Vector3Converter : JsonConverter | |
{ | |
public static readonly Vector3Converter Instance = new Vector3Converter(); | |
private Vector3Converter() { } | |
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | |
{ | |
JToken.FromObject(((Vector3)value).ToJsonString()).WriteTo(writer); | |
} | |
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, | |
JsonSerializer serializer) | |
{ | |
throw new NotImplementedException("Reading Vector3s are currently not supported"); | |
} | |
public override bool CanConvert(Type objectType) | |
{ | |
return objectType == typeof(Vector3); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment