【m】添加图像识别
This commit is contained in:
@@ -4,151 +4,158 @@ using Rokid.UXR.Interaction;
|
||||
using Stary.Evo;
|
||||
using UnityEngine;
|
||||
|
||||
public static class RKAddInteractionExtension
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
#region 触摸
|
||||
/// <summary>
|
||||
/// 添加触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
/// <param name="TouchEvent">触碰后事件</param>
|
||||
public static void ObjectAddTouchEvent(this GameObject Touchedobject, System.Action<GameObject> TouchEvent, float TouchScale = 1.2f)
|
||||
public static class RKAddInteractionExtension
|
||||
{
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
|
||||
#region 触摸
|
||||
|
||||
// 原有的组件设置优先级最高
|
||||
if (ObjectCollider == null)
|
||||
/// <summary>
|
||||
/// 添加触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
/// <param name="TouchEvent">触碰后事件</param>
|
||||
public static void ObjectAddTouchEvent(this GameObject Touchedobject, System.Action<GameObject> TouchEvent,
|
||||
float TouchScale = 1.2f)
|
||||
{
|
||||
ObjectCollider = Touchedobject.AddComponent<BoxCollider>();
|
||||
ObjectCollider.isTrigger = true;
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
|
||||
|
||||
// 原有的组件设置优先级最高
|
||||
if (ObjectCollider == null)
|
||||
{
|
||||
ObjectCollider = Touchedobject.AddComponent<BoxCollider>();
|
||||
ObjectCollider.isTrigger = true;
|
||||
}
|
||||
|
||||
if (GrabInteractable == null)
|
||||
{
|
||||
GrabInteractable = Touchedobject.AddComponent<GrabInteractable>();
|
||||
GrabInteractable.rate = TouchScale;
|
||||
}
|
||||
|
||||
GrabInteractable.OnHoverBegin.AddListener(() => TouchEvent?.Invoke(Touchedobject));
|
||||
}
|
||||
|
||||
if (GrabInteractable == null)
|
||||
/// <summary>
|
||||
/// 暂停触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
public static void ObjectPauseTouchEvent(this GameObject Touchedobject)
|
||||
{
|
||||
GrabInteractable = Touchedobject.AddComponent<GrabInteractable>();
|
||||
GrabInteractable.rate = TouchScale;
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null)
|
||||
{
|
||||
ObjectCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
GrabInteractable.OnHoverBegin.AddListener(()=>TouchEvent?.Invoke(Touchedobject));
|
||||
/// <summary>
|
||||
/// 恢复触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
public static void ObjectResumeTouchEvent(this GameObject Touchedobject)
|
||||
{
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null)
|
||||
{
|
||||
ObjectCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
|
||||
public static void ObjectRemoveTouchEvent(this GameObject Touchedobject)
|
||||
{
|
||||
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
|
||||
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHoverBegin.RemoveAllListeners();
|
||||
Object.Destroy(GrabInteractable);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 拖动
|
||||
|
||||
/// <summary>
|
||||
/// 添加拖动事件
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject">被拖动物体</param>
|
||||
/// <param name="DragingEvent">拖动时执行的方法</param>
|
||||
public static void objectAddDrag(this GameObject Dragedobject, System.Action<GameObject> DragingEvent = null,
|
||||
float DragScale = 1.2f)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
GrabInteractable GrabInteractable = Dragedobject.GetComponent<GrabInteractable>();
|
||||
Rigidbody Rigidbody = Dragedobject.GetComponent<Rigidbody>();
|
||||
Throwable Throwable = Dragedobject.GetComponent<Throwable>();
|
||||
|
||||
// 原有的组件设置优先级最高
|
||||
if (ObjectCollider == null)
|
||||
{
|
||||
ObjectCollider = Dragedobject.AddComponent<BoxCollider>();
|
||||
ObjectCollider.isTrigger = true;
|
||||
}
|
||||
|
||||
if (GrabInteractable == null)
|
||||
{
|
||||
GrabInteractable = Dragedobject.AddComponent<GrabInteractable>();
|
||||
GrabInteractable.rate = DragScale;
|
||||
}
|
||||
|
||||
if (Rigidbody == null)
|
||||
{
|
||||
Rigidbody = Dragedobject.AddComponent<Rigidbody>();
|
||||
Rigidbody.useGravity = false;
|
||||
}
|
||||
|
||||
if (Throwable == null)
|
||||
{
|
||||
Throwable = Dragedobject.AddComponent<Throwable>();
|
||||
}
|
||||
|
||||
GrabInteractable.OnHeldUpdate.AddListener(() => DragingEvent?.Invoke(Dragedobject));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停拖动
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject"></param>
|
||||
public static void objectPauseDrag(this GameObject Dragedobject)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null) ObjectCollider.enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复拖动
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject"></param>
|
||||
public static void objectResumeDrag(this GameObject Dragedobject)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null) ObjectCollider.enabled = true;
|
||||
}
|
||||
|
||||
public static void objectRemoveDrag(this GameObject Dragedobject)
|
||||
{
|
||||
Throwable Throwable = Dragedobject.GetComponent<Throwable>();
|
||||
GrabInteractable GrabInteractable = Dragedobject.GetComponent<GrabInteractable>();
|
||||
if (Throwable != null) Object.Destroy(Throwable);
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHeldUpdate.RemoveAllListeners();
|
||||
Object.Destroy(GrabInteractable);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
public static void ObjectPauseTouchEvent(this GameObject Touchedobject)
|
||||
{
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null)
|
||||
{
|
||||
ObjectCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
public static void ObjectResumeTouchEvent(this GameObject Touchedobject)
|
||||
{
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null)
|
||||
{
|
||||
ObjectCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
|
||||
public static void ObjectRemoveTouchEvent(this GameObject Touchedobject)
|
||||
{
|
||||
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
|
||||
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHoverBegin.RemoveAllListeners();
|
||||
Object.Destroy(GrabInteractable);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 拖动
|
||||
|
||||
/// <summary>
|
||||
/// 添加拖动事件
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject">被拖动物体</param>
|
||||
/// <param name="DragingEvent">拖动时执行的方法</param>
|
||||
public static void objectAddDrag(this GameObject Dragedobject, System.Action<GameObject> DragingEvent = null, float DragScale = 1.2f)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
GrabInteractable GrabInteractable = Dragedobject.GetComponent<GrabInteractable>();
|
||||
Rigidbody Rigidbody = Dragedobject.GetComponent<Rigidbody>();
|
||||
Throwable Throwable = Dragedobject.GetComponent<Throwable>();
|
||||
|
||||
// 原有的组件设置优先级最高
|
||||
if (ObjectCollider == null)
|
||||
{
|
||||
ObjectCollider = Dragedobject.AddComponent<BoxCollider>();
|
||||
ObjectCollider.isTrigger = true;
|
||||
}
|
||||
|
||||
if (GrabInteractable == null)
|
||||
{
|
||||
GrabInteractable = Dragedobject.AddComponent<GrabInteractable>();
|
||||
GrabInteractable.rate = DragScale;
|
||||
}
|
||||
|
||||
if (Rigidbody == null)
|
||||
{
|
||||
Rigidbody = Dragedobject.AddComponent<Rigidbody>();
|
||||
Rigidbody.useGravity = false;
|
||||
}
|
||||
|
||||
if (Throwable == null)
|
||||
{
|
||||
Throwable = Dragedobject.AddComponent<Throwable>();
|
||||
}
|
||||
|
||||
GrabInteractable.OnHeldUpdate.AddListener(()=>DragingEvent?.Invoke(Dragedobject));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停拖动
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject"></param>
|
||||
public static void objectPauseDrag(this GameObject Dragedobject)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider!= null) ObjectCollider.enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复拖动
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject"></param>
|
||||
public static void objectResumeDrag(this GameObject Dragedobject)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider!= null) ObjectCollider.enabled = true;
|
||||
}
|
||||
|
||||
public static void objectRemoveDrag(this GameObject Dragedobject)
|
||||
{
|
||||
Throwable Throwable = Dragedobject.GetComponent<Throwable>();
|
||||
GrabInteractable GrabInteractable = Dragedobject.GetComponent<GrabInteractable>();
|
||||
if (Throwable != null) Object.Destroy(Throwable);
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHeldUpdate.RemoveAllListeners();
|
||||
Object.Destroy(GrabInteractable);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -3,126 +3,129 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Rokid.UXR.Interaction;
|
||||
|
||||
public abstract class GestureBase : MonoBehaviour
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
private GestureBean leftBean = null;
|
||||
private GestureBean rightBean = null;
|
||||
|
||||
protected void OnEnable()
|
||||
public abstract class GestureBase : MonoBehaviour
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess += OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed += OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand += OnRenderHand;
|
||||
}
|
||||
private GestureBean leftBean = null;
|
||||
private GestureBean rightBean = null;
|
||||
|
||||
protected void OnDisable()
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess -= OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed -= OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand -= OnRenderHand;
|
||||
}
|
||||
|
||||
protected void FixedUpdate()
|
||||
{
|
||||
if (leftBean!=null)
|
||||
protected void OnEnable()
|
||||
{
|
||||
GestureType type= GesEventInput.Instance.GetGestureType(HandType.LeftHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.LeftHand).forward;
|
||||
GestureLeftSuccess(type,handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureLeftFail();
|
||||
GesEventInput.OnTrackedSuccess += OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed += OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand += OnRenderHand;
|
||||
}
|
||||
|
||||
if (rightBean != null)
|
||||
protected void OnDisable()
|
||||
{
|
||||
GestureType type= GesEventInput.Instance.GetGestureType(HandType.RightHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.RightHand).forward;
|
||||
GestureRightSuccess(type,handForward);
|
||||
GesEventInput.OnTrackedSuccess -= OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed -= OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand -= OnRenderHand;
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureRightFail();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrackedSuccess(HandType handType)
|
||||
{
|
||||
protected void FixedUpdate()
|
||||
{
|
||||
if (leftBean != null)
|
||||
{
|
||||
GestureType type = GesEventInput.Instance.GetGestureType(HandType.LeftHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.LeftHand).forward;
|
||||
GestureLeftSuccess(type, handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureLeftFail();
|
||||
}
|
||||
|
||||
if (rightBean != null)
|
||||
{
|
||||
GestureType type = GesEventInput.Instance.GetGestureType(HandType.RightHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.RightHand).forward;
|
||||
GestureRightSuccess(type, handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureRightFail();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrackedSuccess(HandType handType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTrackedFailed(HandType handType)
|
||||
{
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
leftBean = null;
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRenderHand(HandType handType, GestureBean gestureBean)
|
||||
{
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
rightBean = null;
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取骨架点位置
|
||||
/// </summary>
|
||||
/// <param name="index">骨架序号</param>
|
||||
/// <param name="hand">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Pose GetSkeletonPose(SkeletonIndexFlag index, HandType hand)
|
||||
{
|
||||
return GesEventInput.Instance.GetSkeletonPose(index, hand);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取手地朝向
|
||||
/// </summary>
|
||||
/// <param name="handType">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 GetHandForward(HandType handType)
|
||||
{
|
||||
Vector3 handForward = (GetSkeletonPose(SkeletonIndexFlag.MIDDLE_FINGER_MCP, handType).position -
|
||||
GetSkeletonPose(SkeletonIndexFlag.WRIST, handType).position);
|
||||
return handForward;
|
||||
}
|
||||
|
||||
|
||||
#region 需要被重写的方法
|
||||
|
||||
public abstract void GestureLeftSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureRightSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureLeftFail();
|
||||
public abstract void GestureRightFail();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
private void OnTrackedFailed(HandType handType)
|
||||
{
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
leftBean = null;
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRenderHand(HandType handType, GestureBean gestureBean)
|
||||
{
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
rightBean = null;
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取骨架点位置
|
||||
/// </summary>
|
||||
/// <param name="index">骨架序号</param>
|
||||
/// <param name="hand">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Pose GetSkeletonPose(SkeletonIndexFlag index, HandType hand)
|
||||
{
|
||||
return GesEventInput.Instance.GetSkeletonPose(index, hand);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取手地朝向
|
||||
/// </summary>
|
||||
/// <param name="handType">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 GetHandForward(HandType handType)
|
||||
{
|
||||
Vector3 handForward = (GetSkeletonPose(SkeletonIndexFlag.MIDDLE_FINGER_MCP, handType).position -
|
||||
GetSkeletonPose(SkeletonIndexFlag.WRIST, handType).position);
|
||||
return handForward;
|
||||
}
|
||||
|
||||
|
||||
#region 需要被重写的方法
|
||||
|
||||
public abstract void GestureLeftSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureRightSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureLeftFail();
|
||||
public abstract void GestureRightFail();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -4,61 +4,67 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Stary.Evo;
|
||||
|
||||
public interface IVoiceCommandSystem : ISystem
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
public void AddVoiceCommand(string content,string spell, Action action);
|
||||
public void DeleteVoiceCommand(string content);
|
||||
public void ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem
|
||||
{
|
||||
private VoiceCommandController _voiceController;
|
||||
protected virtual string ControllerName
|
||||
public interface IVoiceCommandSystem : ISystem
|
||||
{
|
||||
get { return "VoiceCommandController"; }
|
||||
public void AddVoiceCommand(string content, string spell, Action action);
|
||||
public void DeleteVoiceCommand(string content);
|
||||
public void ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
private void createVoiceCommandContriller()
|
||||
public class VoiceCommandSystem : AbstractSystem, IVoiceCommandSystem
|
||||
{
|
||||
GameObject VoiceControllerObject = GameObject.Find(ControllerName);
|
||||
if (VoiceControllerObject == null)
|
||||
private VoiceCommandController _voiceController;
|
||||
|
||||
protected virtual string ControllerName
|
||||
{
|
||||
VoiceControllerObject = new GameObject(ControllerName);
|
||||
get { return "VoiceCommandController"; }
|
||||
}
|
||||
_voiceController = VoiceControllerObject.GetComponent<VoiceCommandController>();
|
||||
if (_voiceController == null)
|
||||
|
||||
private void createVoiceCommandContriller()
|
||||
{
|
||||
_voiceController = VoiceControllerObject.AddComponent<VoiceCommandController>();
|
||||
GameObject VoiceControllerObject = GameObject.Find(ControllerName);
|
||||
if (VoiceControllerObject == null)
|
||||
{
|
||||
VoiceControllerObject = new GameObject(ControllerName);
|
||||
}
|
||||
|
||||
_voiceController = VoiceControllerObject.GetComponent<VoiceCommandController>();
|
||||
if (_voiceController == null)
|
||||
{
|
||||
_voiceController = VoiceControllerObject.AddComponent<VoiceCommandController>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddVoiceCommand(string content,string spell, Action action)
|
||||
{
|
||||
if (_voiceController == null) createVoiceCommandContriller();
|
||||
_voiceController.RegisteredVoiceCommand(content, spell, action);
|
||||
}
|
||||
|
||||
public void DeleteVoiceCommand(string content)
|
||||
{
|
||||
if(_voiceController!=null) _voiceController.DeleteVoiceCommand(content);
|
||||
}
|
||||
|
||||
public void ClearAllVoiceCommands()
|
||||
{
|
||||
if (_voiceController != null)
|
||||
public void AddVoiceCommand(string content, string spell, Action action)
|
||||
{
|
||||
_voiceController.ClearAllVoiceCommand();
|
||||
GameObject.Destroy(_voiceController.gameObject);
|
||||
if (_voiceController == null) createVoiceCommandContriller();
|
||||
_voiceController.RegisteredVoiceCommand(content, spell, action);
|
||||
}
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
public void DeleteVoiceCommand(string content)
|
||||
{
|
||||
if (_voiceController != null) _voiceController.DeleteVoiceCommand(content);
|
||||
}
|
||||
|
||||
public void ClearAllVoiceCommands()
|
||||
{
|
||||
if (_voiceController != null)
|
||||
{
|
||||
_voiceController.ClearAllVoiceCommand();
|
||||
GameObject.Destroy(_voiceController.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,87 +6,92 @@ using Stary.Evo;
|
||||
using Rokid.UXR.Module;
|
||||
using UnityEngine.Android;
|
||||
|
||||
public class VoiceCommandController : MonoBehaviour
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
public Dictionary<string, Action> VoiceCommands = new Dictionary<string, Action>();
|
||||
public bool isInit = false;
|
||||
|
||||
void Awake()
|
||||
public class VoiceCommandController : MonoBehaviour
|
||||
{
|
||||
public Dictionary<string, Action> VoiceCommands = new Dictionary<string, Action>();
|
||||
public bool isInit = false;
|
||||
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
//if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO")) return;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册语音指令
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="spell"></param>
|
||||
/// <param name="action"></param>
|
||||
public void RegisteredVoiceCommand(string content, string spell, Action action)
|
||||
{
|
||||
if (!isInit)
|
||||
void Awake()
|
||||
{
|
||||
if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO"))
|
||||
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
//if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO")) return;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册语音指令
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="spell"></param>
|
||||
/// <param name="action"></param>
|
||||
public void RegisteredVoiceCommand(string content, string spell, Action action)
|
||||
{
|
||||
if (!isInit)
|
||||
{
|
||||
Permission.RequestUserPermission("android.permission.RECORD_AUDIO");
|
||||
if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO"))
|
||||
{
|
||||
Permission.RequestUserPermission("android.permission.RECORD_AUDIO");
|
||||
}
|
||||
|
||||
ModuleManager.Instance.RegistModule("com.rokid.voicecommand.VoiceCommandHelper", false);
|
||||
OfflineVoiceModule.Instance.ChangeVoiceCommandLanguage(LANGUAGE.CHINESE);
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
ModuleManager.Instance.RegistModule("com.rokid.voicecommand.VoiceCommandHelper", false);
|
||||
OfflineVoiceModule.Instance.ChangeVoiceCommandLanguage(LANGUAGE.CHINESE);
|
||||
isInit = true;
|
||||
if (!VoiceCommands.ContainsKey(content))
|
||||
{
|
||||
VoiceCommands.Add(content, action);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"语音命令 :“'{content}' ”已经注册了!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
OfflineVoiceModule.Instance.AddInstruct(LANGUAGE.CHINESE, content, spell, this.gameObject.name,
|
||||
"OnReceive");
|
||||
OfflineVoiceModule.Instance.Commit();
|
||||
}
|
||||
|
||||
if (!VoiceCommands.ContainsKey(content))
|
||||
/// <summary>
|
||||
/// 删除语音指令
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
public void DeleteVoiceCommand(string content)
|
||||
{
|
||||
VoiceCommands.Add(content, action);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"语音命令 :“'{content}' ”已经注册了!!!");
|
||||
return;
|
||||
}
|
||||
OfflineVoiceModule.Instance.AddInstruct(LANGUAGE.CHINESE, content, spell, this.gameObject.name, "OnReceive");
|
||||
OfflineVoiceModule.Instance.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除语音指令
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
public void DeleteVoiceCommand(string content)
|
||||
{
|
||||
if (VoiceCommands.ContainsKey(content))
|
||||
{
|
||||
VoiceCommands.Remove(content);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"语音命令 :“'{content}' 不存在!!!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有语音指令
|
||||
/// </summary>
|
||||
public void ClearAllVoiceCommand()
|
||||
{
|
||||
VoiceCommands.Clear();
|
||||
OfflineVoiceModule.Instance.ClearAllInstruct();
|
||||
OfflineVoiceModule.Instance.Commit();
|
||||
}
|
||||
|
||||
void OnReceive(string msg)
|
||||
{
|
||||
if (VoiceCommands.TryGetValue(msg, out Action action))
|
||||
{
|
||||
action?.Invoke();
|
||||
if (VoiceCommands.ContainsKey(content))
|
||||
{
|
||||
VoiceCommands.Remove(content);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"语音命令 :“'{content}' 不存在!!!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有语音指令
|
||||
/// </summary>
|
||||
public void ClearAllVoiceCommand()
|
||||
{
|
||||
VoiceCommands.Clear();
|
||||
OfflineVoiceModule.Instance.ClearAllInstruct();
|
||||
OfflineVoiceModule.Instance.Commit();
|
||||
}
|
||||
|
||||
void OnReceive(string msg)
|
||||
{
|
||||
if (VoiceCommands.TryGetValue(msg, out Action action))
|
||||
{
|
||||
action?.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/07.RKTools/RunTime/TrackedImage.meta
Normal file
3
Assets/07.RKTools/RunTime/TrackedImage.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef115ccabf224be8a3f28036d2f0b488
|
||||
timeCreated: 1747635144
|
||||
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Rokid.UXR.Module;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
public class TrackedImageEvoManager : ARTrackedImageManager
|
||||
{
|
||||
[TableList] public List<TarkedImageEvoData> TrackedImages;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
TrackedImages = new List<TarkedImageEvoData>();
|
||||
}
|
||||
|
||||
public TarkedImageEvoData GetTrackedImageEvoData(int imageIndex)
|
||||
{
|
||||
foreach (var imageEvoData in TrackedImages)
|
||||
{
|
||||
if (imageEvoData.imageIndex == imageIndex)
|
||||
{
|
||||
return imageEvoData;
|
||||
}
|
||||
}
|
||||
Debug.LogError($"StaryEvo:未找到对应的图片的id数据,请检查是否进行前置识别 index:{imageIndex}");
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetTrackedImageEvoData(int imageIndex, Transform transform)
|
||||
{
|
||||
foreach (var imageEvoData in TrackedImages)
|
||||
{
|
||||
if (imageEvoData.imageIndex == imageIndex)
|
||||
{
|
||||
imageEvoData.position = transform.position;
|
||||
imageEvoData.rotation = transform.eulerAngles;
|
||||
imageEvoData.scale = transform.localScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TarkedImageEvoData GetTrackedImageEvoData(string domain)
|
||||
{
|
||||
foreach (var imageEvoData in TrackedImages)
|
||||
{
|
||||
if (imageEvoData.domain == domain)
|
||||
{
|
||||
return imageEvoData;
|
||||
}
|
||||
}
|
||||
Debug.LogError($"StaryEvo:未找到对应的domain的id数据,请检查是否进行前置识别 domain:{domain}");
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetTrackedImageEvoData(string domain, Transform transform)
|
||||
{
|
||||
foreach (var imageEvoData in TrackedImages)
|
||||
{
|
||||
if (imageEvoData.domain == domain)
|
||||
{
|
||||
imageEvoData.position = transform.position;
|
||||
imageEvoData.rotation = transform.eulerAngles;
|
||||
imageEvoData.scale = transform.localScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class TarkedImageEvoData
|
||||
{
|
||||
[VerticalGroup("key")] public string domain;
|
||||
[VerticalGroup("key")] public int imageIndex;
|
||||
|
||||
[VerticalGroup("transform")] public Vector3 position;
|
||||
[VerticalGroup("transform")] public Vector3 rotation;
|
||||
[VerticalGroup("transform")] public Vector3 scale;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be33290f8aa3440cac3e24a68606958b
|
||||
timeCreated: 1747635178
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.rktools",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"displayName": "07.RKTools",
|
||||
"description": "Rokid工具",
|
||||
"unity": "2021.3",
|
||||
@@ -15,6 +15,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"com.rokid.xr.unity":"3.0.3",
|
||||
"com.staryevo.main":"1.x.x"
|
||||
"com.staryevo.main":"1.x.x",
|
||||
"com.rokid.xr.extension":"x.x.x"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user