Skip to content

Instantly share code, notes, and snippets.

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