Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

  1. /************************************************************************************
  2. Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. See SampleFramework license.txt for license terms. Unless required by applicable law
  4. or agreed to in writing, the sample code is provided AS IS WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied. See the license for specific
  6. language governing permissions and limitations under the license.
  7. ************************************************************************************/
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. using UnityEngine.Assertions;
  12. public class HandsActiveChecker : MonoBehaviour
  13. {
  14. [SerializeField]
  15. private GameObject _notificationPrefab = null;
  16. private GameObject _notification = null;
  17. private OVRCameraRig _cameraRig = null;
  18. private Transform _centerEye = null;
  19. private void Awake()
  20. {
  21. Assert.IsNotNull(_notificationPrefab);
  22. _notification = Instantiate(_notificationPrefab);
  23. StartCoroutine(GetCenterEye());
  24. }
  25. private void Update()
  26. {
  27. if (OVRPlugin.GetHandTrackingEnabled())
  28. {
  29. _notification.SetActive(false);
  30. }
  31. else
  32. {
  33. _notification.SetActive(true);
  34. if (_centerEye) {
  35. _notification.transform.position = _centerEye.position + _centerEye.forward * 0.5f;
  36. _notification.transform.rotation = _centerEye.rotation;
  37. }
  38. }
  39. }
  40. private IEnumerator GetCenterEye()
  41. {
  42. if ((_cameraRig = FindObjectOfType<OVRCameraRig>()) != null)
  43. {
  44. while (!_centerEye)
  45. {
  46. _centerEye = _cameraRig.centerEyeAnchor;
  47. yield return null;
  48. }
  49. }
  50. }
  51. }