Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        static List <GSWorksheet> downloadWorksheets(string sheetId)
        {
            string          url_worksheet = string.Format(WORKSHEET_LIST_URL, sheetId);
            UnityWebRequest req           = UnityWebRequest.Get(url_worksheet);

            var op = req.SendWebRequest();

            while (!op.isDone)
            {
            }

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

            string workSheetText = req.downloadHandler.text;

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

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

            List <GSWorksheet> worksheets = new List <GSWorksheet>();

            foreach (GSResponse.Entry entry in response.feed.entry)
            {
                string worksheetTitle = entry.title._d_t;

                GSWorksheet worksheet   = new GSWorksheet(worksheetTitle);
                bool        gid_check   = false;
                bool        cells_check = false;

                foreach (GSResponse.Link link in entry.link)
                {
                    string url = link.href;

                    if (url.Contains("/cells/"))
                    {
                        worksheet.link = url + "?alt=json";
                        cells_check    = true;
                    }

                    if (url.Contains("gid="))
                    {
                        worksheet.gid = ExtractGID(url);
                        gid_check     = true;
                    }

                    if (cells_check && gid_check)
                    {
                        break;
                    }
                }
                worksheets.Add(worksheet);
            }
            return(worksheets);
        }