namespace Zinnia.Tracking.CameraRig { using UnityEngine; using UnityEngine.XR; using Zinnia.Utility; /// /// A base implementation of the that utilises the to be extended upon further. /// public abstract class BaseDeviceDetailsRecord : DeviceDetailsRecord { /// public override bool IsConnected { get => XRDeviceProperties.IsTracked(XRNodeType); protected set => throw new System.NotImplementedException(); } /// public override string Manufacturer { get => XRDeviceProperties.Manufacturer(XRNodeType); protected set => throw new System.NotImplementedException(); } /// public override string Model { get => GetModelString(); protected set => throw new System.NotImplementedException(); } /// public override SpatialTrackingType TrackingType { get => GetTrackingType(); protected set => throw new System.NotImplementedException(); } /// public override float BatteryLevel { get => GetBatteryLevel(); protected set => throw new System.NotImplementedException(); } /// public override BatteryStatus BatteryChargeStatus { get => XRNodeType == XRNode.Head ? SystemInfo.batteryStatus : BatteryStatus.Unknown; protected set => throw new System.NotImplementedException(); } /// /// The last known battery charge status. /// protected BatteryStatus lastKnownBatteryStatus; /// /// The last known is connected status. /// protected bool? lastKnownIsConnected; /// /// The last known tracking type. /// protected SpatialTrackingType lastKnownTrackingType; /// protected override bool HasBatteryChargeStatusChanged() { BatteryStatus currentValue = BatteryChargeStatus; bool hasChanged = !currentValue.Equals(lastKnownBatteryStatus); if (hasChanged) { BatteryChargeStatusChanged?.Invoke(currentValue); lastKnownBatteryStatus = currentValue; } return hasChanged; } /// protected override bool HasIsConnectedChanged() { bool currentValue = IsConnected; bool hasChanged = currentValue != lastKnownIsConnected; if (hasChanged) { ConnectionStatusChanged?.Invoke(currentValue); lastKnownIsConnected = currentValue; } return hasChanged; } /// protected override bool HasTrackingTypeChanged() { SpatialTrackingType currentValue = TrackingType; bool hasChanged = !currentValue.Equals(lastKnownTrackingType); if (hasChanged) { TrackingTypeChanged?.Invoke(currentValue); lastKnownTrackingType = currentValue; } return hasChanged; } /// /// Gets the device model from the appropriate Unity library. /// /// The connected node device model. protected virtual string GetModelString() { if (XRNodeType == XRNode.Head && !SystemInfo.deviceModel.ToLower().Contains("system product name")) { return SystemInfo.deviceModel; } return XRDeviceProperties.Model(XRNodeType); } /// /// Gets the spatial tracking type. /// /// The tracking type for the node. protected virtual SpatialTrackingType GetTrackingType() { if (XRDeviceProperties.HasPositionalTracking(XRNodeType) && XRDeviceProperties.HasRotationalTracking(XRNodeType)) { return SpatialTrackingType.RotationAndPosition; } else if (XRDeviceProperties.HasRotationalTracking(XRNodeType)) { return SpatialTrackingType.RotationOnly; } return SpatialTrackingType.None; } /// /// Gets the battery level of the device. /// /// The device battery level. protected virtual float GetBatteryLevel() { if (XRNodeType == XRNode.Head) { return SystemInfo.batteryLevel; } return XRDeviceProperties.BatteryLevel(XRNodeType); } } }