Install the package.
Set up code to trigger events.
Write action methods.
Create events in the editor window
Events can be created by calling TextEvent.CreateRandom()
, TextEvent.CreateRandomWithLabel(string)
or CreateFromIndex(int)
.
Once an event is created it can be presented to the player by calling EnterEvent()
TextEvent.CreateRandom().EnterEvent();
or
TextEvent.CreateRandomWithLabel("Combat").EnterEvent();
Methods can be exposed to the editor window by decorating them with the TextEventAction atribute, passing in a friendly name for the action. int, float bool and string arguments are supported, the name and default values of the arguments are also exposed to the editor window. These methods can be set in the editor window to be triggered with a result.
using DevonMillar.TextEvents;
public class TextEventActions
{
static Player player;
[TextEventAction("Damage player")]
public static void DamagePlayer(float damage = 5.0f)
{
player.Damage(damage);
}
[TextEventAction("Give item")]
public static void GiveItem(string item)
{
player.GiveItem(item);
}
[TextEventAction("Add status effect")]
public static void AddStatusEffect(string effect)
{
player.AddStatusEffect(effect);
}
[TextEventAction("Remove status effect")]
public static void RemoveStatusEffect(string effect)
{
player.RemoveStatusEffect(effect);
}
}
Actions can now be added to results in the editor window
The text event editor can be opened by clicking the "Text Event Editor" button in the Tools menu.
Events contain choices, choices contain any number of results. Results contain any number of actions. A result is chosen at random when a choice is picked by the player.
Event > Choice > Result > Actions
Choices are the options that are given to the player in the event. Choices can contain any number of results. Choices can be folded in the editor
One child result is chosen at random when a choice is picked by the player.
Each result has a "Chance" variable that affects the chance of it being selected. A result can contain it's own text and any number of actions which will be executed if chosen. Results text is shown to the player if picked. If a result has no text the event will be exited as soon as it is chosen. Results can also contain other choices for branching choice events.
Actions are the effects that a result has. These are set up per project. They are executed when the parent result is chosen.
Action methods being removed from the codebase while they are in use will throw when trying to trigger the action
The editor tool may need to be closed and reopened on scirpt compilation.
Action methods must be public and static, and their arguments only support int, float, bool, string