๐บ๏ธ GameInstance
GameInstance โ Component Overview
GameInstance
is the central data manager of the Virtual Pet Game Template. It holds references to all major catalogs, rules, and settings used across the game, and is persistent across scenes.
๐งพ What It Manages
Catalog References
These fields reference the gameโs core data collections:
petData[]
โ List of available pets.currencyData[]
โ List of available in-game currencies.foodData[]
โ List of available food items.minigameData[]
โ All mini-games available in the game.petClothesData[]
โ Available clothing and accessories for pets.
โ ๏ธ These are
ScriptableObjects
. The process of creating and editing them is covered in separate pages: [How to Add New Pet], [How to Add New Food], etc.
Game Rules
petRules
โ Defines emotional states and conditions for pet mood, based on stat thresholds.
EXP Configuration
initialExp
โ EXP required for level 1.finalExp
โ EXP needed for the last level.maxLevel
โ Maximum level the player can reach.expProgressType
โ Defines how EXP scales (Linear or Exponential).expPerLevel[]
โ Auto-filled array defining exact EXP per level (editable in inspector).
๐ฆ Runtime Methods
Pet & Food Access
GetPetDataById(int id)
โ Finds a pet by its ID.GetFoodDataById(int id)
โ Finds a food item by its ID.GetMaxStatValueById(int petId, string statId)
โ Retrieves the max value of a stat for a given pet.
Mood Logic
GetCurrentPetMood()
โ Returns the current mood string ID for the selected pet based on rules and current stats.
Instantiating Pets
InstantiatePetModel(Transform container)
โ Instantiates the currently selected pet prefab inside a container.
UI Helpers
GetCurrencyIconById(string id)
โ Returns a Sprite icon for the currency.GetTranslatedString()
โ Helper functions for fetching localized strings from translation arrays.
๐ก Editor Integration
Includes a custom inspector to auto-fill the EXP table (
expPerLevel[]
) based on chosen curve type.Shows current pet mood when in play mode (for debugging).
This component should only exist once in the project and is marked as DontDestroyOnLoad
. It acts as the backbone of all catalog and rule-based access across the game.
Last updated