Skip to main content

The Global Database

At the heart of HookUI lies the HookUI Database. This is a ScriptableObject that acts as the single source of truth for all identifiers in your project.

Why a Database?

In traditional Unity development, you might reference UI screens by:

  • GameObject references (Fragile: break if object is destroyed).
  • String literals "MainMenu" (Error-prone: typos capable).
  • Enums (Rigid: requires recompilation to add a new screen).

HookUI solves this with String-based IDs managed by a dedicated Editor. This gives you the flexibility of strings with the safety of a dropdown menu.

Structure

The database categorizes IDs into three main types:

  1. Views: Represent full screens or modal popups (e.g., MainMenu, Inventory, Popup_Error).
  2. Buttons: Represent actions that trigger navigation (e.g., Btn_Play, Btn_Back, Btn_Close).
  3. Signals: Represent global events (e.g., OnGameStart, OnPlayerDeath).

Each type is further organizing into Categories (e.g., General, HUD, Popups) to keep large projects organized.

Multi-Database Support

HookUI supports Modular Architectures. You can split your data into multiple database files.

  • Primary Database: Your main project data, located at Assets/Resources/HookUI/HookUI_Database.asset. Only this one is editable via the Dashboard.
  • External Databases: Any HookUIDatabase asset found in any Resources folder (e.g., inside a Unity Package or a different module).

How it works: The system automatically detects these external databases at runtime/editor-time and merges them into the list of available IDs. This allows you to install 3rd party modules that come with their own HookUI screens (like our Demo Lab) without polluting your main project file.

Usage in Code

You rarely access the database directly. Instead, you use the components (HookView, HookButton) which have custom Property Drawers that query this database to show you the dropdowns.

If you DO need to query it from code:

// Check if a View ID exists
bool exists = HookUIDatabase.Instance.ViewIDs.Contains("MyViewID");

// Get all IDs in a category
List<string> hudButtons = HookUIDatabase.Instance.GetItems(HookUIIDType.Button, "HUD");