修改
This commit is contained in:
153
Assets/07.RKTools/RunTime/GestureRecognition/GestureRokidBase.cs
Normal file
153
Assets/07.RKTools/RunTime/GestureRecognition/GestureRokidBase.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
#if Evo_Rokid
|
||||
public abstract class GestureRokidBase : MonoBehaviour
|
||||
{
|
||||
private Rokid.UXR.Interaction.GestureBean leftBean = null;
|
||||
private Rokid.UXR.Interaction.GestureBean rightBean = null;
|
||||
protected void OnEnable()
|
||||
{
|
||||
Rokid.UXR.Interaction.GesEventInput.OnTrackedSuccess += OnTrackedSuccess;
|
||||
Rokid.UXR.Interaction.GesEventInput.OnTrackedFailed += OnTrackedFailed;
|
||||
Rokid.UXR.Interaction.GesEventInput.OnRenderHand += OnRenderHand;
|
||||
}
|
||||
|
||||
protected void OnDisable()
|
||||
{
|
||||
Rokid.UXR.Interaction.GesEventInput.OnTrackedSuccess -= OnTrackedSuccess;
|
||||
Rokid.UXR.Interaction.GesEventInput.OnTrackedFailed -= OnTrackedFailed;
|
||||
Rokid.UXR.Interaction.GesEventInput.OnRenderHand -= OnRenderHand;
|
||||
}
|
||||
|
||||
protected void FixedUpdate()
|
||||
{
|
||||
if (leftBean != null)
|
||||
{
|
||||
Rokid.UXR.Interaction.GestureType type =
|
||||
Rokid.UXR.Interaction.GesEventInput.Instance.GetGestureType(Rokid.UXR.Interaction.HandType.LeftHand);
|
||||
Vector3 handForward =
|
||||
GetSkeletonPose(Rokid.UXR.Interaction.SkeletonIndexFlag.PALM, Rokid.UXR.Interaction.HandType.LeftHand).forward;
|
||||
GestureLeftSuccess(type, handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureLeftFail();
|
||||
}
|
||||
|
||||
if (rightBean != null)
|
||||
{
|
||||
Rokid.UXR.Interaction.GestureType type =
|
||||
Rokid.UXR.Interaction.GesEventInput.Instance.GetGestureType(Rokid.UXR.Interaction.HandType.RightHand);
|
||||
Vector3 handForward =
|
||||
GetSkeletonPose(Rokid.UXR.Interaction.SkeletonIndexFlag.PALM, Rokid.UXR.Interaction.HandType.RightHand).forward;
|
||||
GestureRightSuccess(type, handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureRightFail();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrackedSuccess(Rokid.UXR.Interaction.HandType handType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTrackedFailed(Rokid.UXR.Interaction.HandType handType)
|
||||
{
|
||||
if (handType == Rokid.UXR.Interaction.HandType.None)
|
||||
{
|
||||
leftBean = null;
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == Rokid.UXR.Interaction.HandType.RightHand)
|
||||
{
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == Rokid.UXR.Interaction.HandType.LeftHand)
|
||||
{
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRenderHand(Rokid.UXR.Interaction.HandType handType, Rokid.UXR.Interaction.GestureBean gestureBean)
|
||||
{
|
||||
if (handType == Rokid.UXR.Interaction.HandType.RightHand)
|
||||
{
|
||||
rightBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == Rokid.UXR.Interaction.HandType.LeftHand)
|
||||
{
|
||||
leftBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == Rokid.UXR.Interaction.HandType.None)
|
||||
{
|
||||
rightBean = null;
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取骨架点位置
|
||||
/// </summary>
|
||||
/// <param name="index">骨架序号</param>
|
||||
/// <param name="hand">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Pose GetSkeletonPose(Rokid.UXR.Interaction.SkeletonIndexFlag index, Rokid.UXR.Interaction.HandType hand)
|
||||
{
|
||||
return Rokid.UXR.Interaction.GesEventInput.Instance.GetSkeletonPose(index, hand);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取手地朝向
|
||||
/// </summary>
|
||||
/// <param name="handType">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 GetHandForward(Rokid.UXR.Interaction.HandType handType)
|
||||
{
|
||||
Vector3 handForward =
|
||||
(GetSkeletonPose(Rokid.UXR.Interaction.SkeletonIndexFlag.MIDDLE_FINGER_MCP, handType).position -
|
||||
GetSkeletonPose(Rokid.UXR.Interaction.SkeletonIndexFlag.WRIST, handType).position);
|
||||
return handForward;
|
||||
}
|
||||
|
||||
|
||||
#region 需要被重写的方法
|
||||
|
||||
/// <summary>
|
||||
/// 左手成功识别到手势不断执行操作
|
||||
/// </summary>
|
||||
/// <param name="gestureType">左手手势类型</param>
|
||||
/// <param name="handForward">左手掌心朝向</param>
|
||||
public abstract void GestureLeftSuccess(Rokid.UXR.Interaction.GestureType gestureType, Vector3 handForward);
|
||||
|
||||
/// <summary>
|
||||
/// 右手成功识别到手势不断执行操作
|
||||
/// </summary>
|
||||
/// <param name="gestureType">右手手势类型</param>
|
||||
/// <param name="handForward">右手掌心朝向</param>
|
||||
public abstract void GestureRightSuccess(Rokid.UXR.Interaction.GestureType gestureType, Vector3 handForward);
|
||||
|
||||
/// <summary>
|
||||
/// 左手未识别到手势执行操作
|
||||
/// </summary>
|
||||
public abstract void GestureLeftFail();
|
||||
|
||||
/// <summary>
|
||||
/// 右手未识别到手势执行操作
|
||||
/// </summary>
|
||||
public abstract void GestureRightFail();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user