Unity用kinect的手势触发UI区域进行选择操作

来源:互联网 发布:s7300模拟量编程 编辑:程序博客网 时间:2024/06/07 01:56

我是unity加kinect的菜鸟,所以在此记录自己的菜鸟经验。

在unity下使用kinect,根据左右手的三维坐标,将其映射到UI上,并在UI上设置矩形区域。


RectTransform rectTransformImageUp;Vector3 upScreenPos ;Rect upRect;void Start () {rectTransformImageUp = GameObject.Find("Canvas").GetComponent().transform.Find ("rectUp").gameObject.GetComponent ();upScreenPos = rectTransformImageUp.position;upRect = rectTransformImageUp.rect;}void Update () {Vector3 leftScreenPos = InteractionHandManager.Instance.GetLeftHandScreenPos ();Vector3 rightScreenPos = InteractionHandManager.Instance.GetRightHandScreenPos ();if (leftScreenPos.x <= upScreenPos.x + upRect.width / 2 && leftScreenPos.x >= upScreenPos.x - upRect.width / 2&& leftScreenPos.y <= upScreenPos.y + upRect.height / 2 && leftScreenPos.y >= upScreenPos.y - upRect.height / 2) {isStartUp = true;}else if (rightScreenPos.x <= upScreenPos.x + upRect.width / 2 && rightScreenPos.x >= upScreenPos.x - upRect.width / 2&& rightScreenPos.y <= upScreenPos.y + upRect.height / 2 && rightScreenPos.y >= upScreenPos.y - upRect.height / 2) {isStartUp = true;}elseisStartUp = false;

原创粉丝点击