Virtual Pet Game Template
  • VIRTUAL PET GAME TEMPLATE
  • Getting Started
    • ๐ŸŽฏ Project Setup Guide
    • ๐Ÿงฉ Home Scene Overview
    • ๐Ÿ—บ๏ธ UI Main Menu
    • ๐Ÿ—บ๏ธ LoadingManager
    • ๐Ÿ—บ๏ธ GameInstance
    • ๐Ÿ—บ๏ธ ToolsManager
    • ๐Ÿ—บ๏ธ AudioManager
    • ๐Ÿ—บ๏ธ LanguageManager
    • ๐Ÿ—บ๏ธ MonetizationManager
    • ๐Ÿ—บ๏ธ PlayerSave
  • Modifying the project
    • ๐Ÿพ How to Add a New Pet
    • ๐Ÿ“œHow Add a New Pet Rules
    • ๐Ÿ’ฐ How to Add a New Currency
    • ๐ŸŽ How to Add a New Food Item
    • ๐Ÿงข Adding a New Accessory
    • ๐ŸŽฎ How to Add a New Minigame
  • Modifying Minigames
    • ๐ŸŒค๏ธ Minigame "Jump Sky"
    • ๐Ÿ” Minigame "Food Flicker"
    • ๐Ÿฆ Minigame โ€œFlappyโ€
    • ๐Ÿ’Ž Minigame โ€œGem Hunterโ€
Powered by GitBook
On this page
  • ๐Ÿงพ What It Manages
  • ๐Ÿ“ฆ Runtime Methods
  • ๐Ÿ’ก Editor Integration
  1. Getting Started

๐Ÿ—บ๏ธ 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.

Previous๐Ÿ—บ๏ธ LoadingManagerNext๐Ÿ—บ๏ธ ToolsManager

Last updated 28 days ago