FactionMatrixTemplate - jimdroberts/FishMMO GitHub Wiki

Description

Defines a ScriptableObject that stores a list of all faction templates and a matrix of alliance levels between them. Provides editor utilities to rebuild the matrix and update default relationships for all factions using Addressables.


API Access

Fields

  • public List Factions

    List of all faction templates included in this matrix. Used to define the set of factions and their relationships.

  • public FactionMatrix Matrix

    The matrix of alliance levels between all factions in Factions.

Properties

  • public string Name

    The display name of this faction matrix (from the ScriptableObject's name).

Methods

  • public void RebuildMatrix()

    Rebuilds the faction matrix by loading all FactionTemplate assets using Addressables. Initializes the Factions list and creates a new Matrix with default relationships.

  • public void RebuildFactions()

    Rebuilds the default relationships (allied, neutral, hostile) for each faction based on the matrix values. Clears existing relationships and sets new ones according to the alliance level in the matrix.


Basic Usage

Setup

  1. Create a new FactionMatrixTemplate ScriptableObject in your project.
  2. Use the custom editor to rebuild the matrix and assign all available FactionTemplate assets.
  3. Use the "Rebuild Factions" button to update default relationships for all factions.

Example

// Example 1: Creating and initializing a FactionMatrixTemplate
// 1. In the Unity Editor, create a new FactionMatrixTemplate asset.
// 2. Click "Rebuild Matrix" to load all FactionTemplate assets and initialize the matrix.
// 3. Click "Rebuild Factions" to update default relationships for each faction.

// Example 2: Accessing the matrix in code
var matrixTemplate = Resources.Load<FactionMatrixTemplate>("Path/To/Matrix");
var matrix = matrixTemplate.Matrix;
// Use matrix.Factions to query or modify relationships.

Best Practices

  • Always use the provided editor buttons to rebuild the matrix and factions to ensure data is up to date.
  • Ensure all FactionTemplate assets are properly tagged for Addressables to be found by the loader.
  • After editing relationships, use "Rebuild Factions" to update all default relationships for each faction.
⚠️ **GitHub.com Fallback** ⚠️