Google Sheets For Unity Manual
User Manual: Pdf
Open the PDF directly: View PDF .
Page Count: 8
GoogleSheetsForUnityManual
Youalwayscangetanuptodatecopyofthisdocumentat:
https://docs.google.com/document/d/14cRMeyFXhYYCHYjeNahGFLlsAHlc5HmVWp30ZtdqMkk/edit?usp=sharing
Google Sheets For Unity (“GSFU”) allows you to retrieve and send data to Google
Spreadsheets from a Unity3D project at runtime or design time, for easy and collaboratively,
gamedatatweakingandrecording.
This is usually done by setting up a complex environment involving oAuth authentication,
granular spreadsheets permissions, and developing in Unity the necessary code using the
GoogleAPIforSpreadsheets.
GSFU simplifies all that, by deploying a web service (in Google’s infrastructure, under your
account), that will connect to a given Spreadsheet, and update/return data from a desired
worksheet, in JSON format, and all without involving Google user account credentials from the
Unityside.
Then from Unity3D, you can get the info by poking the web service with the standard WWW
class, and parsing it into ready to use data objects with the json library of your choice (the demo
projectincludesLitJson).
Some of this may sound complicated for those who never worked with Google services before,
but will be found very simple as soon as reading the simple steps described on this manual, and
lookingattheexampleproject.
Also, a major point about GSFU, is that the source code is included, for both, the web service,
andtheUnityclass.Thismeansoptimalflexibility,allowingcustomandusefulcustomizations.
InstallationandSetup
As stated, GSFU consist of two parts: the Unity code, and the web service. And of course, the
Googlespreadsheetcontainingyourdata.
Deployingthewebservicescript
FirststepintosettingupGSFU,isthedeploymentofthewebservicescript.
It is a Google Apps Script, that you can open and modify at will, and have it running as a web
app. You need to have your own copy on Google Drive, that you can get here:
https://script.google.com/d/13SnqGtbQOUcG1QkUKPQ_xdki58Y3wFZxjpFWKmL4WtIlr9RMo5
wd2o5/newcopy
Settinguptheservice:
1. OpenyourcopyoftheGSpreadsheetConnectorgooglescript.
2. Inthescripteditor,goto"Publish"menu,andclickon"Deployaswebapp...".
3. You'll now see a dialog with the title "Deploy as Web App". Where you need to set the
followingvalues:
Projectversion
:
Type"1"inthetextbox,andhit"SaveNewVersion".
Executetheappas
:
Select"Me(your@google.email)".
Whohasaccesstotheapp
:
Select"Anyone,evenanonymous".*
1
4.Clickon"Deploy".
5.Anewdialogwillshowup,takenoteoftheurlunderthelabel"CurrentwebappURL".
ThisistheWebServiceURL,describedatthesection“UnityDataConnector
Parameters”.
6.Click"OK".
*
1
:Ifyoufoundthatthereisno"Anyone,evenanonymous"
option,youneedtocheckwithyourGoogle
AppsAdministratorpanel,thereisapolicyoptionforsharingthedocsoutsidetheorganization.Hereisthe
documentationondocssharingpolicy:https://support.google.com/a/answer/60781?hl=en
Finally, Google requires you to authorize the script. For this, open the "Run" menu, and click on
the first function, "doGet". An script authorization dialog will appear, where you will be prompted
toauthorize.
Youcanignore/dismissanyerrorproducedbythisonetimeineditorscriptrun.
You need to do all the previous steps again, if you make changes to your script that want to go
live.Formoreinfo,goto
https://developers.google.com/appsscript
.
You only need to deploy the web service once. It will work with any and all spreadsheets on
yourGoogleDrive.
ExampleSpreadsheet
The included Unity example project, requires a Google Spreadsheet to connect and
send/retrievedata.
Thespreadsheetisprovidedinthefollowinglink:
https://docs.google.com/spreadsheet/ccc?key=0AssoWeEUz0IdGFLSzRPYmtxU0dDdzJsaUN
HSDBiYUE&newcopy
Youhavetogetacopyofyourownofthisexamplespreadsheet.
When the time comes for creating your own spreadsheet with data, there are a few
considerations,thatyoushouldtakeinmindforGSFUtoworkproperly.
1. Follow the example spreadsheet scheme. The first row in a data worksheet is always for
thefieldnames.
2. Avoid including extra content in the data worksheets, other than the specific data to be
retrievedbyUnity.
3. Always have a worksheet called “passcode”. If you want to set a blank password,
remove any data from the first, top left cell (A1). For more info read the “Security” section
ofthemanual.
4. Google Sheets has some limits that you should take into account when deciding whether
or not to use a Spreadsheet to store your script's data. For example, a Spreadsheet is
limited to 400,000 total cells across all sheets and 256 columns per sheet. See this help
center article for the full listing of limits.
https://support.google.com/drive/answer/2505921
5. FormulascanbeusedtopopulatedatatoberetrievedbyUnity.
In general terms, you will be safer by using the provided example spreadsheet as template for
newspreadsheets.
ExampleScene
From Unity, open the “ConnTest” scene. If you hit Play, you will see a working example of
GSFUupdatingthesceneparametersatruntime.
To understand how it works, stop the project and select the “ConnectionExample” GameObject
inthehierarchyview.YouwillseethisintheInspectorview:
This is the script that you need to include in your Unity projects. The UnityDataConnector script,
exposesfieldswiththerequiredparametersforgettingthedatafromyourspreadsheet.
UnityDataConnectorParameters
❏Web Service Url: Expects the complete url of the web service. For further info look in
the“Howtodeploythewebservicescript”section.
❏Spreadsheet Id: The id of the google spreadsheet containing your data. For more info
readthe“GettingtheSpreadsheetId”section.
❏Sheet Name: Simply the name of the worksheet within your google spreadsheet, that
holds the data you want to retrieve. You can easily extend the UnityDataConnector class
forgettingdatafrommorethanoneworksheet.
❏Password: The string you entered on your “passcode” worksheet. For info, read the
“Security”section.
❏Max Wait Time: The maximum time to wait before aborting the connection operation.
This may vary depending on your internet connection. You can increase it if required by
yourconnectivity.
❏Data Destination Object: This is a reference to an object with the script that will receive
theretrieveddata,throughaUnity’sSendMessagecall.
❏Statistics Sheet Name: Name of the worksheet within your google spreadsheet, that
will receive new rows of data from your game. In the example spreadsheet, the name is
“Statistics”.
GettingtheSpreadsheetId
Now you need the id of the spreadsheet containing your data. It is highly recommended to use
theexamplespreadsheetthefirsttime.
To get the id, simply open the spreadsheet, and look at the URL: it will have one of two possible
formats.TheidinthefollowingexampleURL’sis“abc1234567”:
https://spreadsheets.google.com/a/yourdomain.com/ccc?key=abc1234567
https://docs.google.com/document/d/abc1234567/edit
Security
There are a few security considerations and practical matters to have in mind when using
GSFU.
● The password for accessing your data from Unity, is set on the spreadsheet itself, on a
worksheet called “passcode”. This sheet needs to always be present, and you must not
haveanyotherdatathantheoptionalpasswordonthefirstcell(A1).
Is important to note that while is quite practical, this security approach is recommended
for development time, but probably not suited for released games. For released versions,
itrequiressomeworkandcarefulconsiderationofsecurityandconnectivityaspects.
● Ifyouwantablankpassword,simplyleavethe“passcode”worksheetblank.
● The Web Service must be deployed by the same Google user that will hold the
SpreadsheetinhisGoogleDriveaccount.
● The Google Spreadsheet permissions can be set in any way necessary, and won’t affect
the functionality of GSFU, as long as the Web App owner remains the spreadsheet
owner.
TheExampleProject
Theexampleprojectafterupdatingfromtheonlinespreadsheet.
The included example is pretty much selfexplanatory. When run, you will see three grey balls,
bouncingatthesamerepetitiverateoveraplane.
TherewillbealsoaGUIboxatthetopleft,whichincludesthreeelements:
➔The connection status reference, at the top, that will describe the connection process for
the retrieving of data from the spreadsheet. If there are any errors, it will be reported
there.
➔The update button, in the middle, that will start the sequence of connecting to the sheet
on the cloud, and get the data. It will fetch the ball color and drag coefficient by object
name.
➔The save stats checkbox, that will initiate the process of sending to the online sheet, the
records of each ball bounce over the plane, including a timestamp, ball name, and
bounce magnitude. As opposed to the update button, the status and error handling of
this is internal and won’t report to the top GUI reference element, nor the Unity console,
to avoid clogging; however in code you will find the places where to handle issues
dependingyourcase.
EditorExample
Since version 1.2 of Google Sheets for Unity, a new example is included, in which you can see
ausecaseoftheextensioncapabilitiesatdesigntime.
Forthisfeature,anewmenuintheUnityEditorhasbeencreated.
Theneweditormenu
As a practical measure, the menu items will only be enabled if an object named
“DataUseExample
” is currently selected in the scene (it is the scene object handling the data
sentorretrievedfromtheGoogleSpreadsheetsinthebaseexample).
The result of the “Update from Google Spreadsheet” menu item action, is the same than in
the base runtime example (the bouncing balls color and drag values get updated from the
cloud), except that being at design time, you can opt to save the changes permanently in the
sceneand/ortheproject,orsimplyplaythescenetotestthechanges.
The drag value of the balls is affected on the scene, while the color is affected on the hierarchy
material asset, meaning the update is beyond the limits of the scene itself, and will persist on
theprojectifdesired.
The“Reset”menuoptionwillsetthecoloranddragvaluesoftheballsbacktotheoriginal.
Changelog
1.0
FirstversiononUnityAssetStore.
1.1
Addedsavingtospreadsheetfeature.
1.2
Newexampleincluded:UnityEditormenu,foruseatdesigntime.
1.3
UpdatedLitJsontolatestversion.
FixedissuewhereemptyvaluesonthespreadsheetthrowerrorsonUnity.
Replaced"sheet"by"worksheet"toavoidconfusions.
Polishedthemanualabit,andfixedsomegrammarerrors(thanksAnthony!).
1.3.1
NewdebugModeflagintheconnectionobjectforamoreverboseconsoleoutput.
1.3.2
PlacedContinuationManager.csandGSFUEditorMenu.csfilesinside"Editor"folder.
1.5
CompatibilitycheckwithUnity5…Success!
Unity5BuildforUnityAssetStore.