IStatus

MonoBehaviours that inherit IStatus will be able to add and remove status effects.

IStatus needs a public list of effects to be defined as well as the method OnStatusEffect. Here is a simple example class using that implementation:

// Need to use StatusEffects namespace.
using StatusEffects;
using UnityEngine;
// Inheriting from MonoBehaviour and IStatus.
public class Example : MonoBehaviour, IStatus
{
    public List<StatusEffect> effects { get; set; }
    
    public void OnStatusEffect(StatusEffect statusEffect, bool started) { }
}

Extensions

After inheriting, the class will now be able to call extension methods specific to the Status Effect Framework. For more information on what exactly is available see StatusManager.

// Examples using the add and remove status effect extension.
public StatusEffectData slownessEffect;
public float effectTime = 5;

public void OnDamageTaken()
{
    // Note that if no effect time 
    // is given it will be infinite.
    this.AddStatusEffect(slownessEffect, effectTime);
}

public void OnLevelCompleted()
{
    // Use this to remove all status effects.
    this.RemoveAllStatusEffects();
    // Use this to remove a specific status effect.
    this.RemoveStatusEffect(slownessEffect);
}

Effects

The effects list will dynamically update as effects are added or removed. It is recommended to not directly add or remove using the list methods and instead only interact with it from a read only permission and the extension methods.

OnStatusEffect

The method OnStatusEffect will be called everytime there is a change to the effect list of the IStatus class. Its parameters return the updated effect and a bool of whether the effect was started or stopped. If a project requires an on screen effect UI this method would be ideal to use in tandem with public actions subscription on each StatusEffect's started and stopped event.

Last updated