From 99c4f11d5482618a33aeff1211c7652bd7b9c053 Mon Sep 17 00:00:00 2001 From: terric Date: Fri, 10 Nov 2023 16:12:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=8B=E4=BB=B6=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/RobotController.cs | 9 +++- Assets/Scripts/EventManager.cs | 23 ++++++---- .../PoseCheck/GudieAnimationManager.cs | 20 ++++++++- Assets/Scripts/PoseCheck/HeadTurnLeft.cs | 16 ++++++- .../Scripts/PoseCheck/MotionCaptureManager.cs | 29 +++++++----- Assets/Scripts/UI/GuideUI.cs | 44 +++++-------------- 6 files changed, 84 insertions(+), 57 deletions(-) diff --git a/Assets/RobotController.cs b/Assets/RobotController.cs index d723810..e3ae382 100644 --- a/Assets/RobotController.cs +++ b/Assets/RobotController.cs @@ -7,12 +7,17 @@ public class RobotController : MonoBehaviour { public void CheckAction(AvatarAction action) { - EventManager.Instance.Dispatch("EstimateAction", action); + EventManager.Instance.Dispatch(YogaEventType.EstimateAction, action); } public void FinishCurrentActionCheck() { - EventManager.Instance.Dispatch("ScoreUpdate"); + EventManager.Instance.Dispatch(YogaEventType.ScoreUpdate); + } + + public void GetActionBasePoint() + { + EventManager.Instance.Dispatch(YogaEventType.GetActionBasePoint); } } diff --git a/Assets/Scripts/EventManager.cs b/Assets/Scripts/EventManager.cs index 1575807..eba31f1 100644 --- a/Assets/Scripts/EventManager.cs +++ b/Assets/Scripts/EventManager.cs @@ -8,9 +8,9 @@ public class EventManager : MonoSingleton { public delegate void EventHandler(params object[] args); - private Dictionary _actionDic = new Dictionary(); - private Dictionary _actionsDic = new Dictionary(); - public void AddEventListener(string eventName, Action handler) + private Dictionary _actionDic = new Dictionary(); + private Dictionary _actionsDic = new Dictionary(); + public void AddEventListener(YogaEventType eventName, Action handler) { if (!_actionDic.ContainsKey(eventName)) { @@ -23,7 +23,7 @@ public class EventManager : MonoSingleton } } - public void RemoveEventListener(string eventName, Action handler) + public void RemoveEventListener(YogaEventType eventName, Action handler) { if (!_actionDic.ContainsKey(eventName)) return; @@ -31,7 +31,7 @@ public class EventManager : MonoSingleton _actionDic[eventName] -= handler; } - public void Dispatch(string eventName) + public void Dispatch(YogaEventType eventName) { if (!_actionDic.ContainsKey(eventName)) return; @@ -40,7 +40,7 @@ public class EventManager : MonoSingleton } //带参数的事件 - public void AddEventListener(string eventName, EventHandler handler) + public void AddEventListener(YogaEventType eventName, EventHandler handler) { if (!_actionsDic.ContainsKey(eventName)) { @@ -53,7 +53,7 @@ public class EventManager : MonoSingleton } } - public void RemoveEventListener(string eventName, EventHandler handler) + public void RemoveEventListener(YogaEventType eventName, EventHandler handler) { if (!_actionsDic.ContainsKey(eventName)) return; @@ -61,11 +61,18 @@ public class EventManager : MonoSingleton _actionsDic[eventName] -= handler; } - public void Dispatch(string eventName, params object[] param) + public void Dispatch(YogaEventType eventName, params object[] param) { if (!_actionsDic.ContainsKey(eventName)) return; _actionsDic[eventName]?.Invoke(param); } +} + +public enum YogaEventType +{ + StartMotionCapture, + StopMotionCapture, + EstimateAction, } \ No newline at end of file diff --git a/Assets/Scripts/PoseCheck/GudieAnimationManager.cs b/Assets/Scripts/PoseCheck/GudieAnimationManager.cs index 59cca8e..ae838f7 100644 --- a/Assets/Scripts/PoseCheck/GudieAnimationManager.cs +++ b/Assets/Scripts/PoseCheck/GudieAnimationManager.cs @@ -1,10 +1,11 @@ -using System.Collections; +锘縰sing System.Collections; using System.Collections.Generic; using UnityEngine; public class GudieAnimationManager : MonoBehaviour { private Animator _animator; + private string _currName; private void Awake() { @@ -14,6 +15,21 @@ public class GudieAnimationManager : MonoBehaviour public void Play(string name) { _animator.CrossFade(name, 0.5f); + _currName = name; + } + + private void Update() + { + if (string.IsNullOrEmpty(_currName)) + return; + //褰撴湭杈惧埌鎸囨爣涓斿姩鐢绘挱鏀惧畬姣曟椂锛岄噸鏂版挱鏀 + if (_animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) + { + if (YogaManager.Instance.CurrentActionCount < YogaManager.Instance.MaxActionCount) + { + _animator.Play(_currName, 0, 0.0f); + } + } } public void Stop() @@ -23,7 +39,7 @@ public class GudieAnimationManager : MonoBehaviour public void FrameEstimate() { - EventManager.Instance.Dispatch("PoseEstimate"); + EventManager.Instance.Dispatch(YogaEventType.PoseEstimate); } } diff --git a/Assets/Scripts/PoseCheck/HeadTurnLeft.cs b/Assets/Scripts/PoseCheck/HeadTurnLeft.cs index bc63f7d..5b91998 100644 --- a/Assets/Scripts/PoseCheck/HeadTurnLeft.cs +++ b/Assets/Scripts/PoseCheck/HeadTurnLeft.cs @@ -10,10 +10,24 @@ public class HeadTurnLeft : PoseBase public override bool CheckPose(List points) { - if (!CheckPoint(points, "Nose")) + if (!CheckPoint(points, "Nose") || CheckPoint(points, "LEar") || CheckPoint(points, "Neck")) // 蹇呴』鍖呭惈 Nose 鍜 LEar 鍜 Neck 鐨勭偣浣 return false; //宸﹁浆澶存娴 + //褰 LShoulder 鍜 RShoulder 閮芥湭妫娴嬪埌鏃 + if (!CheckPoint(points, "LShoulder") || !CheckPoint(points, "RShoulder")) + { + + } + + + //褰 LShoulder 鍜 RShoulder 閮芥娴嬪埌鏃讹紝浠 LShoulder 鍜 RShoulder 涓哄熀鍑 + + + // + + + if (CheckPoint(points, "LEar") && !CheckPoint(points, "REar")) { return true; diff --git a/Assets/Scripts/PoseCheck/MotionCaptureManager.cs b/Assets/Scripts/PoseCheck/MotionCaptureManager.cs index da1a5ab..78375b5 100644 --- a/Assets/Scripts/PoseCheck/MotionCaptureManager.cs +++ b/Assets/Scripts/PoseCheck/MotionCaptureManager.cs @@ -56,18 +56,22 @@ namespace Yoga private void OnEnable() { - EventManager.Instance.AddEventListener("StartMotionCapture", OnStartMotionCapture); - EventManager.Instance.AddEventListener("StopMotionCapture", OnStopMotionCapture); - EventManager.Instance.AddEventListener("EstimateAction", EstimateAction); - EventManager.Instance.AddEventListener("ScoreUpdate", ScoreUpdate); + EventManager.Instance.AddEventListener(YogaEventType.StartMotionCapture, OnStartMotionCapture); + EventManager.Instance.AddEventListener(YogaEventType.StopMotionCapture, OnStopMotionCapture); + EventManager.Instance.AddEventListener(YogaEventType.EstimateAction, EstimateAction); + EventManager.Instance.AddEventListener(YogaEventType.ScoreUpdate, ScoreUpdate); + EventManager.Instance.AddEventListener(YogaEventType.GetActionBasePoint, GetActionBasePoint); } + + private void OnDisable() { - EventManager.Instance.RemoveEventListener("StartMotionCapture", OnStartMotionCapture); - EventManager.Instance.RemoveEventListener("StopMotionCapture", OnStopMotionCapture); - EventManager.Instance.RemoveEventListener("EstimateAction", EstimateAction); - EventManager.Instance.RemoveEventListener("ScoreUpdate", ScoreUpdate); + EventManager.Instance.RemoveEventListener(YogaEventType.StartMotionCapture, OnStartMotionCapture); + EventManager.Instance.RemoveEventListener(YogaEventType.StopMotionCapture, OnStopMotionCapture); + EventManager.Instance.RemoveEventListener(YogaEventType.EstimateAction, EstimateAction); + EventManager.Instance.RemoveEventListener(YogaEventType.ScoreUpdate, ScoreUpdate); + EventManager.Instance.RemoveEventListener(YogaEventType.GetActionBasePoint, GetActionBasePoint); } private void OnStartMotionCapture() @@ -81,7 +85,10 @@ namespace Yoga this.enabled = false; _isOnCamCapture = false; } - + private void GetActionBasePoint() + { + throw new NotImplementedException(); + } public override void Init() { base.Init(); @@ -378,11 +385,11 @@ namespace Yoga if (_isCorrectAction) { - EventManager.Instance.Dispatch("ActionSuccess"); + EventManager.Instance.Dispatch(YogaEventType.ActionSuccess); } else { - EventManager.Instance.Dispatch("ActionFailed"); + EventManager.Instance.Dispatch(YogaEventType.ActionFailed); } _isCorrectAction = false;//閲嶇疆 diff --git a/Assets/Scripts/UI/GuideUI.cs b/Assets/Scripts/UI/GuideUI.cs index 22c0d66..69c8f61 100644 --- a/Assets/Scripts/UI/GuideUI.cs +++ b/Assets/Scripts/UI/GuideUI.cs @@ -27,20 +27,20 @@ public class GuideUI : UIPanelBase private void OnEnable() { - EventManager.Instance.AddEventListener("PlayAnimation", PlayAnimation); - EventManager.Instance.AddEventListener("ActionSuccess", ShowSuccessEffect); - EventManager.Instance.AddEventListener("UpdateProgress", UpdateSuccessCount); - EventManager.Instance.AddEventListener("ActionFailed", ShowFailEffect); + EventManager.Instance.AddEventListener(YogaEventType.PlayAnimation, PlayAnimation); + EventManager.Instance.AddEventListener(YogaEventType.ActionSuccess, ShowSuccessEffect); + EventManager.Instance.AddEventListener(YogaEventType.UpdateProgress, UpdateSuccessCount); + EventManager.Instance.AddEventListener(YogaEventType.ActionFailed, ShowFailEffect); } private void OnDisable() { - EventManager.Instance.RemoveEventListener("PlayAnimation", PlayAnimation); - EventManager.Instance.RemoveEventListener("ActionSuccess", ShowSuccessEffect); - EventManager.Instance.RemoveEventListener("UpdateProgress", UpdateSuccessCount); - EventManager.Instance.RemoveEventListener("ActionFailed", ShowFailEffect); + EventManager.Instance.RemoveEventListener(YogaEventType.PlayAnimation, PlayAnimation); + EventManager.Instance.RemoveEventListener(YogaEventType.ActionSuccess, ShowSuccessEffect); + EventManager.Instance.RemoveEventListener(YogaEventType.UpdateProgress, UpdateSuccessCount); + EventManager.Instance.RemoveEventListener(YogaEventType.ActionFailed, ShowFailEffect); } #region Event Func @@ -54,28 +54,6 @@ public class GuideUI : UIPanelBase } GuideMgr.Play(Enum.GetName(typeof(AvatarAction), animeType)); - - //switch ((AvatarAction)animeType) - //{ - // case AvatarAction.HeadTurnLeft: - // GuideMgr.Play("HeadTurnLeft"); - // break; - // case AvatarAction.HeadTurnRight: - // GuideMgr.Play("HeadTurnRight"); - // break; - // case AvatarAction.HeadShake: - // GuideMgr.Play("HeadShake"); - // break; - // case AvatarAction.Nod: - // GuideMgr.Play("Nod"); - // break; - // case AvatarAction.HandsUp: - // GuideMgr.Play("HandsUp"); - // break; - // default: - // GuideMgr.Play("Idle"); - // break; - //} } private void UpdateSuccessCount(params object[] args) @@ -147,8 +125,8 @@ public class GuideUI : UIPanelBase { base.OnEnter(); _guide.SetActive(true); - EventManager.Instance.Dispatch("StartMotionCapture"); - EventManager.Instance.Dispatch("PlayAnimation", YogaManager.Instance.Action.Action); + EventManager.Instance.Dispatch(YogaEventType.StartMotionCapture); + EventManager.Instance.Dispatch(YogaEventType.PlayAnimation, YogaManager.Instance.Action.Action); } public override void OnExit() @@ -156,6 +134,6 @@ public class GuideUI : UIPanelBase base.OnExit(); _guide.SetActive(false); GuideMgr.Stop(); - EventManager.Instance.Dispatch("StopMotionCapture"); + EventManager.Instance.Dispatch(YogaEventType.StopMotionCapture); } }