// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) 2022 Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% namespace UnityEngine.XR.MagicLeap { /// /// MLHeadsetFit Summary placeholder. /// public partial class MLHeadsetFit : MLAutoAPISingleton { /// /// Represents the different fit status that the system can report. /// If status is neither NotWorn nor Unknown, then headset is being worn. /// public enum Status { /// /// Headset fit status not available for unknown reason. /// Unknown = 0, /// /// Headset not worn. /// NotWorn, /// /// Good fit. /// GoodFit, /// /// Bad fit. /// BadFit, }; /// /// Headset fit state /// public readonly struct State { /// /// Headset fit status /// public readonly Status FitStatus; /// /// The epoch time of the last update in microseconds. /// public readonly long Timestamp; internal State(Status status, long timestamp) { FitStatus = status; Timestamp = timestamp; } } #region MLAutoAPISingleton /// /// Start the API. /// protected override MLResult.Code StartAPI() => Instance.InternalMLHeadsetFitCreateClient(); /// /// Stop the API. /// protected override MLResult.Code StopAPI() => Instance.InternalMLHeadsetFitDestroyClient(); /// /// Handle Unity application pause and resume /// /// If the application is now paused or not protected override void OnApplicationPause(bool pauseStatus) { base.OnApplicationPause(pauseStatus); if (pauseStatus) { Instance.InternalMLHeadsetFitDestroyClient(); } else { Instance.InternalMLHeadsetFitCreateClient(); } } #endregion /// /// Gets information about the user's current headset fit. /// public static MLResult GetState(out State state) => MLResult.Create(Instance.InternalMLHeadsetFitGetState(out state)); /// /// Creates a headset fit client. /// private MLResult.Code InternalMLHeadsetFitCreateClient() { var resultCode = NativeBindings.MLHeadsetFitCreateClient(out Handle); MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLHeadsetFitCreateClient)); return resultCode; } /// /// Destroys headset fit client. /// private MLResult.Code InternalMLHeadsetFitDestroyClient() { var resultCode = NativeBindings.MLHeadsetFitDestroyClient(Handle); MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLHeadsetFitDestroyClient)); return resultCode; } /// /// Gets information about the user's current headset fit. /// private MLResult.Code InternalMLHeadsetFitGetState(out State state) { var nativeState = NativeBindings.MLHeadsetFitState.Create(); var resultCode = NativeBindings.MLHeadsetFitGetState(Handle, out nativeState); MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLHeadsetFitGetState)); state = new State(nativeState.FitStatus, nativeState.EpochTimestampUs); return resultCode; } } }