HandDrop.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace Leap.Unity
  5. {
  6. public class HandDrop : HandTransitionBehavior
  7. {
  8. protected override void Awake()
  9. {
  10. base.Awake();
  11. this.palm = base.GetComponent<HandModel>().palm;
  12. this.startingPalmPosition = this.palm.localPosition;
  13. this.startingOrientation = this.palm.localRotation;
  14. }
  15. protected override void HandFinish()
  16. {
  17. base.StartCoroutine(this.LerpToStart());
  18. }
  19. protected override void HandReset()
  20. {
  21. base.StopAllCoroutines();
  22. }
  23. private IEnumerator LerpToStart()
  24. {
  25. Vector3 droppedPosition = this.palm.localPosition;
  26. Quaternion droppedOrientation = this.palm.localRotation;
  27. float duration = 0.25f;
  28. float startTime = Time.time;
  29. float endTime = startTime + duration;
  30. while (Time.time <= endTime)
  31. {
  32. float t = (Time.time - startTime) / duration;
  33. this.palm.localPosition = Vector3.Lerp(droppedPosition, this.startingPalmPosition, t);
  34. this.palm.localRotation = Quaternion.Lerp(droppedOrientation, this.startingOrientation, t);
  35. yield return null;
  36. }
  37. yield break;
  38. }
  39. private Vector3 startingPalmPosition;
  40. private Quaternion startingOrientation;
  41. private Transform palm;
  42. }
  43. }