Event Listening

The GameFlow API also exposes a series of subclasses of GFEvent that represent the different events that GameFlow is able to manage. These classes are the following:

Event subscription

Any object that implements the IEventListener interface can be added to the list of subscribers that will receive a notification when an event of a certain type is triggered. This allows your own scripts to react to events triggered by GameFlow programs.

The steps to follow to do this are:

  1. Implement in our script the IsListening() and EventReceived() methods of the IEventListener interface to filter and respond to events.

  2. Invoke the AddListener() static method of the type of event to which we want an instance of our script to subscribe.

In the following example, each instance of our MyEventHook script is subscribed to receive notifications of events of type GameStart. Each time one of these events is received, we will post a message on the console as an answer:

using GameFlow;
using UnityEngine;

namespace MyNamespace {

public class MyEventHook : MonoBehaviour, IEventListener {

    void Start() {
        GameStartEvent.AddListener(this);
    }

    public void EventReceived(GFEvent e) {
        Debug.Log("Game started!");
    }

    public bool IsListening() {
        return true;
    }

}

}

Last updated