NPCAttributeDatabase - jimdroberts/FishMMO GitHub Wiki
ScriptableObject database for storing and retrieving NPC attributes by name. Provides centralized management and lookup for NPC attribute definitions in FishMMO.
-
public List Attributes
List of all NPC attributes in the database.
-
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.
-
- Create a new
NPCAttributeDatabase
ScriptableObject in the Unity Editor. - Add
NPCAttribute
entries to theAttributes
list via the Inspector. - Reference the database in scripts or systems that require NPC attribute lookups.
// 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
}
- 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.