// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using UnityEngine; using UnityEngine.EventSystems; namespace Microsoft.MixedReality.Toolkit { /// /// Generic Base Event Data for Sending Events through the Event System. /// public class GenericBaseEventData : BaseEventData { /// /// The Event Source that the event originates from. /// public IMixedRealityEventSource EventSource { get; private set; } /// /// The UTC time at which the event occurred. /// public DateTime EventTime { get; private set; } /// /// The BaseEventData.selectedObject is explicitly hidden because access to it /// (either via get or set) throws a NullReferenceException in typical usage within /// the MRTK. Prefer using the subclasses own fields to access information about /// the event instead of fields on BaseEventData. /// /// /// BaseEventData is only used because it's part of Unity's EventSystem dispatching, /// so this code must subclass it in order to leverage EventSystem.ExecuteEvents /// public new GameObject selectedObject { get; protected set; } /// /// Constructor. /// /// Usually EventSystems.EventSystem.current public GenericBaseEventData(EventSystem eventSystem) : base(eventSystem) { } /// /// Used to initialize/reset the event and populate the data. /// /// The source of the event. protected void BaseInitialize(IMixedRealityEventSource eventSource) { Reset(); EventTime = DateTime.UtcNow; EventSource = eventSource; } } }