GameCalendarKit.Events - Gravideots/GameCalendarKit GitHub Wiki

GameTimeKit contain six events in three class and four type of Event Object. You can use them by add your method to event like on example below:

Example

Initialize GameCalendar in Calendar variable:

public GameCalendar Calendar;

create method DayOver that will wait when event CalendarDayEndEvent invoke.

private void DayOver(object source, GameClockEventObject clockObject)
{
    print("Day is over, current time is: " + clockObject.Hour + ":" + clockObject.Minute);
}

add DayOver to Calendar.CalendarDayEndEvent event:

void Start()
{
    Calendar.CalendarDayEndEvent += DayOver;
}

after invoke CalendarDayEndEvent, print() inside DayOver method will execute.

All Events

GameCalendar

  • CalendarTimeChangedEvent is event method which will be launched every game seconds.
   public event EventHandler<GameClockEventObject> CalendarTimeChangedEvent;
  • CalendarDayEndEvent is event method which will be launched at the end of the working day.
   public event EventHandler<GameClockEventObject> CalendarDayEndEvent;
  • CalendarEventStarted is event method which will be launched when and if new event started.
   public event EventHandler<GameCalendarEventObjectList> CalendarEventStarted;
  • CalendarEventEnded is event method which will be launched when any event ended.
   public event EventHandler<GameCalendarEventObjectList> CalendarEventEnded;

GameClock

  • MinuteEndEvent is a event method which will be launched when game minute ending.
  public event EventHandler<GameClockEventObject> TimeChangedEvent;
  • DayEndEvent is a event method which will be launched when game day ending.
  public event EventHandler<GameClockEventObject> DayEndEvent;

Ticker

  • TickEvent is a event method which will be launched when tick counted from private method OnTimedEvent().
  public event EventHandler<TickEventObject> TickEvent;

Events Objects

Event Object is a class successor of EventArgs, that contain some custom fields whit base and custom information such as:

  • Status
  • DateTime
  • Title
  • etc

some of Event Object have a partial keyword, that mean you can extend class and add you own realization.

   [Serializable]
   public partial class GameCalendarEventObject : EventArgs

GameCalendarEventObject

Constructor method:

public GameCalendarEventObject(DateTime dateStart, DateTime dateEnd, string title)
{
    _dateStart = dateStart.ToString();
    _dateEnd = dateEnd.ToString();
    _title = title;
}

Base property which care information about current event, such as:

public DateTime DateStart;
public DateTime DateEnd;
public string Title;

Partial example

This object has a partial keyword that give you a possibility to extend current class and create your own event object.

public partial class GameCalendarEventObject
{
    public GameCalendarEventObject(DateTime dateStart, DateTime dateEnd, string title, string text)
    {
        _dateStart = dateStart.ToString();
        _dateEnd = dateEnd.ToString();
        _title = title;
        _text = text;
    }

    [SerializeField]
    string _text;

    public string Text
    {
        get
        {
            return _text;
        }
    }
}

this example add new serialized field and property Text to base class GameCalendarEventObject.

GameClockEventObject

Constructor method:

public GameClockEventObject(bool status, int hour, int minute)
{
    _status = status;
    _hour = hour;
    _minute = minute;
}

Base property which care information about current time and status, such as:

public bool Status;

public int Hour;

public int Minute;

TickEventObject

Constructor method:

public TickEventObject(bool status, int curentTickIteration, int curentIntervalIteration)
{
    _status = status;
    _curentTickIteration = curentTickIteration;
    _curentIntervalIteration = curentIntervalIteration;
}

and contain base property which care information about current tick, such as:

  • Status - when ticks iteration is over this value will be false, otherwise it's true.
  • CurentTick
public bool Status;
public int CurentTick;