NRHandStatesService.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. public class NRHandStatesService : IHandStatesService
  12. {
  13. private NativeHandTracking m_NativeHandTracking;
  14. public bool IsRunning { private set; get; }
  15. public bool RunService()
  16. {
  17. if (m_NativeHandTracking == null)
  18. {
  19. m_NativeHandTracking = new NativeHandTracking();
  20. }
  21. bool success = m_NativeHandTracking.Start();
  22. if (success)
  23. {
  24. IsRunning = true;
  25. }
  26. return success;
  27. }
  28. public bool StopService()
  29. {
  30. if (m_NativeHandTracking != null)
  31. {
  32. bool success = m_NativeHandTracking.Stop();
  33. if (success)
  34. {
  35. IsRunning = false;
  36. }
  37. return success;
  38. }
  39. return false;
  40. }
  41. public void UpdateStates(HandState[] handStates)
  42. {
  43. if (m_NativeHandTracking != null)
  44. {
  45. m_NativeHandTracking.Update(handStates);
  46. }
  47. }
  48. public void PauseService()
  49. {
  50. if (m_NativeHandTracking != null)
  51. {
  52. bool success = m_NativeHandTracking.Pause();
  53. if (success)
  54. {
  55. IsRunning = false;
  56. }
  57. }
  58. }
  59. public void ResumeService()
  60. {
  61. if (m_NativeHandTracking != null)
  62. {
  63. bool success = m_NativeHandTracking.Resume();
  64. if (success)
  65. {
  66. IsRunning = true;
  67. }
  68. }
  69. }
  70. public void DestroyService()
  71. {
  72. if (m_NativeHandTracking != null)
  73. {
  74. bool success = m_NativeHandTracking.Destroy();
  75. if (success)
  76. {
  77. IsRunning = false;
  78. m_NativeHandTracking = null;
  79. }
  80. }
  81. }
  82. }
  83. }