Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using JetBrains.Annotations;
using System;
using UnityEngine;
namespace Kogane
public static class JsonUnityEngineCaching
private struct JsonData
[SerializeField][UsedImplicitly] public int cacheCount;
[SerializeField][UsedImplicitly] public bool ready;
[SerializeField][UsedImplicitly] public bool compressionEnabled;
[SerializeField][UsedImplicitly] public JsonUnityEngineCache defaultCache;
[SerializeField][UsedImplicitly] public JsonUnityEngineCache currentCacheForWriting;
public static string Get()
var jsonData = new JsonData
cacheCount = Caching.cacheCount,
ready = Caching.ready,
compressionEnabled = Caching.compressionEnabled,
defaultCache = new JsonUnityEngineCache( Caching.defaultCache ),
currentCacheForWriting = new JsonUnityEngineCache( Caching.currentCacheForWriting ),
return JsonUtility.ToJson( jsonData, true );
public sealed class JsonUnityEngineCache
[SerializeField][UsedImplicitly] public bool valid;
[SerializeField][UsedImplicitly] public bool ready;
[SerializeField][UsedImplicitly] public bool readOnly;
[SerializeField][UsedImplicitly] public string path;
[SerializeField][UsedImplicitly] public int index;
[SerializeField][UsedImplicitly] public long spaceFree;
[SerializeField][UsedImplicitly] public long maximumAvailableStorageSpace;
[SerializeField][UsedImplicitly] public long spaceOccupied;
[SerializeField][UsedImplicitly] public int expirationDelay;
public JsonUnityEngineCache( Cache cache )
valid = cache.valid;
ready = cache.ready;
readOnly = cache.readOnly;
path = cache.path;
index = cache.index;
spaceFree = cache.spaceFree;
maximumAvailableStorageSpace = cache.maximumAvailableStorageSpace;
spaceOccupied = cache.spaceOccupied;
expirationDelay = cache.expirationDelay;
public override string ToString()
return JsonUtility.ToJson( this, true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment