namespace Zinnia.Tracking.CameraRig { using System; using UnityEngine; using UnityEngine.Events; using UnityEngine.XR; using Zinnia.Process; /// /// Provides the basis for describing a CameraRig Alias device details and status. /// public abstract class DeviceDetailsRecord : MonoBehaviour, IProcessable { /// /// Defines the event with the . /// [Serializable] public class BoolUnityEvent : UnityEvent { } /// /// Defines the event with the . /// [Serializable] public class SpatialTrackingTypeUnityEvent : UnityEvent { } /// /// Defines the event with the . /// [Serializable] public class BatteryStatusUnityEvent : UnityEvent { } /// /// The types of spatial tracking available. /// public enum SpatialTrackingType { /// /// An unknown tracking type. /// Unknown, /// /// 0 degrees of freedom, does not track rotation or position of a static device. /// None, /// /// 3 degrees of freedom, only rotational tracking of yaw, pitch and roll rotations. /// RotationOnly, /// /// 6 degrees of freedom, including rotational tracking as well as positional tracking of horizontal, vertical and depth movement. /// RotationAndPosition } /// /// The type of XR node the device is representing. /// public abstract XRNode XRNodeType { get; protected set; } /// /// Whether the device is currently connected. /// public abstract bool IsConnected { get; protected set; } /// /// The priority this device has over any similar devices. /// public abstract int Priority { get; protected set; } /// /// The manufacturer name of the device. /// public abstract string Manufacturer { get; protected set; } /// /// The model name of the device. /// public abstract string Model { get; protected set; } /// /// The spatial tracking type that the device is tracking with. /// public abstract SpatialTrackingType TrackingType { get; protected set; } /// /// The current level of charge in the battery in percentage. /// public abstract float BatteryLevel { get; protected set; } /// /// The current battery charge state. /// public abstract BatteryStatus BatteryChargeStatus { get; protected set; } /// /// Whether the device has a pass through camera. /// public abstract bool HasPassThroughCamera { get; protected set; } /// /// Whether tracking for this device has begun. /// public bool TrackingHasBegun { get; protected set; } /// /// The backing field for the property. /// private bool passThroughCameraEnabled; /// /// Whether the headset passthrough camera is enabled or disabled. /// public bool PassThroughCameraEnabled { get { return passThroughCameraEnabled; } set { if (!HasPassThroughCamera) { return; } passThroughCameraEnabled = value; if (passThroughCameraEnabled) { EnablePassThrough(); } else { DisablePassThrough(); } } } /// /// Emitted when the device begins tracking. /// public UnityEvent TrackingBegun = new UnityEvent(); /// /// Emitted whenever the connection status changes. /// public BoolUnityEvent ConnectionStatusChanged = new BoolUnityEvent(); /// /// Emitted whenever the tracking type changes. /// public SpatialTrackingTypeUnityEvent TrackingTypeChanged = new SpatialTrackingTypeUnityEvent(); /// /// Emitted whenever the tracking type changes. /// public BatteryStatusUnityEvent BatteryChargeStatusChanged = new BatteryStatusUnityEvent(); /// /// Emitted when the pass through camera is enabled. /// public UnityEvent PassThroughCameraWasEnabled = new UnityEvent(); /// /// Emitted when the pass through camera is disabled. /// public UnityEvent PassThroughCameraWasDisabled = new UnityEvent(); /// /// Checks to see if the statues have changed. /// public virtual void Process() { HasTrackingBegun(); HasIsConnectedChanged(); HasTrackingTypeChanged(); HasBatteryChargeStatusChanged(); } /// /// Sets the pass through state on the camera based on the current state. /// public virtual void SetPassThrough() { if (!HasPassThroughCamera) { return; } if (PassThroughCameraEnabled) { EnablePassThrough(); } else { DisablePassThrough(); } } /// /// Checks to see if the has changed. /// /// Whether the status has changed or not. protected abstract bool HasBatteryChargeStatusChanged(); /// /// Checks to see if the has changed. /// /// Whether the status has changed or not. protected abstract bool HasIsConnectedChanged(); /// /// Checks to see if the has changed. /// /// Whether the status has changed or not. protected abstract bool HasTrackingTypeChanged(); protected virtual void OnEnable() { TrackingHasBegun = false; } /// /// Determines whether tracking for this device has begun. /// /// Whether tracking for this device has begun. protected virtual bool HasTrackingBegun() { if (!TrackingHasBegun && IsConnected) { TrackingBegun?.Invoke(); TrackingHasBegun = true; return true; } return false; } /// /// Enables the pass through on the camera. /// protected virtual void EnablePassThrough() { PassThroughCameraWasEnabled?.Invoke(); } /// /// Disables the pass through on the camera. /// protected virtual void DisablePassThrough() { PassThroughCameraWasDisabled?.Invoke(); } } }