Page cover image

⚑Events Module

Overview

Use the COZY system to directly impact your world in a quick manner. The lightweight Events Module will provide you with access to many simple hooks that you can use to link functions to various events that can happen in the COZY system.

For more advanced control. see the Habits Module.

Compatibility Information

Compatible with all modules however:

Key Features

Control Events by Time of Day

  • Run an event at dawn.

  • Run an event at morning.

  • Run an event at day.

  • Run an event at afternoon.

  • Run an event at evening.

  • Run an event at twilight.

  • Run an event at night.

Control Events by Time Passing

  • Run an event when an in-game minute passes.

  • Run an event when the hour changes.

  • Run an event when the day changes.

  • Run an event when the year changes.

Control Events Based on the Weather

  • Run an event when the weather changes.

  • Run events when a weather profile with a certain Event FX profile is playing.

Usage Examples

Turn a light on in the evening and off in the morning

This is incredibly simple within the Events Module! Simply create a point light in your scene and in the Events Module add two events. In the OnMorning section, add an event that disables the point light, and in the OnTwilight section add an event that enables it:

In this example, we use the OnMorning event instead of the OnDawn event because we want the light to stay on for a bit longer. Dawn will typically run right before the sun rises. Similarly, we use the OnTwilight event instead of the OnNight event because there will be a little bit of natural light left during twilight. These will combine to give your scene a very natural lighting system that keep your game well lit!

Add events that play during a certain weather type

Click the Add New Event FX Reference button

Now select your FX reference. This is an Event FX profile that is assigned to several weather profiles that all fit a certain type. By default, COZY ships with 3 Event FX types for rainy, snowy, and foggy weather but you can create your own Event FX Profiles using the right-click context menu.

Once your Event FX Reference is set, you can assign your events using the OnStart and OnStop Unity Events

For basic events, follow this C# script example. You can replace onDawn with any other COZY event that you want to listen to

using UnityEngine;
using DistantLands.Cozy;

public class EventRunningExample : MonoBehaviour
{

    private void OnEnable()
    {
        CozyWeather.Events.onDawn += PlayOnDawn;
    }

    private void OnDisable()
    {
        CozyWeather.Events.onDawn -= PlayOnDawn;
    }

    public void PlayOnDawn()
    {

    }
}

For events that play based on Event FX, you will need to follow this for your C# script

using UnityEngine;
using DistantLands.Cozy.Data; //Event FX Profiles are stored in this namespace

public class RunFunctionWhenWeatherTypeStartsOrStops : MonoBehaviour
{

    [Tooltip("Assign the weather FX that you want to draw events from here!")]
    public EventFX eventFX;

   void OnEnable()
    {

        eventFX.onCall += DoSomething;
        eventFX.onEnd += DoSomethingElse;

    }

void OnDisable()
    {

        eventFX.onCall -= DoSomething;
        eventFX.onEnd -= DoSomethingElse;

    }

    public void DoSomething()
    {

        //This function will run when weather profiles that have the eventFx FXProfile attatched to it begin playing.

    }

    public void DoSomethingElse()
    {

        //This function will run when weather profiles that have the eventFx FXProfile attatched to it stop playing.

    }
}

Last updated

Was this helpful?