- Click on just created service account under Service accounts tab.
- Go to Keys tab.
- Click Add key->Create New key.
- Select Json (default).
- Click Create.
- Place it in your project.
- Copy service account mail under Service Accounts tab.
- Add created service account to your GoogleSheets table.
Just import package to unity. If you already using Newtonsoft in your project ignore dll "Redpenguin/Dependencies/Newtonsoft.Json.dll" before importing or remove it after.
-
Select profiles
-
Add new profile
-
Choose name and color for profile
-
Get google sheet id from link https:/docs.google.com/spreadsheets/d/*************************/... and paste it as table id
-
Enter your credential from google service account at credential field
-
Enter save path for db (relative to asset folder)
-
Enter file name
-
Select serialization rule
- Profiles dropdown list
- Open profiles window
- Serialization all sheets that profile contains
- Use ScriptableObject containers as intermediate object for load and serialization data
- Load data from google table before save (only available if use SO containers)
- Clear data from cache and playerPrefs.
Create minimum one table script using data from google sheet
Field name in your data class and column name in sheet should be the same!
[SpreadSheet("Example")] //Get values from Example sheet
[Serializable]
public class ExampleData : ISheetData
{
public string myString; // string
public int myInt; // 1
public bool myBool; // true
public List<int> myInts; // [1,2,3]
public List<string> myStrings; // ["a","b","c"]
public JsonExample jsonExample; // {"id":1,"myString":"string"}
public ExampleEnum exampleEnum; // Example1
}
Make sure that sheet exist in table, either data won't display. If sheet exist and still doesn't display just press "Clear Meta" button on your profile in profiles tab
To access google sheets data required to create provider script
public class ExampleDatabaseProvider
{
public ExampleDatabaseProvider()
{
var databaseProvider = new SpreadSheetsDatabaseProvider();
var database = databaseProvider.Load("ExampleProfile"); //Load all sheets that profile contains
var exampleData = database.GetSpreadSheetData<ExampleData>(); //Get list of ExampleData
}
}
If you want serialize or deserialize your data in other way, u can create your own serialization rule.
For that you need inheritate from SerializationRule class, and select this rule for your profile in profiles tab.
public abstract class SerializationRule
{
public abstract void Serialization(string filePath, string fileName, object objectToWrite);
public abstract T Deserialization<T>(string text);
}