1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // /******************************************************************************
- // * File: PointerViewerKeyboard.cs
- // * Copyright (c) 2023 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
- // *
- // *
- // ******************************************************************************/
- using QCHT.Interactions.Core;
- using QCHT.Interactions.Hands;
- using QCHT.Samples.Menu;
- using UnityEngine;
- using UnityEngine.XR.Interaction.Toolkit;
- namespace QCHT.Samples.XRKeyboard
- {
- public class PointerViewerKeyboard : PointerViewer
- {
- private Transform _leftHand, _righHand;
- [SerializeField] private float distanceToDesactivate = 0.5f;
- private Transform _keyboardTransform = null;
- public Transform KeyboardTransform
- {
- get => _keyboardTransform;
- set => _keyboardTransform = value;
- }
- [SerializeField] private bool _shouldHideHands = false;
- private bool _shouldShowRightHandsAndRays = true;
- private bool _shouldShowLeftHandsAndRays = true;
- private void Start()
- {
- _leftHand = XRHandTrackingManager.GetOrCreate().LeftHand.transform;
- _righHand = XRHandTrackingManager.GetOrCreate().RightHand.transform;
- }
- // Update is called once per frame
- protected override void Update()
- {
- if (!updateRays) return;
- //base.Update();
- var currentShowRight = _shouldShowRightHandsAndRays;
- var currentShowLeft = _shouldShowLeftHandsAndRays;
- if (_keyboardTransform == null)
- return;
- var keyboardPosition = _keyboardTransform.position;
- _shouldShowRightHandsAndRays =
- !(Vector3.Distance(keyboardPosition, _righHand.position) <= distanceToDesactivate);
- _shouldShowLeftHandsAndRays =
- !(Vector3.Distance(keyboardPosition, _leftHand.position) <= distanceToDesactivate);
- leftController.SetActive(_shouldShowLeftHandsAndRays && leftIsTracked.IsInProgress());
- rightController.SetActive(_shouldShowRightHandsAndRays && rightIsTracked.IsInProgress());
- if (_shouldHideHands)
- {
- //Hide hands
- if (currentShowLeft != _shouldShowLeftHandsAndRays)
- {
- if (_leftHand.TryGetComponent(out XRBaseController xrController) && xrController.model != null &&
- xrController.model.TryGetComponent(out IHideable hideable))
- {
- if (_shouldShowLeftHandsAndRays)
- hideable.Show();
- else
- hideable.Hide();
- }
- }
- if (currentShowRight != _shouldShowRightHandsAndRays)
- {
- if (_righHand.TryGetComponent(out XRBaseController xrController) && xrController.model != null &&
- xrController.model.TryGetComponent(out IHideable hideable))
- {
- if (_shouldShowRightHandsAndRays)
- hideable.Show();
- else
- hideable.Hide();
- }
- }
- }
- }
- }
- }
|