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;
}
}