CustomSkeletonHelper.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. using UnityEngine;
  3. using System.Collections;
  4. using Valve.VR;
  5. using UnityEngine.Serialization;
  6. namespace Valve.VR.InteractionSystem.Sample
  7. {
  8. public class CustomSkeletonHelper : MonoBehaviour
  9. {
  10. public Retargetable wrist;
  11. public Finger[] fingers;
  12. public Thumb[] thumbs;
  13. private void Update()
  14. {
  15. for (int fingerIndex = 0; fingerIndex < fingers.Length; fingerIndex++)
  16. {
  17. Finger finger = fingers[fingerIndex];
  18. finger.metacarpal.destination.rotation = finger.metacarpal.source.rotation;
  19. finger.proximal.destination.rotation = finger.proximal.source.rotation;
  20. finger.middle.destination.rotation = finger.middle.source.rotation;
  21. finger.distal.destination.rotation = finger.distal.source.rotation;
  22. }
  23. for (int thumbIndex = 0; thumbIndex < thumbs.Length; thumbIndex++)
  24. {
  25. Thumb thumb = thumbs[thumbIndex];
  26. thumb.metacarpal.destination.rotation = thumb.metacarpal.source.rotation;
  27. thumb.middle.destination.rotation = thumb.middle.source.rotation;
  28. thumb.distal.destination.rotation = thumb.distal.source.rotation;
  29. }
  30. wrist.destination.position = wrist.source.position;
  31. wrist.destination.rotation = wrist.source.rotation;
  32. }
  33. public enum MirrorType
  34. {
  35. None,
  36. LeftToRight,
  37. RightToLeft
  38. }
  39. [System.Serializable]
  40. public class Retargetable
  41. {
  42. public Transform source;
  43. public Transform destination;
  44. public Retargetable(Transform source, Transform destination)
  45. {
  46. this.source = source;
  47. this.destination = destination;
  48. }
  49. }
  50. [System.Serializable]
  51. public class Thumb
  52. {
  53. public Retargetable metacarpal;
  54. public Retargetable middle;
  55. public Retargetable distal;
  56. public Transform aux;
  57. public Thumb(Retargetable metacarpal, Retargetable middle, Retargetable distal, Transform aux)
  58. {
  59. this.metacarpal = metacarpal;
  60. this.middle = middle;
  61. this.distal = distal;
  62. this.aux = aux;
  63. }
  64. }
  65. [System.Serializable]
  66. public class Finger
  67. {
  68. public Retargetable metacarpal;
  69. public Retargetable proximal;
  70. public Retargetable middle;
  71. public Retargetable distal;
  72. public Transform aux;
  73. public Finger(Retargetable metacarpal, Retargetable proximal, Retargetable middle, Retargetable distal, Transform aux)
  74. {
  75. this.metacarpal = metacarpal;
  76. this.proximal = proximal;
  77. this.middle = middle;
  78. this.distal = distal;
  79. this.aux = aux;
  80. }
  81. }
  82. }
  83. }