【m】Rokid工具修改
This commit is contained in:
8
Assets/07.RKTools/RunTime.meta
Normal file
8
Assets/07.RKTools/RunTime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1654ed807ee7c24c94cab4c172e6f91
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/07.RKTools/RunTime/AddInteraction.meta
Normal file
8
Assets/07.RKTools/RunTime/AddInteraction.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 198b77f2e2fe1e149bdb8e23f2c74b20
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
154
Assets/07.RKTools/RunTime/AddInteraction/RKAddInteraction.cs
Normal file
154
Assets/07.RKTools/RunTime/AddInteraction/RKAddInteraction.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Rokid.UXR.Interaction;
|
||||
using Stary.Evo;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class RKAddInteraction : MonoBehaviour
|
||||
{
|
||||
#region 触摸
|
||||
/// <summary>
|
||||
/// 添加触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
/// <param name="TouchEvent">触碰后事件</param>
|
||||
public virtual void ObjectAddTouchEvent(GameObject Touchedobject, System.Action<GameObject> TouchEvent, float TouchScale = 1.2f)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
public virtual void ObjectPauseTouchEvent(GameObject Touchedobject)
|
||||
{
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null)
|
||||
{
|
||||
ObjectCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
public virtual void ObjectResumeTouchEvent(GameObject Touchedobject)
|
||||
{
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider != null)
|
||||
{
|
||||
ObjectCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除触摸事件
|
||||
/// </summary>
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
|
||||
public virtual void ObjectRemoveTouchEvent(GameObject Touchedobject)
|
||||
{
|
||||
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
|
||||
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHoverBegin.RemoveAllListeners();
|
||||
Destroy(GrabInteractable);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 拖动
|
||||
|
||||
/// <summary>
|
||||
/// 添加拖动事件
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject">被拖动物体</param>
|
||||
/// <param name="DragingEvent">拖动时执行的方法</param>
|
||||
public virtual void objectAddDrag(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 virtual void objectPauseDrag(GameObject Dragedobject)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider!= null) ObjectCollider.enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复拖动
|
||||
/// </summary>
|
||||
/// <param name="Dragedobject"></param>
|
||||
public virtual void objectResumeDrag(GameObject Dragedobject)
|
||||
{
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
if (ObjectCollider!= null) ObjectCollider.enabled = true;
|
||||
}
|
||||
|
||||
public virtual void objectRemoveDrag(GameObject Dragedobject)
|
||||
{
|
||||
Throwable Throwable = Dragedobject.GetComponent<Throwable>();
|
||||
GrabInteractable GrabInteractable = Dragedobject.GetComponent<GrabInteractable>();
|
||||
if (Throwable != null) Destroy(Throwable);
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHeldUpdate.RemoveAllListeners();
|
||||
Destroy(GrabInteractable);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5cbdc9e864eefd4fba9661707859b6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/07.RKTools/RunTime/GestureRecognition.meta
Normal file
8
Assets/07.RKTools/RunTime/GestureRecognition.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cba726e4bef03144c99f9e7ef6fa0de8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Assets/07.RKTools/RunTime/GestureRecognition/GestureBase.cs
Normal file
128
Assets/07.RKTools/RunTime/GestureRecognition/GestureBase.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Rokid.UXR.Interaction;
|
||||
|
||||
public abstract class GestureBase : MonoBehaviour
|
||||
{
|
||||
private GestureBean leftBean = null;
|
||||
private GestureBean rightBean = null;
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess += OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed += OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand += OnRenderHand;
|
||||
}
|
||||
|
||||
protected void OnDisable()
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess -= OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed -= OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand -= OnRenderHand;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d59c6f28c5e793c43a03e7ba7be931d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/07.RKTools/RunTime/RKTools.RunTime.asmdef
Normal file
18
Assets/07.RKTools/RunTime/RKTools.RunTime.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "RKVoiceCommand.RunTime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:6447e10b87dc140ab924878c1ecef665",
|
||||
"GUID:fe14bc9dd681249d19cf4ef377c7e29e",
|
||||
"GUID:d1a793c2b6959e04ea45b972eaa369c8"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
13
Assets/07.RKTools/RunTime/RKTools.RunTime.asmdef.meta
Normal file
13
Assets/07.RKTools/RunTime/RKTools.RunTime.asmdef.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
<<<<<<<< HEAD:Assets/05.TableTextConversion/Editor/Excel.meta
|
||||
guid: 10c9b58b77ad42b4193e2a393b1a9899
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
========
|
||||
guid: 44e8639d57fc2a94b94ecef44bf1e36a
|
||||
AssemblyDefinitionImporter:
|
||||
>>>>>>>> 04.AudioCore:Assets/04.AudioCore/RunTime/AudioCore.RunTime.asmdef.meta
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/07.RKTools/RunTime/RKVoiceCommand.meta
Normal file
8
Assets/07.RKTools/RunTime/RKVoiceCommand.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97334fe27b1e8f2488496b4eebec0377
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Stary.Evo;
|
||||
|
||||
public interface IVoiceCommandSystem : ISystem
|
||||
{
|
||||
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
|
||||
{
|
||||
get { return "VoiceCommandController"; }
|
||||
}
|
||||
|
||||
private void createVoiceCommandContriller()
|
||||
{
|
||||
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)
|
||||
{
|
||||
_voiceController.ClearAllVoiceCommand();
|
||||
GameObject.Destroy(_voiceController.gameObject);
|
||||
}
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 073d8fadbb202ad42a540fd5299555c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Stary.Evo;
|
||||
using Rokid.UXR.Module;
|
||||
using UnityEngine.Android;
|
||||
|
||||
public class VoiceCommandController : MonoBehaviour
|
||||
{
|
||||
public Dictionary<string, Action> VoiceCommands = new Dictionary<string, Action>();
|
||||
public bool isInit = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f55b7179dceeae47826f4f0f08ba3fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/07.RKTools/package.json
Normal file
20
Assets/07.RKTools/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "com.staryevo.rktools",
|
||||
"version": "1.0.0",
|
||||
"displayName": "07.RKTools",
|
||||
"description": "Rokid工具",
|
||||
"unity": "2021.3",
|
||||
"unityRelease": "23f1",
|
||||
"keywords": [
|
||||
"unity",
|
||||
"scirpt"
|
||||
],
|
||||
"author": {
|
||||
"name": "staryEvo",
|
||||
"url": "https://www.unity3d.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"com.rokid.xr.unity":"3.0.3",
|
||||
"com.staryevo.main":"1.x.x"
|
||||
}
|
||||
}
|
||||
7
Assets/07.RKTools/package.json.meta
Normal file
7
Assets/07.RKTools/package.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1e566c37939b1c45885d8ca929414a7
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user