public IEnumerator SpreadSheet(string _strSheetId, string _strSheetName, Action _onRecieved) { string sheet_id = ""; { string strUrl = string.Format("https://spreadsheets.google.com/feeds/worksheets/{0}/public/basic", _strSheetId); UnityWebRequest req = UnityWebRequest.Get(strUrl); yield return(req.SendWebRequest()); while (req.downloadProgress < 1f) { if (req.downloadProgress > 0) { } yield return(null); } if (req.isNetworkError) { Debug.LogError("error:" + strUrl); yield break; } //Debug.LogWarning(req.downloadHandler.text); sheet_id = ParseSpreadSheetSerial(_strSheetId, _strSheetName, req.downloadHandler.text); //Debug.LogWarning(sheet_id); } { string strUrlSub = string.Format("https://spreadsheets.google.com/feeds/cells/{0}/{1}/public/values?alt=json", _strSheetId, sheet_id); UnityWebRequest req = UnityWebRequest.Get(strUrlSub); yield return(req.SendWebRequest()); while (req.downloadProgress < 1f) { if (req.downloadProgress > 0) { } yield return(null); } if (req.isNetworkError) { Debug.LogError("error:" + strUrlSub); yield break; } IDictionary dictRecieveData = null; #if USE_MINIJSON dictRecieveData = (IDictionary)MiniJSON.Json.Deserialize(req.downloadHandler.text); #endif if (dictRecieveData != null) { Input(SpreadSheetData.ConvertSpreadSheetData(dictRecieveData)); } } _onRecieved.Invoke(); }
static public List <SpreadSheetData> ConvertSpreadSheetData(IDictionary _dict) { List <SpreadSheetData> ret = new List <SpreadSheetData>(); SpreadSheetData data = new SpreadSheetData(); bool bRecord = false; search(_dict, ref bRecord, ref data, ref ret); return(ret); }
public void onRecieved(TNetworkData _data) { csvWord = new CsvWord(); csvWord.Input(SpreadSheetData.ConvertSpreadSheetData(_data.m_dictRecievedData)); csvWord.setupDict(); /* * Debug.LogError(string.Format("key:{0} word:{1}", "title" ,csvWord.Get("title", "ja"))); * Debug.LogError(string.Format("key:{0} word:{1}", "title", csvWord.Get("title", "en"))); */ IsReady = true; }
virtual protected T makeParam(List <SpreadSheetData> _list, int _iSerial, int _iRow, string[] _keyArr) { T retParam = new T(); // このあたりは共通化を頼る // 並びとか変わると残念な結果になりますので! int iIndex = 1; //PropertyInfo[] infoArray = retParam.GetType().GetProperties(); foreach (string key in _keyArr) { SpreadSheetData ssd = SpreadSheetData.GetSpreadSheet(_list, _iRow, iIndex++); if (ssd != null) { retParam.SetField(key, ssd.param); } } return(retParam); }
// SpreadSheetデータを取得する static private void search(IDictionary _dict, ref bool _bRecord, ref SpreadSheetData _data, ref List <SpreadSheetData> _list) { foreach (var key in _dict.Keys) { if (_bRecord) { if (key.Equals("row") == true) { //Debug.Log (key); //Debug.Log (_dict [key]); //Debug.Log (_dict [key].GetType()); _data.row = int.Parse((string)_dict[key]); //_data.row = int.Parse((string)_dict [key]); } else if (key.Equals("col") == true) { //DataCopyUtil.copyLongToInt (ref _data.col, _dict, key.ToString()); _data.col = int.Parse((string)_dict[key]); //_data.col = int.Parse(_dict [key]); } else if (key.Equals("$t") == true) { DataCopyUtil.copyString(ref _data.param, _dict, key.ToString()); } else { // むしろエラー } } if (key.Equals("gs$cell") == true) { _data = new SpreadSheetData(); _bRecord = true; } if (_dict[key] is IDictionary) { //Debug.Log ("idict"); search((IDictionary)_dict[key], ref _bRecord, ref _data, ref _list); } else if (_dict[key] is IList) { IList use_list = (IList)_dict[key]; //Debug.Log (use_list.Count); foreach (IDictionary indict in use_list) { search((IDictionary)indict, ref _bRecord, ref _data, ref _list); } } else { ; // nocalled } if (key.Equals("gs$cell") == true) { _list.Add(_data); _bRecord = false; } } }