Kinect for Unity V2 代码示例(一)
2016-04-19 09:08
489 查看
using UnityEngine; using System.Collections; using UnityEngine.UI; public class UseKinectManager : MonoBehaviour { public RawImage kinectImg; // Use this for initialization void Start () { } // Update is called once per frame void Update () { bool isInit = KinectManager.Instance.IsInitialized(); //检测设备可用 if (isInit) { //设备准备好了 可以读取了 if(kinectImg.texture == null) { Texture2D kinectPic = KinectManager.Instance.GetUsersClrTex(); //从设备获取彩色数据 // Texture2D kinectPic = KinectManager.Instance.GetUsersLblTex(); //获取深度数据量 kinectImg.texture = kinectPic; //把彩色数据给控件显示 } if (KinectManager.Instance.IsUserDetected()) { //检测到玩家 long userId = KinectManager.Instance.GetPrimaryUserID(); //获取用户id Vector3 userPos = KinectManager.Instance.GetUserPosition(userId); //获取用户离Kinect的距离信息 //print("x = " + userPos.x + " y = " + userPos.y + " z = " + userPos.z); int jointType = (int)KinectInterop.JointType.HandLeft; if (KinectManager.Instance.IsJointTracked(userId,jointType)) { //关节点被追踪到 Vector3 leftHandPos = KinectManager.Instance.GetJointKinectPosition(userId, jointType); //Vector3 leftHandPos = KinectManager.Instance.GetJointPosition(userId, jointType); //y轴输出不一样 // print("x = " + leftHandPos.x + " y = " + leftHandPos.y + " z = " + leftHandPos.z); KinectInterop.HandState leftHandState = KinectManager.Instance.GetLeftHandState(userId); //获取左手姿势 if (leftHandState == KinectInterop.HandState.Closed) { print("左手握拳"); }else if (leftHandState == KinectInterop.HandState.Open) { print("左手张开"); }else if (leftHandState == KinectInterop.HandState.Lasso) { print("yes手势"); } } } } } }
相关文章推荐
- 一个通用的有限状态机(FSM)框架
- 2.《Unity中C#脚本语法-常用变量类型》
- 1.《介绍Unity中C#脚本语言》
- Unity3D Terrain 变成粉色(紫色/洋红色)解决方案!
- unity中利用mesh动态创建墙体
- Unity Chan Advanced
- Unity Coroutine协程
- unity性能分析
- Unity3d SendMessage 简单用法笔记
- Unity3d 查找所选的是否引用过某资源
- 记一次基于Unity的Profiler性能分析
- 微软unity 注入mvc
- Unity 动画模板代码注解
- Unity3D_NGUI_性能优化实践_CPU卡顿
- Unity3d 用NGUI制作做新手引导的思路
- 浅析:Unity3D开发的游戏如何降低包体大小
- 浅析:Unity3D开发的游戏如何降低包体大小
- 关于unity5.x破解不了的问题
- 在Unity 5中如何减少Draw Call
- Unity开发Leapmotion