您的位置:首页 > 产品设计 > UI/UE

Kinect V2 多关节捕捉应用中break 与 continue的妙用

2016-08-10 14:30 971 查看
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UseKinectPosTwoPeople : MonoBehaviour {

public bool[] bools = new bool[32];
public Text numTxt;

public Image[] images = new Image[32];
private int[] jointTypes = new int[25];

// Use this for initialization
void Start () {
for(int i = 0; i < 32; i++)
{
bools[i] = false;
}

//特征点
for (int i = 0; i < 25; i++)
{
jointTypes[i] = i;
}

}

// Update is called once per frame
void Update () {
bool isInit = KinectManager.Instance.IsInitialized();  //检测设备可用
if (isInit)
{
if (KinectManager.Instance.IsUserDetected())
{
//检测到玩家
long userId = KinectManager.Instance.GetPrimaryUserID();  //获取用户id
long userId2 = 0;
//KinectManager.Instance.GetAllUserIds();
int count = KinectManager.Instance.GetUsersCount();
numTxt.text = "usersCount = " + count;
if (count == 2)
{
userId = KinectManager.Instance.GetUserIdByIndex(0);
userId2 = KinectManager.Instance.GetUserIdByIndex(1);
}

for (int i = 0; i < 32; i++)
{
Image img = GameObject.Find("startAniImg" + (i + 1)).GetComponent<Image>();

bool isFind = false;  //找到

//上半身
for(int j=0; j<11; j++)
{
if (KinectManager.Instance.IsJointTracked(userId, jointTypes[j]))
{
Vector3 pos = KinectManager.Instance.GetJointKinectPosition(userId, jointTypes[j]);  //1.获取关节点3D坐标
Vector3 screenPos = Camera.main.WorldToScreenPoint(pos);  //2.关节点坐标转换成屏幕坐标
if (RectTransformUtility.RectangleContainsScreenPoint(img.rectTransform, screenPos, null))
{
GameObject.Find("startAniImg" + (i + 1)).GetComponent<StartAnimationClass>().isPlay = true;
bools[i] = true;
isFind = true;
break;
}
}

if (count == 2)
{
if (KinectManager.Instance.IsJointTracked(userId2, jointTypes[j]))
{
Vector3 pos2 = KinectManager.Instance.GetJointKinectPosition(userId2, jointTypes[j]);  //1.获取关节点3D坐标
Vector3 screenPos2 = Camera.main.WorldToScreenPoint(pos2);  //2.关节点坐标转换成屏幕坐标
if (RectTransformUtility.RectangleContainsScreenPoint(img.rectTransform, screenPos2, null))
{
GameObject.Find("startAniImg" + (i + 1)).GetComponent<StartAnimationClass>().isPlay = true;
bools[i] = true;
isFind = true;
break;
}
}
}
}
if (isFind)
{
continue;
}

if (bools[i])
{
GameObject.Find("startAniImg" + (i + 1)).GetComponent<StartAnimationClass>().isPlay = false;
GameObject.Find("startAniImg" + (i + 1)).GetComponent<StartAnimationClass>().isClose = true;
bools[i] = false;
}

}

}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息