// // /*=============================================================================== // // Copyright (C) 2025 PhantomsXR Ltd. All Rights Reserved. // // // // This file is part of the Phantom.XRMOD.QuestModule.Runtime. // // // // The XR-MOD cannot be copied, distributed, or made available to // // third-parties for commercial purposes without written permission of PhantomsXR Ltd. // // // // Contact nswell@phantomsxr.com for licensing requests. // // ===============================================================================*/ using System; using Phantom.XRMOD.ActionNotification.Runtime; using Phantom.XRMOD.Core.Runtime; using Phantom.XRMOD.XRMODInput.Runtime; namespace Phantom.XRMOD.QuestModule.Runtime { /// /// Feature decorator for switching between different interaction inputs on Meta Quest. /// /// Listens for input switch notifications and activates/deactivates corresponding controllers (Hands, XR Controllers, etc.). /// /// public class MetaQuestInteracterSwitherDecorator : BaseMetaQuestFeatureDecorator { private ArchitectureComponentsModel architectureComponentsModel; /// /// Initializes a new instance of the class. /// public MetaQuestInteracterSwitherDecorator() { architectureComponentsModel = IocContainer.GetIoc.Resolve(); } /// /// Starts the input switcher algorithm. /// /// Subscribes to the "SwitchInput" notification. /// /// public override void StartAlgorithm() { base.StartAlgorithm(); ActionNotificationCenter.DefaultCenter.AddObserver(SwitchInput, nameof(SwitchInput)); } /// /// Determines if this feature is supported. /// /// Always returns true. public override bool SupportThisFeature() { return true; } /// /// Pauses the algorithm. (No implementation). /// public override void PauseAlgorithm() { } /// /// Stops the algorithm and unsubscribes from the "SwitchInput" notification. /// public override void StopAlgorithm() { ActionNotificationCenter.DefaultCenter.RemoveObserver(nameof(SwitchInput)); } /// /// Callback handler for input switching notifications. /// /// Notification data containing the to switch to. private void SwitchInput(BaseNotificationData _notification) { architectureComponentsModel.XRInputModalityManager.enabled = false; var tmp_InputType = (InputType) _notification.ObjectData; switch (tmp_InputType) { case InputType.NatureHands: architectureComponentsModel.LeftController.gameObject.SetActive(false); architectureComponentsModel.RightController.gameObject.SetActive(false); architectureComponentsModel.LeftHandController.gameObject.SetActive(true); architectureComponentsModel.RightHandController.gameObject.SetActive(true); break; case InputType.KeyboardNMouse: case InputType.GamePad: architectureComponentsModel.LeftController.gameObject.SetActive(false); architectureComponentsModel.RightController.gameObject.SetActive(false); architectureComponentsModel.LeftHandController.gameObject.SetActive(false); architectureComponentsModel.RightHandController.gameObject.SetActive(false); break; case InputType.XRController: architectureComponentsModel.LeftController.gameObject.SetActive(true); architectureComponentsModel.RightController.gameObject.SetActive(true); architectureComponentsModel.LeftHandController.gameObject.SetActive(false); architectureComponentsModel.RightHandController.gameObject.SetActive(false); break; case InputType.Unknown: architectureComponentsModel.XRInputModalityManager.enabled = true; break; default: throw new ArgumentOutOfRangeException(); } } } }