Advertisement
Pro_Unit

IntReactivePropertyJsonConverter

Jun 24th, 2022
1,183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None
  1. using System;
  2. using Newtonsoft.Json;
  3. using UniRx;
  4. using UnityEngine;
  5.  
  6. public class IntReactivePropertyJsonConverter : JsonConverter<IntReactiveProperty>
  7. {
  8.     public override void WriteJson(JsonWriter writer, IntReactiveProperty value, JsonSerializer serializer)
  9.     {
  10.         Debug.Log(nameof(WriteJson));
  11.  
  12.         Debug.Log("value.Value = " + value.Value);
  13.  
  14.         writer.WriteValue(value.Value);
  15.     }
  16.  
  17.     public override IntReactiveProperty ReadJson(
  18.         JsonReader reader,
  19.         Type objectType,
  20.         IntReactiveProperty existingValue,
  21.         bool hasExistingValue,
  22.         JsonSerializer serializer)
  23.     {
  24.         Debug.Log(nameof(ReadJson));
  25.  
  26.         object readerValue = reader.Value;
  27.  
  28.         Debug.Log("readerValue = " + readerValue);
  29.  
  30.         var s = readerValue.ToString();
  31.  
  32.         Debug.Log("s = " + s);
  33.  
  34.         int value = int.Parse(s);
  35.  
  36.         Debug.Log("value = " + value);
  37.  
  38.         return new IntReactiveProperty(value);
  39.     }
  40. }
Advertisement
RAW Paste Data Copied
Advertisement