Module
Abstract Scriptable Object
Description
UniTask Support
Abstract Methods
Example
using System.Collections;
using UnityEngine;
// Use StatusEffects.Modules namespace for organization.
namespace StatusEffects.Modules
{
// Setup scriptable object in create menu.
[CreateAssetMenu(fileName = "Damage Over Time Effect", menuName = "Status Effect Framework/Custom Effects/Damage Over Time", order = 1)]
// This attribute will attach the module instance so
// that the interval time can be unique to each effect.
[AttachModuleInstance(typeof(DamageOverTimeInstance))]
public class DamageOverTimeEffect : CustomEffect
{
public override IEnumerator EnableModule<T>(T monoBehaviour, StatusEffect statusEffect, ModuleInstance moduleInstance)
{
// Note that for this module it uses a ModuleInstance
// to store a unique interval rate.
DamageOverTimeInstance damageOverTimeInstance = moduleInstance as DamageOverTimeInstance;
if (monoBehaviour.TryGetComponent(out ExampleEntity entity))
// Infinite loop will be cancelled when coroutine is stopped.
for (; ; )
{
// Reduce health based on the Statu Effect base value.
entity.health -= statusEffect.data.baseValue;
// Wait for the interval before applying the damage again.
yield return new WaitForSeconds(damageOverTimeInstance.intervalSeconds);
}
}
// You don't need to have anything in the disable method if you don't need to.
public override void DisableModule<T>(T monoBehaviour, StatusEffect statusEffect, ModuleInstance moduleInstance) { }
}Last updated