From 53902896c0012e8bf292c08e3c0f3513bbd9c698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=93=AE?= <834207172@qq.com> Date: Mon, 19 May 2025 15:42:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90m=E3=80=91=E6=B7=BB=E5=8A=A0=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddInteraction/RKAddInteraction.cs | 285 +++++++++--------- .../RunTime/GestureRecognition/GestureBase.cs | 243 +++++++-------- .../RKVoiceCommand/IVoiceCommandSystem.cs | 94 +++--- .../RKVoiceCommand/VoiceCommandController.cs | 153 +++++----- Assets/07.RKTools/RunTime/TrackedImage.meta | 3 + .../TrackedImage/TrackedImageEvoManager.cs | 81 +++++ .../TrackedImageEvoManager.cs.meta | 3 + Assets/07.RKTools/package.json | 5 +- 8 files changed, 488 insertions(+), 379 deletions(-) create mode 100644 Assets/07.RKTools/RunTime/TrackedImage.meta create mode 100644 Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs create mode 100644 Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs.meta diff --git a/Assets/07.RKTools/RunTime/AddInteraction/RKAddInteraction.cs b/Assets/07.RKTools/RunTime/AddInteraction/RKAddInteraction.cs index 598d5ea..d60fbea 100644 --- a/Assets/07.RKTools/RunTime/AddInteraction/RKAddInteraction.cs +++ b/Assets/07.RKTools/RunTime/AddInteraction/RKAddInteraction.cs @@ -4,151 +4,158 @@ using Rokid.UXR.Interaction; using Stary.Evo; using UnityEngine; -public static class RKAddInteractionExtension +namespace Stary.Evo.RKTools { - #region 触摸 - /// - /// 添加触摸事件 - /// - /// 被触碰物体 - /// 触碰后事件 - public static void ObjectAddTouchEvent(this GameObject Touchedobject, System.Action TouchEvent, float TouchScale = 1.2f) + public static class RKAddInteractionExtension { - Collider ObjectCollider = Touchedobject.GetComponent(); - GrabInteractable GrabInteractable = Touchedobject.GetComponent(); + #region 触摸 - // 原有的组件设置优先级最高 - if (ObjectCollider == null) + /// + /// 添加触摸事件 + /// + /// 被触碰物体 + /// 触碰后事件 + public static void ObjectAddTouchEvent(this GameObject Touchedobject, System.Action TouchEvent, + float TouchScale = 1.2f) { - ObjectCollider = Touchedobject.AddComponent(); - ObjectCollider.isTrigger = true; + Collider ObjectCollider = Touchedobject.GetComponent(); + GrabInteractable GrabInteractable = Touchedobject.GetComponent(); + + // 原有的组件设置优先级最高 + if (ObjectCollider == null) + { + ObjectCollider = Touchedobject.AddComponent(); + ObjectCollider.isTrigger = true; + } + + if (GrabInteractable == null) + { + GrabInteractable = Touchedobject.AddComponent(); + GrabInteractable.rate = TouchScale; + } + + GrabInteractable.OnHoverBegin.AddListener(() => TouchEvent?.Invoke(Touchedobject)); } - if (GrabInteractable == null) + /// + /// 暂停触摸事件 + /// + /// 被触碰物体 + public static void ObjectPauseTouchEvent(this GameObject Touchedobject) { - GrabInteractable = Touchedobject.AddComponent(); - GrabInteractable.rate = TouchScale; + Collider ObjectCollider = Touchedobject.GetComponent(); + if (ObjectCollider != null) + { + ObjectCollider.enabled = false; + } } - - GrabInteractable.OnHoverBegin.AddListener(()=>TouchEvent?.Invoke(Touchedobject)); + + /// + /// 恢复触摸事件 + /// + /// 被触碰物体 + public static void ObjectResumeTouchEvent(this GameObject Touchedobject) + { + Collider ObjectCollider = Touchedobject.GetComponent(); + if (ObjectCollider != null) + { + ObjectCollider.enabled = true; + } + } + + /// + /// 移除触摸事件 + /// + /// 被触碰物体 + + public static void ObjectRemoveTouchEvent(this GameObject Touchedobject) + { + GrabInteractable GrabInteractable = Touchedobject.GetComponent(); + + if (GrabInteractable != null) + { + GrabInteractable.OnHoverBegin.RemoveAllListeners(); + Object.Destroy(GrabInteractable); + } + } + + #endregion + + #region 拖动 + + /// + /// 添加拖动事件 + /// + /// 被拖动物体 + /// 拖动时执行的方法 + public static void objectAddDrag(this GameObject Dragedobject, System.Action DragingEvent = null, + float DragScale = 1.2f) + { + Collider ObjectCollider = Dragedobject.GetComponent(); + GrabInteractable GrabInteractable = Dragedobject.GetComponent(); + Rigidbody Rigidbody = Dragedobject.GetComponent(); + Throwable Throwable = Dragedobject.GetComponent(); + + // 原有的组件设置优先级最高 + if (ObjectCollider == null) + { + ObjectCollider = Dragedobject.AddComponent(); + ObjectCollider.isTrigger = true; + } + + if (GrabInteractable == null) + { + GrabInteractable = Dragedobject.AddComponent(); + GrabInteractable.rate = DragScale; + } + + if (Rigidbody == null) + { + Rigidbody = Dragedobject.AddComponent(); + Rigidbody.useGravity = false; + } + + if (Throwable == null) + { + Throwable = Dragedobject.AddComponent(); + } + + GrabInteractable.OnHeldUpdate.AddListener(() => DragingEvent?.Invoke(Dragedobject)); + } + + /// + /// 暂停拖动 + /// + /// + public static void objectPauseDrag(this GameObject Dragedobject) + { + Collider ObjectCollider = Dragedobject.GetComponent(); + if (ObjectCollider != null) ObjectCollider.enabled = false; + } + + /// + /// 恢复拖动 + /// + /// + public static void objectResumeDrag(this GameObject Dragedobject) + { + Collider ObjectCollider = Dragedobject.GetComponent(); + if (ObjectCollider != null) ObjectCollider.enabled = true; + } + + public static void objectRemoveDrag(this GameObject Dragedobject) + { + Throwable Throwable = Dragedobject.GetComponent(); + GrabInteractable GrabInteractable = Dragedobject.GetComponent(); + if (Throwable != null) Object.Destroy(Throwable); + if (GrabInteractable != null) + { + GrabInteractable.OnHeldUpdate.RemoveAllListeners(); + Object.Destroy(GrabInteractable); + } + } + + #endregion + } - - /// - /// 暂停触摸事件 - /// - /// 被触碰物体 - public static void ObjectPauseTouchEvent(this GameObject Touchedobject) - { - Collider ObjectCollider = Touchedobject.GetComponent(); - if (ObjectCollider != null) - { - ObjectCollider.enabled = false; - } - } - - /// - /// 恢复触摸事件 - /// - /// 被触碰物体 - public static void ObjectResumeTouchEvent(this GameObject Touchedobject) - { - Collider ObjectCollider = Touchedobject.GetComponent(); - if (ObjectCollider != null) - { - ObjectCollider.enabled = true; - } - } - - /// - /// 移除触摸事件 - /// - /// 被触碰物体 - - public static void ObjectRemoveTouchEvent(this GameObject Touchedobject) - { - GrabInteractable GrabInteractable = Touchedobject.GetComponent(); - - if (GrabInteractable != null) - { - GrabInteractable.OnHoverBegin.RemoveAllListeners(); - Object.Destroy(GrabInteractable); - } - } - - #endregion - - #region 拖动 - - /// - /// 添加拖动事件 - /// - /// 被拖动物体 - /// 拖动时执行的方法 - public static void objectAddDrag(this GameObject Dragedobject, System.Action DragingEvent = null, float DragScale = 1.2f) - { - Collider ObjectCollider = Dragedobject.GetComponent(); - GrabInteractable GrabInteractable = Dragedobject.GetComponent(); - Rigidbody Rigidbody = Dragedobject.GetComponent(); - Throwable Throwable = Dragedobject.GetComponent(); - - // 原有的组件设置优先级最高 - if (ObjectCollider == null) - { - ObjectCollider = Dragedobject.AddComponent(); - ObjectCollider.isTrigger = true; - } - - if (GrabInteractable == null) - { - GrabInteractable = Dragedobject.AddComponent(); - GrabInteractable.rate = DragScale; - } - - if (Rigidbody == null) - { - Rigidbody = Dragedobject.AddComponent(); - Rigidbody.useGravity = false; - } - - if (Throwable == null) - { - Throwable = Dragedobject.AddComponent(); - } - - GrabInteractable.OnHeldUpdate.AddListener(()=>DragingEvent?.Invoke(Dragedobject)); - } - - /// - /// 暂停拖动 - /// - /// - public static void objectPauseDrag(this GameObject Dragedobject) - { - Collider ObjectCollider = Dragedobject.GetComponent(); - if (ObjectCollider!= null) ObjectCollider.enabled = false; - } - - /// - /// 恢复拖动 - /// - /// - public static void objectResumeDrag(this GameObject Dragedobject) - { - Collider ObjectCollider = Dragedobject.GetComponent(); - if (ObjectCollider!= null) ObjectCollider.enabled = true; - } - - public static void objectRemoveDrag(this GameObject Dragedobject) - { - Throwable Throwable = Dragedobject.GetComponent(); - GrabInteractable GrabInteractable = Dragedobject.GetComponent(); - if (Throwable != null) Object.Destroy(Throwable); - if (GrabInteractable != null) - { - GrabInteractable.OnHeldUpdate.RemoveAllListeners(); - Object.Destroy(GrabInteractable); - } - } - #endregion - -} +} \ No newline at end of file diff --git a/Assets/07.RKTools/RunTime/GestureRecognition/GestureBase.cs b/Assets/07.RKTools/RunTime/GestureRecognition/GestureBase.cs index 9f3767d..4dc3bd8 100644 --- a/Assets/07.RKTools/RunTime/GestureRecognition/GestureBase.cs +++ b/Assets/07.RKTools/RunTime/GestureRecognition/GestureBase.cs @@ -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 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; + } + } + + + /// + /// 获取骨架点位置 + /// + /// 骨架序号 + /// 哪只手 + /// + public Pose GetSkeletonPose(SkeletonIndexFlag index, HandType hand) + { + return GesEventInput.Instance.GetSkeletonPose(index, hand); + } + + + /// + /// 获取手地朝向 + /// + /// 哪只手 + /// + 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 + } - - 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; - } - } - - - /// - /// 获取骨架点位置 - /// - /// 骨架序号 - /// 哪只手 - /// - public Pose GetSkeletonPose(SkeletonIndexFlag index, HandType hand) - { - return GesEventInput.Instance.GetSkeletonPose(index, hand); - } - - - /// - /// 获取手地朝向 - /// - /// 哪只手 - /// - 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 - -} +} \ No newline at end of file diff --git a/Assets/07.RKTools/RunTime/RKVoiceCommand/IVoiceCommandSystem.cs b/Assets/07.RKTools/RunTime/RKVoiceCommand/IVoiceCommandSystem.cs index be1c816..4610b24 100644 --- a/Assets/07.RKTools/RunTime/RKVoiceCommand/IVoiceCommandSystem.cs +++ b/Assets/07.RKTools/RunTime/RKVoiceCommand/IVoiceCommandSystem.cs @@ -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(); - if (_voiceController == null) + + private void createVoiceCommandContriller() { - _voiceController = VoiceControllerObject.AddComponent(); + GameObject VoiceControllerObject = GameObject.Find(ControllerName); + if (VoiceControllerObject == null) + { + VoiceControllerObject = new GameObject(ControllerName); + } + + _voiceController = VoiceControllerObject.GetComponent(); + if (_voiceController == null) + { + _voiceController = VoiceControllerObject.AddComponent(); + } } - } - 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() + { + + } } } \ No newline at end of file diff --git a/Assets/07.RKTools/RunTime/RKVoiceCommand/VoiceCommandController.cs b/Assets/07.RKTools/RunTime/RKVoiceCommand/VoiceCommandController.cs index 728c2f6..e3d0a3f 100644 --- a/Assets/07.RKTools/RunTime/RKVoiceCommand/VoiceCommandController.cs +++ b/Assets/07.RKTools/RunTime/RKVoiceCommand/VoiceCommandController.cs @@ -6,87 +6,92 @@ using Stary.Evo; using Rokid.UXR.Module; using UnityEngine.Android; -public class VoiceCommandController : MonoBehaviour +namespace Stary.Evo.RKTools { - public Dictionary VoiceCommands = new Dictionary(); - public bool isInit = false; - - void Awake() + public class VoiceCommandController : MonoBehaviour { - - } + public Dictionary VoiceCommands = new Dictionary(); + public bool isInit = false; - void Start() - { - //if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO")) return; - - } - - /// - /// 注册语音指令 - /// - /// - /// - /// - 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; + + } + + /// + /// 注册语音指令 + /// + /// + /// + /// + 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(); - } - /// - /// 删除语音指令 - /// - /// - public void DeleteVoiceCommand(string content) - { - if (VoiceCommands.ContainsKey(content)) - { - VoiceCommands.Remove(content); - } - else - { - Debug.LogWarning($"语音命令 :“'{content}' 不存在!!!"); - } - } + 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(); + } + + /// + /// 删除语音指令 + /// + /// + public void DeleteVoiceCommand(string content) + { + if (VoiceCommands.ContainsKey(content)) + { + VoiceCommands.Remove(content); + } + else + { + Debug.LogWarning($"语音命令 :“'{content}' 不存在!!!"); + } + } + + /// + /// 清除所有语音指令 + /// + public void ClearAllVoiceCommand() + { + VoiceCommands.Clear(); + OfflineVoiceModule.Instance.ClearAllInstruct(); + OfflineVoiceModule.Instance.Commit(); + } + + void OnReceive(string msg) + { + if (VoiceCommands.TryGetValue(msg, out Action action)) + { + action?.Invoke(); + } - /// - /// 清除所有语音指令 - /// - public void ClearAllVoiceCommand() - { - VoiceCommands.Clear(); - OfflineVoiceModule.Instance.ClearAllInstruct(); - OfflineVoiceModule.Instance.Commit(); - } - - void OnReceive(string msg) - { - if (VoiceCommands.TryGetValue(msg, out Action action)) - { - action?.Invoke(); } - } -} +} \ No newline at end of file diff --git a/Assets/07.RKTools/RunTime/TrackedImage.meta b/Assets/07.RKTools/RunTime/TrackedImage.meta new file mode 100644 index 0000000..08402d5 --- /dev/null +++ b/Assets/07.RKTools/RunTime/TrackedImage.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ef115ccabf224be8a3f28036d2f0b488 +timeCreated: 1747635144 \ No newline at end of file diff --git a/Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs b/Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs new file mode 100644 index 0000000..afb38cc --- /dev/null +++ b/Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs @@ -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 TrackedImages; + + private void Start() + { + TrackedImages = new List(); + } + + 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; + } +} \ No newline at end of file diff --git a/Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs.meta b/Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs.meta new file mode 100644 index 0000000..b75453c --- /dev/null +++ b/Assets/07.RKTools/RunTime/TrackedImage/TrackedImageEvoManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: be33290f8aa3440cac3e24a68606958b +timeCreated: 1747635178 \ No newline at end of file diff --git a/Assets/07.RKTools/package.json b/Assets/07.RKTools/package.json index 7596d0a..1357a94 100644 --- a/Assets/07.RKTools/package.json +++ b/Assets/07.RKTools/package.json @@ -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" } }