NPCAttributeDatabase - jimdroberts/FishMMO GitHub Wiki

Description

ScriptableObject database for storing and retrieving NPC attributes by name. Provides centralized management and lookup for NPC attribute definitions in FishMMO.


API Access

Fields

  • public List Attributes

    List of all NPC attributes in the database.

Methods

  • public bool TryGetNPCAttribute(string name, out NPCAttribute npcAttribute)

    Attempts to find an NPC attribute by its template name. Parameters:

    • name (string): The name of the attribute template to search for.
    • npcAttribute (out NPCAttribute): The found NPCAttribute, or null if not found.* Returns: bool — True if the attribute is found, false otherwise.

Basic Usage

Setup

  1. Create a new NPCAttributeDatabase ScriptableObject in the Unity Editor.
  2. Add NPCAttribute entries to the Attributes list via the Inspector.
  3. Reference the database in scripts or systems that require NPC attribute lookups.

Example

// Example 1: Retrieving an NPC attribute by name
NPCAttributeDatabase database = ...; // Reference to the ScriptableObject
NPCAttribute attribute;
if (database.TryGetNPCAttribute("Strength", out attribute))
{
    // Use the attribute as needed
}

Best Practices

  • Keep the Attributes list organized and avoid duplicate template names.
  • Use the database for all NPC attribute lookups to ensure consistency.
  • Validate that each NPCAttribute has a valid template assigned.
  • Use descriptive template names for easier searching and maintenance.
⚠️ **GitHub.com Fallback** ⚠️