HandProxy.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Leap.Unity
  4. {
  5. public class HandProxy : HandRepresentation
  6. {
  7. public HandProxy(HandPool parent, Hand hand, Chirality repChirality, ModelType repType) : base(hand.Id, hand, repChirality, repType)
  8. {
  9. this.parent = parent;
  10. base.RepChirality = repChirality;
  11. base.RepType = repType;
  12. base.MostRecentHand = hand;
  13. }
  14. public override void Finish()
  15. {
  16. if (this.handModels != null)
  17. {
  18. for (int i = 0; i < this.handModels.Count; i++)
  19. {
  20. this.handModels[i].FinishHand();
  21. this.parent.ReturnToPool(this.handModels[i]);
  22. this.handModels[i] = null;
  23. }
  24. }
  25. this.parent.RemoveHandRepresentation(this);
  26. }
  27. public override void AddModel(IHandModel model)
  28. {
  29. if (this.handModels == null)
  30. {
  31. this.handModels = new List<IHandModel>();
  32. }
  33. this.handModels.Add(model);
  34. if (model.GetLeapHand() == null)
  35. {
  36. model.SetLeapHand(base.MostRecentHand);
  37. model.InitHand();
  38. model.BeginHand();
  39. model.UpdateHand();
  40. }
  41. else
  42. {
  43. model.SetLeapHand(base.MostRecentHand);
  44. model.BeginHand();
  45. }
  46. }
  47. public override void RemoveModel(IHandModel model)
  48. {
  49. if (this.handModels != null)
  50. {
  51. model.FinishHand();
  52. this.handModels.Remove(model);
  53. }
  54. }
  55. public override void UpdateRepresentation(Hand hand)
  56. {
  57. base.UpdateRepresentation(hand);
  58. if (this.handModels != null)
  59. {
  60. for (int i = 0; i < this.handModels.Count; i++)
  61. {
  62. this.handModels[i].SetLeapHand(hand);
  63. this.handModels[i].UpdateHand();
  64. }
  65. }
  66. }
  67. private HandPool parent;
  68. public List<IHandModel> handModels;
  69. }
  70. }