EyeType.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using UnityEngine;
  3. namespace Leap.Unity
  4. {
  5. [Serializable]
  6. public class EyeType
  7. {
  8. public EyeType(EyeType.OrderType type)
  9. {
  10. this._orderType = type;
  11. }
  12. public EyeType.OrderType Type
  13. {
  14. get
  15. {
  16. return this._orderType;
  17. }
  18. }
  19. public bool IsLeftEye
  20. {
  21. get
  22. {
  23. if (!this._hasBegun)
  24. {
  25. throw new Exception("Cannot call IsLeftEye or IsRightEye before BeginCamera has been called!");
  26. }
  27. switch (this._orderType)
  28. {
  29. case EyeType.OrderType.LEFT:
  30. return true;
  31. case EyeType.OrderType.RIGHT:
  32. return false;
  33. case EyeType.OrderType.CENTER:
  34. return this._isOnFirst;
  35. default:
  36. throw new Exception("Unexpected order type " + this._orderType);
  37. }
  38. }
  39. }
  40. public bool IsRightEye
  41. {
  42. get
  43. {
  44. return !this.IsLeftEye;
  45. }
  46. }
  47. public void BeginCamera()
  48. {
  49. if (!this._hasBegun)
  50. {
  51. this._isOnFirst = true;
  52. this._hasBegun = true;
  53. }
  54. else
  55. {
  56. this._isOnFirst = !this._isOnFirst;
  57. }
  58. }
  59. public void Reset()
  60. {
  61. this._hasBegun = false;
  62. }
  63. private const string TARGET_EYE_PROPERTY_NAME = "m_TargetEye";
  64. private const int TARGET_EYE_LEFT_INDEX = 1;
  65. private const int TARGET_EYE_RIGHT_INDEX = 2;
  66. private const int TARGET_EYE_CENTER_INDEX = 3;
  67. [SerializeField]
  68. private EyeType.OrderType _orderType = EyeType.OrderType.LEFT;
  69. private bool _isOnFirst;
  70. private bool _hasBegun;
  71. public enum OrderType
  72. {
  73. LEFT = 1,
  74. RIGHT,
  75. CENTER
  76. }
  77. }
  78. }