Models

Models are special data storing and management classes. Instead of building all the variable references and storing them yourself, you can rely on models to do the heavy lifting for you.

For example:

You could call the API directly to fetch the current amount of energy the user has and store this value yourself to show it up on your UI. Later on you can call the API directly to consume some amount of the energy and update your stored value manually.

Instead you can rely on the Energy model which will contain the currently available energy when the user information is fetched, and you can call the Colizeum.User.energy.Consume() method to consume a specific amount of energy which will automatically update the values in the model

private void Awake() {
    Colizeum.Auth.GetUser();
}

public void ConsumeEnergy() {
    var energyToConsume = 10;
    
    // For example, lets say the user has 100 energy
    Debug.Log(Colizeum.User.energy.current);
    
    Colizeum.User.energy.Consume(energyToConsme, null, () => {
        // This will return that user now has 90 energy
        Debug.Log(Colizeum.User.energy.current);        
    });
}

Last updated