예제 #1
0
파일: GSLoader.cs 프로젝트: akagik/GSPlugin
        public static CsvData LoadCsvData(GSWorksheet sheet)
        {
            string title = sheet.title;
            string url   = sheet.link;

            UnityWebRequest req = UnityWebRequest.Get(url);

            var op = req.SendWebRequest();

            while (!op.isDone)
            {
            }

            if (req.isNetworkError)
            {
                Debug.Log(req.error);
                return(null);
            }
            else if (req.responseCode != 200)
            {
                return(null);
            }

            string resJson = req.downloadHandler.text;

            resJson = resJson.Replace("$", "_d_");
            GSResponse response = JsonUtility.FromJson <GSResponse>(resJson);

            if (response == null || response.feed == null)
            {
                return(null);
            }

            List <List <string> > cellList = new List <List <string> >();

            foreach (GSResponse.Entry entry in response.feed.entry)
            {
                var cell = entry.gs_d_cell;

                int    row        = cell.row;
                int    col        = cell.col;
                string inputValue = cell._d_t;

                while (cellList.Count < row)
                {
                    cellList.Add(new List <string>());
                }

                while (cellList[row - 1].Count < col)
                {
                    cellList[row - 1].Add(string.Empty);
                }

                cellList[row - 1][col - 1] = inputValue;
            }

            CsvData csv = ScriptableObject.CreateInstance <CsvData>();

            csv.SetFromList(cellList);
            return(csv);
        }