1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections;
- using UnityEngine;
- namespace Leap.Unity
- {
- public class HandDrop : HandTransitionBehavior
- {
- protected override void Awake()
- {
- base.Awake();
- this.palm = base.GetComponent<HandModel>().palm;
- this.startingPalmPosition = this.palm.localPosition;
- this.startingOrientation = this.palm.localRotation;
- }
- protected override void HandFinish()
- {
- base.StartCoroutine(this.LerpToStart());
- }
- protected override void HandReset()
- {
- base.StopAllCoroutines();
- }
- private IEnumerator LerpToStart()
- {
- Vector3 droppedPosition = this.palm.localPosition;
- Quaternion droppedOrientation = this.palm.localRotation;
- float duration = 0.25f;
- float startTime = Time.time;
- float endTime = startTime + duration;
- while (Time.time <= endTime)
- {
- float t = (Time.time - startTime) / duration;
- this.palm.localPosition = Vector3.Lerp(droppedPosition, this.startingPalmPosition, t);
- this.palm.localRotation = Quaternion.Lerp(droppedOrientation, this.startingOrientation, t);
- yield return null;
- }
- yield break;
- }
- private Vector3 startingPalmPosition;
- private Quaternion startingOrientation;
- private Transform palm;
- }
- }
|