Created
November 11, 2020 02:15
-
-
Save wallstop/e20b73b5f31687dcb68e4a98f9345b00 to your computer and use it in GitHub Desktop.
Vector2Converter
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 Vector2Converter : JsonConverter | |
{ | |
public static readonly Vector2Converter Instance = new Vector2Converter(); | |
private Vector2Converter() { } | |
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | |
{ | |
JToken.FromObject(((Vector2)value).ToJsonString()).WriteTo(writer); | |
} | |
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, | |
JsonSerializer serializer) | |
{ | |
throw new NotImplementedException("Reading Vector2s are currently not supported"); | |
} | |
public override bool CanConvert(Type objectType) | |
{ | |
return objectType == typeof(Vector2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment