多媒体互动:用Unity开发体感接物
Posted qq_35974188
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多媒体互动:用Unity开发体感接物相关的知识,希望对你有一定的参考价值。
需求:挥手或者翻页笔下开启下一页 左右移动让小人左右移动接道具,用户在30s内吃道具,道具总共有7种类型,每种类型吃了后 点亮一个图片。
sdk:kinectv2
挥手核心逻辑 使用KinectGestures.Gestures.SwipeDown
public class PlayerGestureListener : Singleton<PlayerGestureListener>, KinectGestures.GestureListenerInterface
public bool IsSwipeDown()
if (swipeDown)
swipeDown = false;
return true;
return false;
public bool swipeDown = false;
private bool progressDisplayed;
private float progressGestureTime;
// Use this for initialization
void Start()
// Update is called once per frame
void Update()
if (progressDisplayed && ((Time.realtimeSinceStartup - progressGestureTime) > 0.05f))
progressDisplayed = false;
Debug.Log("Forced progress to end.");
public bool GestureCancelled(long userId, int userIndex, KinectGestures.Gestures gesture, KinectInterop.JointType joint)
if (progressDisplayed)
progressDisplayed = false;
return true;
public bool GestureCompleted(long userId, int userIndex, KinectGestures.Gestures gesture, KinectInterop.JointType joint, Vector3 screenPos)
if (gesture == KinectGestures.Gestures.SwipeDown)
swipeDown = true;
return true;
public void GestureInProgress(long userId, int userIndex, KinectGestures.Gestures gesture, float progress, KinectInterop.JointType joint, Vector3 screenPos)
if ((gesture == KinectGestures.Gestures.ZoomOut || gesture == KinectGestures.Gestures.ZoomIn) && progress > 0.5f)
progressDisplayed = true;
progressGestureTime = Time.realtimeSinceStartup;
else if ((gesture == KinectGestures.Gestures.Wheel || gesture == KinectGestures.Gestures.LeanLeft || gesture == KinectGestures.Gestures.LeanRight ||
gesture == KinectGestures.Gestures.LeanForward || gesture == KinectGestures.Gestures.LeanBack) && progress > 0.5f)
progressDisplayed = true;
progressGestureTime = Time.realtimeSinceStartup;
else if (gesture == KinectGestures.Gestures.Run && progress > 0.5f)
progressDisplayed = true;
progressGestureTime = Time.realtimeSinceStartup;
public void UserDetected(long userId, int userIndex)
KinectManager manager = KinectManager.Instance;
manager.DetectGesture(userId, KinectGestures.Gestures.SwipeDown);
public void UserLost(long userId, int userIndex)
Debug.Log("UserLost");
左右移动的核心逻辑:
void Update()
KinectManager manager = KinectManager.Instance;
if (manager && manager.IsInitialized() && foregroundCamera)
Rect backgroundRect = foregroundCamera.pixelRect;
PortraitBackground portraitBack = PortraitBackground.Instance;
if (portraitBack && portraitBack.enabled)
backgroundRect = portraitBack.GetBackgroundRect();
int joint = (int)KinectInterop.JointType.SpineMid;
// overlay all joints in the skeleton
if (manager.IsUserDetected())
long userId = manager.GetUserIdByIndex(playerIndex);
if (manager.IsJointTracked(userId, joint))
posJoint = manager.GetJointPosColorOverlay(userId, joint, foregroundCamera, backgroundRect);
//posJoint = manager.GetJointKinectPosition(userId, joint);
//posJoint = manager.GetJointPosition(userId, joint);
//Debug.Log("GetJointPosition:" + posJoint);
//Debug.Log("转换成屏幕坐标:" + Camera.main.WorldToScreenPoint(posJoint));
//Debug.Log("GetJointPosition:" + manager.GetJointPosition(userId, joint));
//Debug.Log("GetJointKinectPosition:" + manager.GetJointKinectPosition(userId, joint));
//Debug.Log("GetJointPosColorOverlay:" + manager.GetJointPosColorOverlay(userId, joint, foregroundCamera, backgroundRect));
//Debug.Log("GetJointPosDepthOverlay:" + manager.GetJointPosDepthOverlay(userId, joint, foregroundCamera, backgroundRect));
if (posJoint != Vector3.zero)
Vector3 screenPoint= Camera.main.WorldToScreenPoint(posJoint);
rectTran.anchoredPosition=new Vector2(screenPoint.x, -352F);
if(Input.GetKey(KeyCode.UpArrow))
float x=rectTran.anchoredPosition.x;
x -= 10;
x = Mathf.Clamp(x,44,700);
rectTran.anchoredPosition = new Vector2(x, rectTran.anchoredPosition.y);
if (Input.GetKey(KeyCode.DownArrow))
float x = rectTran.anchoredPosition.x;
x += 10;
x = Mathf.Clamp(x, 44, 700);
rectTran.anchoredPosition = new Vector2(x, rectTran.anchoredPosition.y);
U3D外包公司—北京动点(公司性质)承接U3DKinectVR虚拟现实,增强现实,体感互动,大屏互动等各类外包
unity3d外包就找动点软件承接虚拟现实项目外包
承接U3D、Kinect、VR虚拟现实,增强现实,体感互动,大屏互动等各类外包
联系请加QQ:372900288 联系电话:13911652504
我们制作各类型严肃游戏,虚拟现实,增强现实项目! 品质保证,售后完备。
我们团队成立于2011年10月,是一个专业从事严肃游戏研发的团队,主做:Unity3D外包、VR虚拟现实外包、AR增强现实外包
、3DSMAX、MAYA建模外包、大屏互动外包、体感互动外包。
我们能为您提供的服务
一、项目负责 客户提供给我们的资料及我们返还给客户的资料,产权都是客户的。我们建立项目组,确保我们能对每位员工为客户所制作
的项目进行持续的知识产权跟踪。我们的员工都会签署保密协议,以最大限度的维护客户的利益。
二、项目追溯 在合作过程中,我们与客户保持高度的沟通和反馈。我们会有专人负责向客户实时提供最新的进度信息,客户亦可以随时看
到作品进度。对项目中可能出现的问题将即使处理内部总结经验,并迅速应用到后面的制作中去。在项目完成前,我们会逐
级进行检查,以确保符合客户的质量要求。
以上是关于多媒体互动:用Unity开发体感接物的主要内容,如果未能解决你的问题,请参考以下文章
U3D外包公司—北京动点(公司性质)承接U3DKinectVR虚拟现实,增强现实,体感互动,大屏互动等各类外包
小松教你手游开发unity实用技能unity ios快捷打包