Table of Contents

C#: Events

Events allow you to schedule Delay or Repeat callbacks - which will be called automatically by the simulation. Events are the last step to be executed by the simulation when ticking.


Delay Events

The AddDelay function takes in an Action, followed by the amount of seconds to delay. It will only be called once by the simulation. The valid types of Action delegates are:

  • Action
  • Action{double}

To create an event, make sure you inherit from one of the types below:

  • NominalSystems.Core.Component
  • NominalSystems.Core.ComponentModel
  • NominalSystems.Core.SimulationSystem
using NominalSystems.Core

public class MyComponent : Component
{
    void StopTicking()
    {
        bIsEnabled = false;
    }

    protected override void OnBegin(double time)
    {
        // Stop `MyComponent` after 20 seconds
        AddDelayEvent(StopTicking, 20);
    }
}

Repeat Events

The AddRepeat function takes in an Action, followed by the amount of seconds to repeat. It will be called by the simulation at the specified frequency.

The valid types of Action delegates are:

  • Action
  • Action{double}
  • Action{double, double}

To create an event, make sure you inherit from one of the types below:

  • NominalSystems.Core.Component
  • NominalSystems.Core.ComponentModel
  • NominalSystems.Core.SimulationSystem
using NominalSystems.Core

public class MyComponent : Component
{
    void ToggleTicking()
    {
        // Invert `IsEnabled` boolean value
        IsEnabled = !IsEnable;
    }

    protected override void OnBegin(double time)
    {
        // Toggle `MyComponent` every 20 seconds
        AddRepeatEvent(ToggleTicking, 20);
    }
}