Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit fefe28b

Browse files
committed
Handle Disappear Event
1 parent 3022cd5 commit fefe28b

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

Assets/Example/Scripts/HandPositionHandler.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,24 @@ void OnRightHandChange(Vector3 handPosition)
2121
rightCursor.transform.position = Camera.main.transform.position + new Vector3(handPosition.x * 100, handPosition.y * 100, handPosition.z * 100) + Camera.main.transform.forward;
2222
}
2323

24+
void OnLeftHandAppear()
25+
{
26+
leftCursor.SetActive(true);
27+
}
28+
29+
void OnLeftHandDisappear()
30+
{
31+
leftCursor.SetActive(false);
32+
}
33+
34+
void OnRightHandAppear()
35+
{
36+
rightCursor.SetActive(true);
37+
}
38+
39+
void OnRightHandDisappear()
40+
{
41+
rightCursor.SetActive(false);
42+
}
43+
2444
}

Assets/IRToolkit/Scripts/HandPositionManager.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
using Intel.RealSense;
66

77
public class HandPositionManager : Publisher {
8+
9+
enum State
10+
{
11+
Appear,
12+
Lost
13+
}
14+
815
HandManager handManager;
16+
State leftHandState, rightHandState;
917

1018
// Update is called once per frame
1119
void Update () {
@@ -19,17 +27,46 @@ void UpdateHandPosition()
1927
if (GetComponent<DepthCameraManger>().isStart)
2028
if (handManager.handData != null)
2129
{
30+
State isLeftAppear = State.Lost;
31+
State isRightAppear = State.Lost;
2232
for (int i = 0; i < handManager.handData.NumberOfHands; i++)
2333
{
2434
IHand hand;
2535
if (handManager.handData.QueryHandData(AccessOrderType.ACCESS_ORDER_BY_TIME,i,out hand) == Status.STATUS_NO_ERROR)
2636
{
2737
if (hand.BodySide == BodySideType.BODY_SIDE_LEFT)
38+
{
2839
Boardcast("OnLeftHandChange", new Vector3(hand.MassCenterWorld.x, hand.MassCenterWorld.y, hand.MassCenterWorld.z));
40+
isLeftAppear = State.Appear;
41+
}
2942
else if (hand.BodySide == BodySideType.BODY_SIDE_RIGHT)
43+
{
3044
Boardcast("OnRightHandChange", new Vector3(hand.MassCenterWorld.x, hand.MassCenterWorld.y, hand.MassCenterWorld.z));
45+
isRightAppear = State.Appear;
46+
}
3147
}
3248
}
49+
CheckStateChange(isLeftAppear, isRightAppear);
3350
}
3451
}
52+
53+
void CheckStateChange(State isLeftHandAppear,State isRightHandAppear)
54+
{
55+
if (leftHandState != isLeftHandAppear)
56+
{
57+
if (isLeftHandAppear == State.Appear)
58+
Boardcast("OnLeftHandAppear");
59+
else
60+
Boardcast("OnLeftHandDisappear");
61+
leftHandState = isLeftHandAppear;
62+
}
63+
if (rightHandState != isRightHandAppear)
64+
{
65+
if (isRightHandAppear == State.Appear)
66+
Boardcast("OnRightHandAppear");
67+
else
68+
Boardcast("OnRightHandDisappear");
69+
rightHandState = isLeftHandAppear;
70+
}
71+
}
3572
}

0 commit comments

Comments
 (0)