From fefe28b8b34f77c7258aeec25d9a8ec4356084b1 Mon Sep 17 00:00:00 2001 From: ReiiYuki Date: Fri, 23 Jun 2017 17:16:47 +0900 Subject: [PATCH] Handle Disappear Event --- Assets/Example/Scripts/HandPositionHandler.cs | 20 ++++++++++ .../IRToolkit/Scripts/HandPositionManager.cs | 37 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Assets/Example/Scripts/HandPositionHandler.cs b/Assets/Example/Scripts/HandPositionHandler.cs index d53447b..7d84e55 100644 --- a/Assets/Example/Scripts/HandPositionHandler.cs +++ b/Assets/Example/Scripts/HandPositionHandler.cs @@ -21,4 +21,24 @@ void OnRightHandChange(Vector3 handPosition) rightCursor.transform.position = Camera.main.transform.position + new Vector3(handPosition.x * 100, handPosition.y * 100, handPosition.z * 100) + Camera.main.transform.forward; } + void OnLeftHandAppear() + { + leftCursor.SetActive(true); + } + + void OnLeftHandDisappear() + { + leftCursor.SetActive(false); + } + + void OnRightHandAppear() + { + rightCursor.SetActive(true); + } + + void OnRightHandDisappear() + { + rightCursor.SetActive(false); + } + } diff --git a/Assets/IRToolkit/Scripts/HandPositionManager.cs b/Assets/IRToolkit/Scripts/HandPositionManager.cs index 10edf0e..aeb7b47 100644 --- a/Assets/IRToolkit/Scripts/HandPositionManager.cs +++ b/Assets/IRToolkit/Scripts/HandPositionManager.cs @@ -5,7 +5,15 @@ using Intel.RealSense; public class HandPositionManager : Publisher { + + enum State + { + Appear, + Lost + } + HandManager handManager; + State leftHandState, rightHandState; // Update is called once per frame void Update () { @@ -19,17 +27,46 @@ void UpdateHandPosition() if (GetComponent().isStart) if (handManager.handData != null) { + State isLeftAppear = State.Lost; + State isRightAppear = State.Lost; for (int i = 0; i < handManager.handData.NumberOfHands; i++) { IHand hand; if (handManager.handData.QueryHandData(AccessOrderType.ACCESS_ORDER_BY_TIME,i,out hand) == Status.STATUS_NO_ERROR) { if (hand.BodySide == BodySideType.BODY_SIDE_LEFT) + { Boardcast("OnLeftHandChange", new Vector3(hand.MassCenterWorld.x, hand.MassCenterWorld.y, hand.MassCenterWorld.z)); + isLeftAppear = State.Appear; + } else if (hand.BodySide == BodySideType.BODY_SIDE_RIGHT) + { Boardcast("OnRightHandChange", new Vector3(hand.MassCenterWorld.x, hand.MassCenterWorld.y, hand.MassCenterWorld.z)); + isRightAppear = State.Appear; + } } } + CheckStateChange(isLeftAppear, isRightAppear); } } + + void CheckStateChange(State isLeftHandAppear,State isRightHandAppear) + { + if (leftHandState != isLeftHandAppear) + { + if (isLeftHandAppear == State.Appear) + Boardcast("OnLeftHandAppear"); + else + Boardcast("OnLeftHandDisappear"); + leftHandState = isLeftHandAppear; + } + if (rightHandState != isRightHandAppear) + { + if (isRightHandAppear == State.Appear) + Boardcast("OnRightHandAppear"); + else + Boardcast("OnRightHandDisappear"); + rightHandState = isLeftHandAppear; + } + } }