Goggle Inventory Importer is a Unity tool designed to integrate Google Sheets data directly into your Unity project. It provides functionality to parse and import game settings, such as inventory items and their properties, using the Google Sheets API. This tool streamlines the setup of game inventories by eliminating the need for manual entry of item data.
- Imports inventory items from a Google Sheets document.
- Supports parsing of properties, including equippable items and constant stats.
- Uses reflection to dynamically load parsers.
- Integrated with Google Sheets API for async data download.
The InventoryController
script showcases advanced inventory management capabilities within Unity.
-
Inventory Panels
Manages different inventory UI panels, such as:- Equipment Panel
- Inventory Panel
- Loot Panel
-
Tooltips and Context Menus
Provides item details and action menus based on user interaction. -
Item Actions
Supports contextual actions like:- Equipping
- Consuming
- Transferring
- Unequipping
-
Loot Containers
Handles dynamic loot containers and their associated UI. -
Stat Collection
Aggregates and applies item stats to the player or other game entities. -
Event Handling
Centralized management of user interactions, including dragging, clicking, and filtering.
-
Drag-and-Drop UI
Facilitates smooth drag-and-drop functionality for inventory items. -
Dynamic Filtering
Supports real-time search and filtering based on:- Item types
- Item names
-
Panels Management
Automatically opens and closes inventory panels, efficiently handling their lifecycle. -
Modular Design
Actions like equipping and transferring are encapsulated in reusable classes such as:EquipClickAction
TransferClickAction
- Unity 2020.3 or later.
- Google Sheets API credentials.
- Basic knowledge of Unity Editor scripting.
- Odin Inspector.
-
Clone the repository or download the ZIP file.
-
Place your Google Sheets API credentials in the project. Replace the path in the script:
var sheetsImporter = new GoogleSheetsImporter(CREDITS_NAME, SHEET_ID);
-
Set your Sheet ID and Credentials in the
ConfigImportsMenu.cs
file. -
Make sure the game settings asset file exists:
private const string GAME_SETTINGS_DATA = "Assets/Data/Game Settings.asset";
-
To trigger the import, go to Unity Editor and click: GoggleImporter > Import Inventory System.
This class manages the import process via Unity Editor's menu options. It imports both inventory items and property names from Google Sheets.
[MenuItem("GoggleImporter/Import Inventory System")]
public static async void LoadItemsSettings()
Handles the connection to the Google Sheets API, downloading and parsing sheet data.
public async Task DownloadAndParseSheetAsync(string sheetName, IGoogleSheetParser googleSheetParser, int rowIncrement = 1)
- ItemSettingsParser.cs Parses each row of the sheet into the game’s ItemSettings using dynamic parsers based on the header type.
public void ParseSheet(List<string> headers, IList<object> tokens)
EquippablePropertyParser.cs
: Parses items that can be equipped (e.g., weapons, armor).ConstantStatPropertyParser.cs
: Parses constant stat items (e.g., health, strength).
- The importer connects to a Google Sheets document using the Google Sheets API.
- Based on the sheet name, it pulls the data and applies it to game settings.
- Reflection is used to dynamically assign the appropriate parser based on the column headers in the sheet.
- The parsed data is stored in Unity asset files for immediate use in the game.
ActionType
is an abstract base class, and specific actions are implemented as derived classes. The use of a custom ActionTypeAttribute
ensures flexibility for metadata or runtime reflection.
[ActionType]
public class EquippableAction : ActionType
{
public override string ToString() => "After Equip";
}
Create a property class that inherits from Property
and set the property type with all neccesary data, remember to set the same name of class as in your sheet`s property:
public class EquippableProperty : Property
{
public EquipType EquipType;
public int Level;
public override string ToString() => string.Empty;
}
Create a property parser that inherits from BaseParser
. This allows values to be set from Google Sheets and not just from the editor:
public class EquippablePropertyParser : BaseParser, IPropertySetter
{
public override string PropertyType => nameof(EquippableProperty);
public override void Parse(string token, ItemSettings itemSettings)
{
if (string.IsNullOrEmpty(token)) return;
var propertyParts = token.Split(';');
var equipTypeValue = propertyParts[0];
var levelValue = propertyParts.Length > 1 ? propertyParts[1] : "0";
if (!Enum.TryParse(equipTypeValue, out EquipType equipType))
{
Debug.LogError($"Invalid EquipType for EquippableProperty: {equipTypeValue}");
return;
}
var property = new EquippableProperty
{
EquipType = equipType,
Level = int.TryParse(levelValue, out int level) ? level : 0
};
if (itemSettings.CurrentType != null)
{
itemSettings.AllProperties.Add(new ActionTypeToProperty()
{
ActionType = itemSettings.CurrentType,
Property = property
});
}
else
{
Debug.LogWarning($"No type set for EquippableProperty. Default Level: {property.Level}. Item: {itemSettings.Name}");
}
}
}
For the importer to work correctly, your Google Sheet should have the following structure:
- Item Name: The name of the item.
- Is Stackable: The stack of the item.
- Stack Size: The size of the stack.
- Type: Specifies the property type action (e.g., Equippable, Consumable).
- EquipType: Only used for equippable items, specifies the type of equipment, level requirements.
- StatType: The stat affected by the item.
- ItemType: The type of the item, if no equippable property was found.
Feel free to open issues or submit pull requests for new features or bug fixes. Contributions are welcome!