예제 #1
0
        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();
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        // 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;
                }
            }
        }