Inventory Pro

Character stats

Equipment stats can be defined using the editor, this tutorial is only about using the stats inside your own code. First of let’s create a new class outside the InventorySystem folder and name it MyStatsReader.cs To retrieve the stats we first need to grab the stats container (CharacterUI) from our player. If you only use a single player you can use the following code.

var myPlayer = InventoryPlayerManager.instance.currentPlayer;
var myCharacterCollection = myPlayer.characterCollection; // Grab the stats container / character collection.

If you have multiple characters in your scene you'll have to grab the player or character collection you wish to use manually. Which all depends on your own architecture.

MyStatsReader example

Of course you can also serialize the category and stat names to strings.

public class MyStatsReader : MonoBehaviour
    public CharacterUI myCharacterCollection; // Reference to the characterUI we wish to get stats from - Assign in the inspector.

    public void Start()
        var myStat = myCharacterCollection.stats.Get("categoryName", "statName");
        if (myStat == null)
            Debug.LogWarning("No such stat exists");
        Debug.Log(myStat.currentValue); // final value can be used for calculations
        Debug.Log(myStat.ToString()); // Formatted name of stat

        // Changing stats
        myStat.ChangeCurrentValueRaw(10f); // Add +10 to our stat.
        myStat.ChangeFactor(-0.1f); // Remove 10% of our stat.
        myStat.SetMaxValueRaw(200f, false); // Set the max value (this is the raw value, so max health can still be increased by the factorMax).

        // And read our value
        Debug.Log("Value after transmutations: " + myStat.currentValue);