//*********************************************************** // Filename: Event.cs // Author: Niclas Dobbertin // Last changes: Mittwoch, 8. August 2018 // Content: This file contains the abstract Event class and all inheriting Events used //*********************************************************** using System; using UnityEngine; /// /// This class defines an abstract Event from which all custom Events inherit /// /// The type of Event, has to inherit from this abstract class public abstract class Event where T : Event { // description that this event type has fired, mostly used to debug public string description; // true when an unique event has already fired, to prevent loops private bool hasFired; // signature Event listeners have to match public delegate void EventListener(T info); // contains all subscribed listeners private static event EventListener Listeners; /// /// Adds a method with fitting signature as listener to Listeners /// /// The method with fitting signature that should be called when the Event fires public static void RegisterListener(EventListener listener) { Listeners += listener; } /// /// Removes a method with fitting signature as listener to Listeners /// /// The method that should be removed as listener to that Event public static void UnregisterListener(EventListener listener) { Listeners -= listener; } /// /// Calls all registered listeners with child-specific info /// public void FireEvent() { if (hasFired) { throw new Exception("This event has already fired, to prevent infinite loops you can't refire an event"); } hasFired = true; if (Listeners != null) { Listeners(this as T); } } } /// /// This event is for debug purposes, unused verbosityLevel indicates importance of event /// public class DebugEvent : Event { public int verbosityLevel; } /// /// This event should fire when a new target gets instantiated /// public class TargetSpawnedEvent : Event { // The id (number of targets thus far starting with zero) of this target public int targetId; // The transform object of this target public Transform targetTransform; } /// /// This event should fire when a target is locked in and thus reached/destroyed /// public class TargetReachedEvent : Event { // The id (number of targets thus far starting with zero) of this target public int targetId; // The transform object of this target public Transform targetTransform; // The transform object of the player // TODO: check if transform should be replaced with Vector3 to avoid distortion through player movement public Transform playerTransform; // Realtime from target instantiation to lock in public float time; } /// /// This event should fire when the current experiment has finished /// public class ExperimentEndEvent : Event { // empty for now } /// /// This event should fire after a teleportation was executed /// public class TeleportEvent : Event { // Realtime on initiating the teleport by holding a controller button public float startTeleportTime; // Realtime when the teleport is finished and the user is in the new position public float endTeleportTime; // Coordinates of the player when initiating the teleport public Vector3 startUserPosition; // Rotation of the player when initiating the teleport public Vector3 startUserRotation; // Coordinates of the player when the teleport is finished public Vector3 endUserPosition; // Rotation of the player when the teleport is finished public Vector3 endUserRotation; }