A Unity asset using Google Sheets for storing and retrieving data. This package also provides two applications, Database and Ranking, to demostrate the usage.
Database can let you send any form of data to Google sheets and retrieve them later. You can use this system to store player information, such as id, name, equipments, and even master data of your game systems. Data are sent by key value paris and are restricted to some simiple types that MiniJson can parse.
Ranking is another application that can send player scores to Google sheets and get the ranking list back.
Because this asset almost does nothing about security things (hope Google will handle it well though), as well as Quotas for Google Services, it is not recommended for big scale or any commercial projects. Indie developers who just want a simple way of saving and getting data online are welcome to try this :)
- Create a new Google sheet.
- Open the Script Editor from Tools > Script Editor.
- Copy the content of Assets/Umbrella/Databse/Database.gs (for Database) or Assets/Umbrella/Ranking/Ranking.gs (for Ranking) to Code.gs within the Script Editor.
- Save the project and give it a name.
- From the menu, Publish < Deploy as web app...
- In the Deploy as web app popup, make sure you Execute the app as your own account and Who has access to the app is set to Anyone, even anonymous.
- Click Deploy and copy the web app URL.
- If This app isn't verified pops up, at the left bottom corner, click Advanced > Go to [your_project_name] (unsafe) > Allow to verify your app.
- Drag & Drop Assets/Umbrella/Database/DatabaseManager prefab into your scene hierarchy (the scene you want to do the data communication).
- In the Inspector of Assets/Umbrella/Database/DatabaseSettings scriptableobject, paste the web app URL you copied previously to the App URL field.
- Enter the sheet name of your default sheet into the Default Sheet Name field.
- You can now send any data to Google sheets using
DatabaseManager.Instance.SendDataAsync(data, sheetName)
and get data from Google sheets usingDatabaseManager.Instance.GetDataAsync(keys, responseHandler, sheetName)
. If you omit the sheetName parameter, the Default Sheet Name will be used. - responseHandler is a callback function which will be called when response returns. Its parameter is a list of generic objects which contains the values of requested keys. You can use this callback to cast the values and implment your own display logic.
- If you want, add
yield return
beforeDatabaseManager.Instance.SendDataAsync(data, sheetName)
orDatabaseManager.Instance.GetDataAsync(keys, responseHandler, sheetName)
to hang on and wait until the responseHandler callback returns. - For specific usage, please refer to the sample scene and scripts.
- Drag & Drop Assets/Umbrella/Ranking/RankingManager prefab into your scene hierarchy (the scene you want to do the data communication).
- In the Inspector of Assets/Umbrella/Ranking/RankingSettings scriptableobject, paste the web app URL you copied previously to the App URL field.
- Enter the default settings for your ranking requests.
- Ranking Name refers to the name of the ranking, which also determines the name of the corresponding Google Sheets sheet.
- Top Ranking List Settings
- Take Number tells how many data you want to take from the top ranking list, if zero no data will be returned (the ranking list won't be sorted at all).
- Order By tells whether sort the ranking list in ascending or descending order.
- Around Me Ranking List Settings
- Take Number tells how many data you want to take from the around me ranking list, if zero no data will be returned (the ranking list won't be sorted at all).
- Order By tells whether sort the ranking list in ascending or descending order.
- Each time you want to send a score to Google Sheets, you need a
SendScoreRequestData
object. You can easily create a default one with the same settings as you set in the RankingSettings scriptableobject by callingRankingManager.Instance.CreateDefaultSendScoreRequest(score)
. The same rule also applies to getting ranking lists, which requires aRankingRequestData
object. You can now callRankingManager.Instance.SendScoresAsync(requestDataList, responseHandler)
to send scores and callRankingManager.Instance.GetRankingListsAsync(requestDataList, responseHandler)
to get ranking lists. - responseHandler is a callback function which will be called when response returns. Its parameter is a list of
RankingResponseData
objects which contains the sorted ranking lists. You can use this callback to implment your own ranking result display logic. - If you want, add
yield return
beforeRankingManager.Instance.SendScoresAsync(requestDataList, responseHandler)
orRankingManager.Instance.GetRankingListsAsync(requestDataList, responseHandler)
to hang on and wait until the responseHandler callback returns. - For specific usage, please refer to the sample scene and scripts.
-
Send data to Google sheets. The gif shows sending data using key value pairs.
-
Update data in Google sheets. The gif below shows updating data by sending the key and a new value.
-
Send another data. Note: Because Umbrella generates unique ids in Unity and saves them in PlayerPrefs, you should clear PlayerPrefs otherwise duplicated sending will overwrite the data already stored in Google sheets.
-
Get data from Google sheets by keys. The gif below shows getting data using a list of keys.