kinectv1手势识别记录

using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;

public class GestureScript : MonoBehaviour, KinectGestures.GestureListenerInterface
{
    // GUI Text to display the gesture messages.
    public Text GestureInfo;

    private bool Click;
    // private bool swipeRight;
    public GameObject MouseT;
    public Image cc;
    private ImitateMouseClick  imitateMouseClick;

    public void Start()
    {
        imitateMouseClick = GetComponent<ImitateMouseClick>();
    }
    public void Update()
    {
        KinectManager kinectManager = KinectManager.Instance;
        if (!kinectManager || !kinectManager.IsInitialized() || !kinectManager.IsUserDetected())
        {
           // Debug.Log("******");
            return;
        }
       // Debug.Log("※※※※※※※※※※※※※1");
        if (IsClick())
        {
            Debug.Log("※※※※※※点击※※※※※※※");

            Go();


        }
    }   
    /// <summary>
    /// 调用点击鼠标方法
    /// </summary>
    public  void Go()
    {
        //cursorPos = Vector2.Lerp(cursorPos, new Vector2(xScaled, 1f - yScaled), smoothFactor * Time.deltaTime);
        //image.rectTransform.position
        //    = new Vector3(cursorPos.x * Screen.width, cursorPos.y * Screen.height);

        //ImitateMouseClick.MoveTo(MouseT.transform.position.x, MouseT.transform.position.y);
        //Debug.Log("鼠标位移");

        //Vector3 screenPos1 = Camera.main.WorldToScreenPoint(MouseT.transform.position);   //世界转屏幕
        //imitateMouseClick.LeftClick(screenPos1.x, screenPos1.y);
        imitateMouseClick.LeftClick(cc.rectTransform.position.x,(cc.rectTransform.position.y) );
        Debug.Log("鼠标点击");

    }



    public bool IsClick()
    {
        if (Click)
        {
            Click = false;
            return true;
        }

        return false;
    }


    public void UserDetected(uint userId, int userIndex)
    {
        // detect these user specific gestures
        KinectManager manager = KinectManager.Instance;

        manager.DetectGesture(userId, KinectGestures.Gestures.Click);
       // manager.DetectGesture(userId, KinectGestures.Gestures.SwipeRight);

        if (GestureInfo != null)
        {
            GestureInfo.GetComponent<Text>().text = "Swipe left or right to change the slides.";
        }
    }

    public void UserLost(uint userId, int userIndex)
    {
        if (GestureInfo != null)
        {
            GestureInfo.GetComponent<Text>().text = string.Empty;
        }
    }

    public void GestureInProgress(uint userId, int userIndex, KinectGestures.Gestures gesture,
                                  float progress, KinectWrapper.NuiSkeletonPositionIndex joint, Vector3 screenPos)
    {
        // don't do anything here
    }

    public bool GestureCompleted(uint userId, int userIndex, KinectGestures.Gestures gesture,
                                  KinectWrapper.NuiSkeletonPositionIndex joint, Vector3 screenPos)
    {
        string sGestureText = gesture + " detected";
        if (GestureInfo != null)
        {
            GestureInfo.GetComponent<Text>().text = sGestureText;
        }

        if (gesture == KinectGestures.Gestures.Click)//检测点击
        {      Debug.Log("检测到点击");
            Click = true;
          
        }
            
       

        return true;
    }

    public bool GestureCancelled(uint userId, int userIndex, KinectGestures.Gestures gesture,
                                  KinectWrapper.NuiSkeletonPositionIndex joint)
    {
        // don't do anything here, just reset the gesture state
        return true;
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值