RigidFinger.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using UnityEngine;
  3. namespace Leap.Unity
  4. {
  5. public class RigidFinger : SkeletalFinger
  6. {
  7. private void Start()
  8. {
  9. for (int i = 0; i < this.bones.Length; i++)
  10. {
  11. if (this.bones[i] != null)
  12. {
  13. this.bones[i].GetComponent<Rigidbody>().maxAngularVelocity = float.PositiveInfinity;
  14. }
  15. }
  16. }
  17. public override void UpdateFinger()
  18. {
  19. for (int i = 0; i < this.bones.Length; i++)
  20. {
  21. if (this.bones[i] != null)
  22. {
  23. CapsuleCollider component = this.bones[i].GetComponent<CapsuleCollider>();
  24. if (component != null)
  25. {
  26. component.direction = 2;
  27. this.bones[i].localScale = new Vector3(1f / base.transform.lossyScale.x, 1f / base.transform.lossyScale.y, 1f / base.transform.lossyScale.z);
  28. component.radius = base.GetBoneWidth(i) / 2f;
  29. component.height = base.GetBoneLength(i) + base.GetBoneWidth(i);
  30. }
  31. Rigidbody component2 = this.bones[i].GetComponent<Rigidbody>();
  32. if (component2)
  33. {
  34. component2.MovePosition(base.GetBoneCenter(i));
  35. component2.MoveRotation(base.GetBoneRotation(i));
  36. }
  37. else
  38. {
  39. this.bones[i].position = base.GetBoneCenter(i);
  40. this.bones[i].rotation = base.GetBoneRotation(i);
  41. }
  42. }
  43. }
  44. }
  45. public float filtering = 0.5f;
  46. }
  47. }