【m】添加图像识别

This commit is contained in:
2025-05-19 15:42:24 +08:00
parent 9362a57d80
commit 53902896c0
8 changed files with 488 additions and 379 deletions

View File

@@ -4,15 +4,19 @@ using Rokid.UXR.Interaction;
using Stary.Evo;
using UnityEngine;
public static class RKAddInteractionExtension
namespace Stary.Evo.RKTools
{
public static class RKAddInteractionExtension
{
#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 void ObjectAddTouchEvent(this GameObject Touchedobject, System.Action<GameObject> TouchEvent,
float TouchScale = 1.2f)
{
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
@@ -30,7 +34,7 @@ public static class RKAddInteractionExtension
GrabInteractable.rate = TouchScale;
}
GrabInteractable.OnHoverBegin.AddListener(()=>TouchEvent?.Invoke(Touchedobject));
GrabInteractable.OnHoverBegin.AddListener(() => TouchEvent?.Invoke(Touchedobject));
}
/// <summary>
@@ -84,7 +88,8 @@ public static class RKAddInteractionExtension
/// </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)
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>();
@@ -115,7 +120,7 @@ public static class RKAddInteractionExtension
Throwable = Dragedobject.AddComponent<Throwable>();
}
GrabInteractable.OnHeldUpdate.AddListener(()=>DragingEvent?.Invoke(Dragedobject));
GrabInteractable.OnHeldUpdate.AddListener(() => DragingEvent?.Invoke(Dragedobject));
}
/// <summary>
@@ -125,7 +130,7 @@ public static class RKAddInteractionExtension
public static void objectPauseDrag(this GameObject Dragedobject)
{
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
if (ObjectCollider!= null) ObjectCollider.enabled = false;
if (ObjectCollider != null) ObjectCollider.enabled = false;
}
/// <summary>
@@ -135,7 +140,7 @@ public static class RKAddInteractionExtension
public static void objectResumeDrag(this GameObject Dragedobject)
{
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
if (ObjectCollider!= null) ObjectCollider.enabled = true;
if (ObjectCollider != null) ObjectCollider.enabled = true;
}
public static void objectRemoveDrag(this GameObject Dragedobject)
@@ -149,6 +154,8 @@ public static class RKAddInteractionExtension
Object.Destroy(GrabInteractable);
}
}
#endregion
}
}

View File

@@ -3,8 +3,10 @@ using System.Collections.Generic;
using UnityEngine;
using Rokid.UXR.Interaction;
public abstract class GestureBase : MonoBehaviour
namespace Stary.Evo.RKTools
{
public abstract class GestureBase : MonoBehaviour
{
private GestureBean leftBean = null;
private GestureBean rightBean = null;
@@ -24,11 +26,11 @@ public abstract class GestureBase : MonoBehaviour
protected void FixedUpdate()
{
if (leftBean!=null)
if (leftBean != null)
{
GestureType type= GesEventInput.Instance.GetGestureType(HandType.LeftHand);
GestureType type = GesEventInput.Instance.GetGestureType(HandType.LeftHand);
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.LeftHand).forward;
GestureLeftSuccess(type,handForward);
GestureLeftSuccess(type, handForward);
}
else
{
@@ -37,9 +39,9 @@ public abstract class GestureBase : MonoBehaviour
if (rightBean != null)
{
GestureType type= GesEventInput.Instance.GetGestureType(HandType.RightHand);
GestureType type = GesEventInput.Instance.GetGestureType(HandType.RightHand);
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.RightHand).forward;
GestureRightSuccess(type,handForward);
GestureRightSuccess(type, handForward);
}
else
{
@@ -125,4 +127,5 @@ public abstract class GestureBase : MonoBehaviour
#endregion
}
}

View File

@@ -4,16 +4,19 @@ 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 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
{
public class VoiceCommandSystem : AbstractSystem, IVoiceCommandSystem
{
private VoiceCommandController _voiceController;
protected virtual string ControllerName
{
get { return "VoiceCommandController"; }
@@ -26,6 +29,7 @@ public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem
{
VoiceControllerObject = new GameObject(ControllerName);
}
_voiceController = VoiceControllerObject.GetComponent<VoiceCommandController>();
if (_voiceController == null)
{
@@ -33,7 +37,7 @@ public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem
}
}
public void AddVoiceCommand(string content,string spell, Action action)
public void AddVoiceCommand(string content, string spell, Action action)
{
if (_voiceController == null) createVoiceCommandContriller();
_voiceController.RegisteredVoiceCommand(content, spell, action);
@@ -41,7 +45,7 @@ public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem
public void DeleteVoiceCommand(string content)
{
if(_voiceController!=null) _voiceController.DeleteVoiceCommand(content);
if (_voiceController != null) _voiceController.DeleteVoiceCommand(content);
}
public void ClearAllVoiceCommands()
@@ -52,6 +56,7 @@ public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem
GameObject.Destroy(_voiceController.gameObject);
}
}
public override void Dispose()
{
ClearAllVoiceCommands();
@@ -61,4 +66,5 @@ public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem
{
}
}
}

View File

@@ -6,8 +6,10 @@ using Stary.Evo;
using Rokid.UXR.Module;
using UnityEngine.Android;
public class VoiceCommandController : MonoBehaviour
namespace Stary.Evo.RKTools
{
public class VoiceCommandController : MonoBehaviour
{
public Dictionary<string, Action> VoiceCommands = new Dictionary<string, Action>();
public bool isInit = false;
@@ -51,7 +53,9 @@ public class VoiceCommandController : MonoBehaviour
Debug.LogError($"语音命令 :“'{content}' ”已经注册了!!!");
return;
}
OfflineVoiceModule.Instance.AddInstruct(LANGUAGE.CHINESE, content, spell, this.gameObject.name, "OnReceive");
OfflineVoiceModule.Instance.AddInstruct(LANGUAGE.CHINESE, content, spell, this.gameObject.name,
"OnReceive");
OfflineVoiceModule.Instance.Commit();
}
@@ -89,4 +93,5 @@ public class VoiceCommandController : MonoBehaviour
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ef115ccabf224be8a3f28036d2f0b488
timeCreated: 1747635144

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: be33290f8aa3440cac3e24a68606958b
timeCreated: 1747635178

View File

@@ -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"
}
}