{"id":21334790,"url":"https://github.com/dkoleev/unigsc","last_synced_at":"2025-03-16T01:40:36.278Z","repository":{"id":221017988,"uuid":"589511281","full_name":"dkoleev/UniGSC","owner":"dkoleev","description":"Loads data from Google sheets of any structure into Unity and parses it into a Json file of any given structure.","archived":false,"fork":false,"pushed_at":"2023-03-29T10:42:59.000Z","size":1908,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T14:24:24.773Z","etag":null,"topics":["google-sheets-api-v4","unity","unity-configs","unity3d","unity3d-plugin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dkoleev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-01-16T09:44:51.000Z","updated_at":"2025-01-06T11:25:02.000Z","dependencies_parsed_at":"2024-02-05T18:51:22.333Z","dependency_job_id":"dec7c39f-ebc5-4357-aa5c-56180cb3723b","html_url":"https://github.com/dkoleev/UniGSC","commit_stats":null,"previous_names":["dkoleev/unigsc"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoleev%2FUniGSC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoleev%2FUniGSC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoleev%2FUniGSC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoleev%2FUniGSC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dkoleev","download_url":"https://codeload.github.com/dkoleev/UniGSC/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814907,"owners_count":20352037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-sheets-api-v4","unity","unity-configs","unity3d","unity3d-plugin"],"created_at":"2024-11-21T23:26:51.840Z","updated_at":"2025-03-16T01:40:36.252Z","avatar_url":"https://github.com/dkoleev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Google Sheets Configs for Unity game engine.\n===\n\n```mermaid\nflowchart LR\nid1(Google sheet) --\u003e|parser| id2(Json) --\u003e|data model| id3(Unity runtime)\n```\n\nThis package converts data from `Google sheets` to `Json` files. \n\nThe json file structure is generated using custom parsers, which allows you to generate a json file of any structure from a Google sheet of any structure.\n\n## Table of contents\n\n\u003cdetails\u003e\n\t\n\u003c!-- toc --\u003e\n- [Installation](#installation)\n- [Setup](#setup)\n- [Creating Credentials in Google API Console](#creating-credentials-in-google-api-console)\n- [Connect Unity project to Google Sheets service](#connect-unity-project-to-google-sheets-service)\n- [Setup local configs](#setup-local-configs)\n- [Parsers](#parsers)\n\t- [Default parser](#default-parser)\n\t- [Create custom parser](#create-custom-parser)\n\n\u003c!-- tocstop --\u003e\n\t\n\u003c/details\u003e\n\n## Installation\n\n1. UniGSC required [Newtonsoft Json Unity Package](https://docs.unity3d.com/Packages/com.unity.nuget.newtonsoft-json@3.0/manual/index.html).\n\t\u003e [How to install Newtonsoft Json](https://github.com/jilleJr/Newtonsoft.Json-for-Unity/wiki/Install-official-via-UPM)\n\n\n2. Install UniGSC. Use [UPM](https://docs.unity3d.com/Manual/upm-ui.html) to install the package via the following git URL: \n\n\t```\n\thttps://github.com/dkoleev/UniGHC.git\n\t```\n\n\t![](https://gyazo.com/8c8fc97345fc64f53d62814cce571974.gif)\n\n\n## Setup\n### Creating Credentials in Google API Console\n\nTo set up **OAuth** or **API Key** authorization, follow these steps:\n- Open [Google API Console](https://console.developers.google.com/) and select the **Credentials** section under APIs \u0026 Services.\n\n![image](https://user-images.githubusercontent.com/54948242/212972962-fabc6862-6540-40f7-b1d0-3359c662ebf2.png)\n  \n- Select Google APIs and Services project for your Unity application. If you do not have project select **CREATE PROJECT** to create new project. \n- Enable the Google Sheets API support.\n- Select the **CREATE CREDENTIALS** option and select either **API Key** or **OAuth Client ID**.\n\n#### OAuth\n\nWigh OAuth 2.0 authentication you can read and write from a public and private sheets. For more information, see [Google’s OAuth 2.0 documentation](https://developers.google.com/identity/protocols/oauth2).\n\nWhen generating OAuth credentials, set the application type to Desktop (because plugin uses the service only through the Unity Editor).\n\nAfter the credentials have been created, download the JSON file.\n\n![image](https://user-images.githubusercontent.com/54948242/212972140-70c60a83-b3fa-4c71-bb9d-137564c71c4b.png)\n![image](https://user-images.githubusercontent.com/54948242/212972417-42ed6fc2-e799-47a3-b9d6-701e14e542c1.png)\n \n#### API Key\n\nAPI keys are a simple encrypted string that can be used only for read data from public Google Sheets.\n\nAfter the key has been created, click **SHOW KEY** and copy key to clipboard.\n\n### Activate Google Sheet service\n- Go to Enabled APIs \u0026 services\n\n![image](https://user-images.githubusercontent.com/54948242/213471801-af4d9efe-1421-4feb-abb6-f9b0177b8b10.png)\n\n- Find Google Sheets Api and Enable it.\n\n![image](https://user-images.githubusercontent.com/54948242/213471990-4430f73a-3d28-43dc-bace-b19ab90f772e.png)\n\n\n\n\n## Connect Unity project to Google Sheets service\n- Create **Google Sheets service Provider**. \n  - Right Click in **Project** tab.\n  - Select `Create -\u003e Yogi -\u003e Google Sheets Configs -\u003e Provider`\n  - Select created file.\n  - Choose authentication type\n  \n    ![image](https://user-images.githubusercontent.com/54948242/212975382-19a3df8a-e81a-47ec-9437-ddf8fae8a7d3.png)\n    \n  - OAuth\n    - Click `Load Credentials` and select credentials .json file downloaded from Google Sheets API.\n    - Click `Authorize`.\n      - Unity launches your web browser and opens a Google authentication page. Log in your Google account and allow Unity access to the account. If you don't click **Authorize** Unity opens the web browser when you pull data from the Google sheet.\n   - Api Key\n      - Insert **Api Key** to field.\n  ### Setup local configs.\n    - Create **Google Sheets Configs** file. \n      - Right Click in **Project** tab.\n      - Select `Create -\u003e Yogi -\u003e Google Sheets Configs -\u003e Configs`\n      - Select created file.\n      - Assigen the [provider](#connect-unity-project-to-google-sheets-service) created in the previous step.\n      \n      ![image](https://user-images.githubusercontent.com/54948242/212977810-ce313302-a63f-4e1c-9a3f-ba50612cf259.png)\n      \n    - Add your first config\n    \n    ![image](https://user-images.githubusercontent.com/54948242/212978995-2a787755-bf6e-446a-95ce-9b9c7854c3b6.png)\n\n     - `Name` - You can give it any name you want. Doesn't affect anything.\n     - `Spread Sheet` - Spreadsheet id.\n      \n     ![image](https://user-images.githubusercontent.com/54948242/212985253-cb37a9a8-0e61-4801-98f6-2206774f86a3.png)\n        \n     - Sheets\n       - `Config Name` - The path where generated config .json file will be saved.\n       - `Sheet Id` - The id of the sheet used to load the data.\n       \n       ![image](https://user-images.githubusercontent.com/54948242/212985300-f1d5c8e0-32ba-4967-a671-df4461604394.png)\n       \n       - `Range` - Range of sheet used for loading. Examples: 'A1:E1000', '2:1000'. **Leave empty to loading the entire sheet**.\n       - `Parser` - The way how to parse data loaded from sheet. Use 'default' parser or create your own.\n     - Click `Pull Configs from Google Drive` to load google sheets configs into local json files.\n      \n      \n \u003cdetails\u003e\n  \u003csummary\u003eExample\u003c/summary\u003e\n \n \n   We have sheet config with monsters.\n   \n   ![image](https://user-images.githubusercontent.com/54948242/212984890-09e9c978-9f2e-4d07-a44a-43a0ed054818.png)\n    \n   Setup config in Unity.\n   \n   ![image](https://user-images.githubusercontent.com/54948242/212983257-421da2c4-6338-41a3-b0d0-63ba77ec9a32.png)\n   \n  After pulling Monsters.json config will be created.\n  \n  ![image](https://user-images.githubusercontent.com/54948242/212983611-5182d516-5a29-44f6-a25b-becc6b6bde8f.png)\n\n  How you can see - with the 'default' parser, the first column is used as the key in json config.\n \n \u003c/details\u003e\n \n      \n## Parsers\n  \n\u003e 💥 **You can write any unique parser for each table to generate json files of the desired format** 💥\n\n[Json.Net](https://www.newtonsoft.com/json) is used to parse google sheet data.\n \n### Default parser\n\nDefault parser has id `default` and parse sheet data to the next structure\n\n```json\n{\n \"[first_column_current_row_value]\" : {\n  \"[first_column_first_row_value]\" : \"[first_column_current_row_value]\",\n  \"[second_column_first_row_value]\" : \"[second_column_second_row_value]\",\n  ...\n  \"[n_column_first_row_value]\" : \"[n_column_n_row_value]\",\n }\n}\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eExample\u003c/summary\u003e\n\nThis sheet\n\n![image](https://user-images.githubusercontent.com/54948242/213211874-3eaa9b3d-c8d5-4777-99c9-44178a002086.png)\n\nwill be parsed in next json structure\n\n```json\n{\n  \"monster_0\": {\n    \"id\": \"monster_0\",\n    \"name\": \"Big Boss\",\n    \"damage\": 10\n  },\n  \"monster_1\": {\n    \"id\": \"monster_1\",\n    \"name\": \"Small Boss\",\n    \"damage\": 20\n  }\n}\n```\n\n\u003c/details\u003e\n\nTo use default parser set field `Parser` in sheet config to `default`.\n\n![image](https://user-images.githubusercontent.com/54948242/213213224-58e192d3-845c-4d3d-8571-393f288a1e27.png)\n\n\n## Create custom parser\n\nFor example - we have this Google sheet config\n\n![image](https://user-images.githubusercontent.com/54948242/213154537-90b554c5-fd6f-412f-81c3-9f5df0bb710c.png)\n\nAnd we want parse it to this json format\n\n```json\n{\n  \"reward_0\": {\n    \"id\": \"reward_0\",\n    \"resources\": [\n      {\n        \"resource_id\": \"gems\",\n        \"amount\": 10\n      },\n      {\n        \"resource_id\": \"gold\",\n        \"amount\": 5\n      }\n    ]\n  },\n  \"reward_1\": {\n    \"id\": \"reward_1\",\n    \"resources\": [\n      {\n        \"resource_id\": \"gold\",\n        \"amount\": 100\n      }\n    ]\n  }\n}\n...\n```\n\n**Make next steps:**\n\n- Create new class `RewardsParser` and implement an interface `ISpreadsheetParser`.\n\n\n```c#\nusing System.Collections.Generic;\nusing Yogi.GoogleSheetsConfig.Editor.Parsers;\n\nnamespace Editor {\n    public class RewardsParser : ISpreadsheetParser {\n        public string Parse(int sheetId, IList\u003cIList\u003cobject\u003e\u003e sheetData) {\n            return string.Empty;\n        }\n    }\n}\n```\n\n- Add `ParserType` attribute to `RewardParser` class and name it for example `reward_parser`.\n\n```c#\nusing System.Collections.Generic;\nusing Yogi.GoogleSheetsConfig.Editor.Parsers;\n\nnamespace Editor {\n    [ParserType(\"reward_parser\")]\n    public class RewardsParser : ISpreadsheetParser {\n        public string Parse(int sheetId, IList\u003cIList\u003cobject\u003e\u003e sheetData) {\n            return string.Empty;\n        }\n    }\n}\n```\n\n- Parse **sheetData** to json object\n\n```c#\nusing System.Collections.Generic;\nusing Framework.Editor.Google;\nusing JetBrains.Annotations;\nusing Newtonsoft.Json.Linq;\n\nnamespace GameGarden.Florescence.Editor.Configs.Parsers {\n    [UsedImplicitly]\n    [ParserType(SpreadsheetParserType.ByIdMultiplyRows)]\n    public class SpreadsheetParserByIdMultiplyRows : ISpreadsheetParser {\n        public string Parse(int sheetId, IList\u003cIList\u003cobject\u003e\u003e sheetData) {\n            JObject dicJson = new JObject();\n            var itemList = new JArray();\n\n            var item = new JObject();\n            var key = \"\";\n            \n            //go by rows\n            for (int i = 1; i \u003c sheetData.Count; i++) {\n                //set key by first column\n                if (!string.IsNullOrEmpty(sheetData[i][0].ToString())) {\n                    item.Add(new JProperty(sheetData[0][0].ToString(), sheetData[i][0].ToString().Replace(',', '.')));\n                    key = sheetData[i][0].ToString();\n                }\n\n                var itemListItem = new JObject();\n                //go by columns for current row and add data to JObject\n                for (int j = 1; j \u003c sheetData[i].Count; j++) {\n                    itemListItem.Add(new JProperty(sheetData[0][j].ToString(), sheetData[i][j].ToString().Replace(',', '.')));\n                }\n                \n                //add generated item to list items for key\n                itemList.Add(itemListItem);\n\n                //If we have reached the next key then add current to dictionary\n                if (i == sheetData.Count - 1 || !string.IsNullOrEmpty(sheetData[i + 1][0].ToString())) {\n                    item[\"items\"] = itemList;\n                    dicJson[key] = item.DeepClone();\n                    itemList.Clear();\n                    item = new JObject();\n                }\n            }\n\n            return dicJson.ToString();\n        }\n    }\n}\n```\n\n\u003e ❕ Read [Json.Net Documentation](https://www.newtonsoft.com/json/help/html/Introduction.htm) if you don't know how to generate json object.\n\n- Set this parser to your Google sheets config\n\n![image](https://user-images.githubusercontent.com/54948242/213167136-7f9e2586-9bbe-492d-9bdd-f2f3d364ec6a.png)\n\n- Click `Pull` and json config will be generated.\n\n![image](https://user-images.githubusercontent.com/54948242/213167376-8312eaa0-6a8f-42df-9a26-e39d0b294765.png)\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkoleev%2Funigsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdkoleev%2Funigsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkoleev%2Funigsc/lists"}