using System;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
namespace KTGMGemClient
{
public class JsonDataReader : MonoBehaviour
{
public static JsonDataReader Instance
{
private set;
get;
}
///
/// Awake is called when the script instance is being loaded.
///
void Awake()
{
Instance = this;
}
Action _ac;
public void StartRead(Action ac)
{
_ac = ac;
string path = Application.streamingAssetsPath + "/Table/";
ReadJsonForAndroid(path);
if (Application.platform == RuntimePlatform.Android)
{
}
else if (Application.platform == RuntimePlatform.WindowsEditor ||
Application.platform == RuntimePlatform.WindowsPlayer)
{
}
}
private void ReadJsonForAndroid(string path)
{
string[] allPath = tableLoader.gettables();
StartCoroutine(JsonController.Instance.WWWReadFromFile(path, allPath, InitJson));
}
private void InitJson(Dictionary allDatas)
{
if (allDatas == null)
{
UnityEngine.Debug.Log("get table data error");
if (_ac != null)
{
_ac();
}
return;
}
foreach (string tablename in allDatas.Keys)
{
tableLoader.load(tablename, allDatas[tablename]);
}
if (_ac != null)
{
_ac();
}
}
}
}