Ejemplo n.º 1
0
        public DemoTableData FetchDataFromFile(string _filePath, out string _md5, out bool _changed)
        {
            if (!Utilities.CheckFileHasChanged(_filePath, lastFileMD5))
            {
                Debug.Log($"Data hasn't changed on {_filePath}. Nothing to do here");
                _md5     = lastFileMD5;
                _changed = false;
                return(loadedData);
            }
            _changed = true;

            string _fileContent = Utilities.GetFileContent(_filePath, out string _newMD5);

            _md5 = _newMD5;

            // I leave this because of native implementation... but well... you added a dictionary and I didn't noticed it before.
            //DemoTableData _newData = JsonUtility.FromJson<DemoTableData>(_fileContent);

            DemoTableData _newData = new DemoTableData()
            {
                ColumnHeaders = new List <string>(),
                Data          = new List <DemoTableRowData>()
            };

            JSONObject jsonObject = new JSONObject(_fileContent);

            _newData.Title = jsonObject["Title"].str;

            jsonObject["ColumnHeaders"].list.ForEach((_item) =>
            {
                _newData.ColumnHeaders.Add(_item.str);
            });

            foreach (JSONObject _data in jsonObject["Data"].list)
            {
                DemoTableRowData _newRow = new DemoTableRowData()
                {
                    items = new List <DemoTableColumnData>()
                };

                for (int i = 0; i < _data.list.Count; i++)
                {
                    DemoTableColumnData _item = new DemoTableColumnData()
                    {
                        key   = _data.keys[i],
                        value = _data.list[i].str
                    };
                    _newRow.items.Add(_item);
                }

                _newData.Data.Add(_newRow);
            }

            return(_newData);
        }
Ejemplo n.º 2
0
 public void Build(DemoTableColumnData _data, bool _asHeader = false)
 {
     _isHeader  = _asHeader;
     id         = _data.key;
     title.text = _data.value;
 }