Skip to content

Instantly share code, notes, and snippets.

@wallstop
Created November 11, 2020 02:15
Show Gist options
  • Save wallstop/e20b73b5f31687dcb68e4a98f9345b00 to your computer and use it in GitHub Desktop.
Save wallstop/e20b73b5f31687dcb68e4a98f9345b00 to your computer and use it in GitHub Desktop.
Vector2Converter
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