Custom Effects

If you want to create new effects or conditions, you can create a new script that inherits from ConditionData or EffectData, and override one of the functions.

Effects

For example, let's create a new effect that destroy all the Actor near the player: EffectDestroyNearby.cs

using UnityEngine;
using DialogueQuests;

[CreateAssetMenu(fileName = "condition", menuName = "DialogueQuests/Effects/DestroyNearby", order = 10)]
public class EffectDestroyNearby : EffectData
{
    public override void DoEffect(NarrativeEvent evt, NarrativeEffect effect, Actor player, Actor triggerer)
    {
        if(player != null)
        {
            foreach(Actor actor in Actor.GetAll())
            {
                float dist = (actor.transform.position - player.transform.position).magnitude;
                if(actor != player && dist < effect.value_float)
                {
                    GameObject.Destroy(actor.gameObject);
                }
            }
        }
    }
    
    public override bool ShowValueFloat()
    {
        return true;
    }
    
    public override string GetLabelValueFloat()
    {
        return "Range";
    }
}

The effect will loop on all actors and check the range with the player who triggered the event, if the actor isn't the player and is also within the range, it will be destroyed. The other function defines which values should appear in the unity inspector, in this case it is only a float value named Range.

Data Files

We will now create the data files for the effect we just created (the other effects are in the Resources folder). And then Link it to the ability.

In Unity, right click inside a folder, and select Create -> DialogueQuests-> Effects, select your new effect, it should be named what you set in the tag [CreateAssetMenu] in your new script.

You can now add conditions to any NarrativeEffect in your dialogues and events.

Other Values

If you want to see the list of possible values that can be displayed in the inspector for effects, open the EffectData.cs script and you will see all the available functions that can be overriden.

Last updated