Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created November 10, 2020 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baba-s/ce9200b0468f6fda6fb5415ba8ce8459 to your computer and use it in GitHub Desktop.
Save baba-s/ce9200b0468f6fda6fb5415ba8ce8459 to your computer and use it in GitHub Desktop.
using JetBrains.Annotations;
using System;
using UnityEngine;
namespace Kogane
{
public static class JsonUnityEngineCaching
{
[Serializable]
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 );
}
}
[Serializable]
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