Tanoda
LeapTestProvider.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.Collections;
10using System.Collections.Generic;
11using UnityEngine;
12
13namespace Leap.Unity {
14
16
17 public Frame frame;
18 public override Frame CurrentFrame {
19 get {
20 #if UNITY_EDITOR
21 if (!Application.isPlaying) {
22 frame = TestHandFactory.MakeTestFrame(frameId: 0,
23 includeLeftHand: true, includeRightHand: true,
24 handPose: editTimePose,
25 unitType: TestHandFactory.UnitType.UnityUnits);
26 }
27 #endif
28 return frame;
29 }
30 }
31 public override Frame CurrentFixedFrame {
32 get {
33 #if UNITY_EDITOR
34 if (!Application.isPlaying) {
35 frame = TestHandFactory.MakeTestFrame(frameId: 0,
36 includeLeftHand: true, includeRightHand: true,
37 handPose: editTimePose,
38 unitType: TestHandFactory.UnitType.UnityUnits);
39 }
40 #endif
41 return frame;
42 }
43 }
44
45 [Header("Runtime Basis Transforms")]
46
47 [Tooltip("At runtime, if this Transform is non-null, the LeapTestProvider will "
48 + "create a test-pose left hand at this transform's position and rotation."
49 + "Setting this binding to null at runtime will cause the hand to disappear "
50 + "from Frame data, as if it stopped tracking.")]
51 public Transform leftHandBasis;
52 private Hand _leftHand = null;
53 private Hand _cachedLeftHand = null;
54
55 [Tooltip("At runtime, if this Transform is non-null, the LeapTestProvider will "
56 + "create a test-pose right hand at this transform's position and rotation."
57 + "Setting this binding to null at runtime will cause the hand to disappear "
58 + "from Frame data, as if it stopped tracking.")]
59 public Transform rightHandBasis;
60 private Hand _rightHand = null;
61 private Hand _cachedRightHand = null;
62
63 void Awake() {
64 _cachedLeftHand = TestHandFactory.MakeTestHand(isLeft: true,
65 unitType: TestHandFactory.UnitType.UnityUnits);
66 _cachedLeftHand.Id = 0;
67 _cachedRightHand = TestHandFactory.MakeTestHand(isLeft: false,
68 unitType: TestHandFactory.UnitType.UnityUnits);
69 _cachedRightHand.Id = 1;
70 }
71
72 void Update() {
73 if (_leftHand == null && leftHandBasis != null) {
74 _leftHand = _cachedLeftHand;
75 frame.Hands.Add(_leftHand);
76 }
77 if (_leftHand != null && leftHandBasis == null) {
78 frame.Hands.Remove(_leftHand);
79 _leftHand = null;
80 }
81 if (_leftHand != null) {
82 _leftHand.SetTransform(leftHandBasis.position, leftHandBasis.rotation);
83 }
84
85 if (_rightHand == null && rightHandBasis != null) {
86 _rightHand = _cachedRightHand;
87 frame.Hands.Add(_rightHand);
88 }
89 if (_rightHand != null && rightHandBasis == null) {
90 frame.Hands.Remove(_rightHand);
91 _rightHand = null;
92 }
93 if (_rightHand != null) {
94 _rightHand.SetTransform(rightHandBasis.position, rightHandBasis.rotation);
95 }
96
98 }
99
100 void FixedUpdate() {
102 }
103
104 }
105
106}
The Frame class represents a set of hand and finger tracking data detected in a single frame.
Definition: Frame.cs:24
List< Hand > Hands
The list of Hand objects detected in this frame, given in arbitrary order. The list can be empty if n...
Definition: Frame.cs:156
The Hand class reports the physical characteristics of a detected hand.
Definition: Hand.cs:26
int Id
A unique ID assigned to this Hand object, whose value remains the same across consecutive frames whil...
Definition: Hand.cs:152
Provides Frame object data to the Unity application by firing events as soon as Frame data is availab...
Definition: LeapProvider.cs:21
void DispatchUpdateFrameEvent(Frame frame)
Definition: LeapProvider.cs:49
TestHandPose editTimePose
Definition: LeapProvider.cs:23
void DispatchFixedFrameEvent(Frame frame)
Definition: LeapProvider.cs:58