weixudong
2020-12-09 17c6e8b6f2aee4ed9a15c886f54a73f0cb61b125
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
 
namespace KTGMGemClient
{
    public class JsonDataReader : MonoBehaviour
    {
        public static JsonDataReader Instance
        {
            private set;
            get;
        }
 
        /// <summary>
        /// Awake is called when the script instance is being loaded.
        /// </summary>
        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<string, JsonData> 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();
            }
        }
    }
}