Advertisement
Pertinate

Untitled

Nov 10th, 2014
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using SimpleJSON;
  4.  
  5. namespace Utils.Loaders
  6. {
  7.     public class JSONLoader
  8.     {
  9.         public const string PATH_PREFIX = "Data/JSON/";
  10.  
  11.         private static Dictionary<string, JSONNode> CachedJSONNodes = new Dictionary<string, JSONNode>();
  12.  
  13.         public static JSONNode Load(string JSONFilePath, bool cache = true)
  14.         {
  15.             if (CachedJSONNodes.ContainsKey(JSONFilePath) && cache)
  16.                 return CachedJSONNodes[JSONFilePath];
  17.             else if (cache)
  18.                 return CachedJSONNodes[JSONFilePath] = JSON.Parse(Resources.Load<TextAsset>(PATH_PREFIX + JSONFilePath).text);
  19.             else
  20.                 return JSON.Parse(Resources.Load<TextAsset>(PATH_PREFIX + JSONFilePath).text);
  21.         }
  22.  
  23.         public static void Clear()
  24.         {
  25.             CachedJSONNodes.Clear();
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement