PoseIndicator.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*===============================================================================
  2. Copyright (C) 2022 Immersal - Part of Hexagon. All Rights Reserved.
  3. This file is part of the Immersal SDK.
  4. The Immersal SDK cannot be copied, distributed, or made available to
  5. third-parties for commercial purposes without written permission of Immersal Ltd.
  6. Contact sdk@immersal.com for licensing requests.
  7. ===============================================================================*/
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. namespace Immersal.Samples.Util
  11. {
  12. [RequireComponent(typeof(Image))]
  13. public class PoseIndicator : MonoBehaviour {
  14. public enum IndicatorMode { multiplyColor, changeSprite };
  15. public IndicatorMode indicatorMode = IndicatorMode.multiplyColor;
  16. public Color noPose;
  17. public Color weakPose;
  18. public Color goodPose;
  19. public Color excellentPose;
  20. public Sprite noPoseSprite;
  21. public Sprite weakPoseSprite;
  22. public Sprite goodPoseSprite;
  23. public Sprite excellentPoseSprite;
  24. private Image m_Image;
  25. private ImmersalSDK m_Sdk;
  26. void Start () {
  27. m_Image = GetComponent<Image>();
  28. m_Sdk = ImmersalSDK.Instance;
  29. if (indicatorMode == IndicatorMode.multiplyColor)
  30. {
  31. m_Image.color = noPose;
  32. }
  33. }
  34. void Update ()
  35. {
  36. int q = m_Sdk.TrackingQuality;
  37. if (indicatorMode == IndicatorMode.multiplyColor)
  38. {
  39. switch (q)
  40. {
  41. case 0:
  42. m_Image.color = noPose;
  43. break;
  44. case 1:
  45. m_Image.color = weakPose;
  46. break;
  47. case 2:
  48. m_Image.color = goodPose;
  49. break;
  50. default:
  51. m_Image.color = excellentPose;
  52. break;
  53. }
  54. }
  55. else if (indicatorMode == IndicatorMode.changeSprite)
  56. {
  57. switch (q)
  58. {
  59. case 0:
  60. m_Image.sprite = noPoseSprite;
  61. break;
  62. case 1:
  63. m_Image.sprite = weakPoseSprite;
  64. break;
  65. case 2:
  66. m_Image.sprite = goodPoseSprite;
  67. break;
  68. default:
  69. m_Image.sprite = excellentPoseSprite;
  70. break;
  71. }
  72. }
  73. }
  74. }
  75. }