Created
November 10, 2020 12:31
-
-
Save baba-s/ce9200b0468f6fda6fb5415ba8ce8459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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