Health/Assets/Scripts/YogaManager.cs

85 lines
2.8 KiB
C#
Raw Normal View History

2023-11-07 13:55:35 +00:00
using NUnit.Framework.Internal;
using OpenCVForUnity.CoreModule;
using OpenCVForUnity.DnnModule;
using OpenCVForUnity.UnityUtils;
using OpenCVForUnity.UnityUtils.Helper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using UnityEngine;
public class YogaManager : MonoSingleton<YogaManager>
{
private List<Point> _points = new List<Point>();
public List<Point> Points { get => _points; private set => _points = value; }
2023-11-07 16:51:42 +00:00
private int _currentActionCount; //当前动作计数
2023-11-07 17:51:34 +00:00
public int CurrentActionCount { get => _currentActionCount;}
2023-11-07 16:51:42 +00:00
private int _currentSuccessActionCount; //当前成功动作计数
2023-11-07 17:51:34 +00:00
public int CurrentSuccessActionCount { get => _currentSuccessActionCount; }
private int _maxActionCount = 0;
public int MaxActionCount { get => _maxActionCount; }
2023-11-07 16:51:42 +00:00
private int _actionIndex; //用户选择界面选择的动作索引
public int ActionIndex { get => _actionIndex; internal set => _actionIndex = value; }
private Dictionary<AvatarAction, PoseBase> _actions = new Dictionary<AvatarAction, PoseBase>();
2023-11-07 13:55:35 +00:00
2023-11-07 15:28:19 +00:00
public void InitData()
2023-11-07 13:55:35 +00:00
{
2023-11-07 16:51:42 +00:00
_actions[AvatarAction.HeadTurnLeft] = new HeadTurnLeft();
_actions[AvatarAction.HeadTurnRight] = new HeadTurnRight();
2023-11-07 13:55:35 +00:00
2023-11-07 15:28:19 +00:00
_currentActionCount = 0;
_currentSuccessActionCount = 0;
2023-11-07 17:51:34 +00:00
_maxActionCount = 3;
EventManager.Instance.Dispatch("UpdateProgress", CurrentSuccessActionCount, CurrentActionCount, MaxActionCount);
2023-11-07 13:55:35 +00:00
}
2023-11-07 17:51:34 +00:00
private void OnEnable()
{
EventManager.Instance.AddEventListener("ActionSuccess", OnActionSuccess);
EventManager.Instance.AddEventListener("ActionFailed", OnActionFailed);
}
private void OnDisable()
{
EventManager.Instance.RemoveEventListener("ActionSuccess", OnActionSuccess);
EventManager.Instance.RemoveEventListener("ActionFailed", OnActionFailed);
}
private void OnActionSuccess()
{
_currentSuccessActionCount++;
_currentActionCount++;
//args[0] = successCount args[1] = excutedCount args[2] = totalCount
EventManager.Instance.Dispatch("UpdateProgress", CurrentSuccessActionCount, CurrentActionCount, MaxActionCount);
}
private void OnActionFailed()
{
_currentActionCount++;
EventManager.Instance.Dispatch("UpdateProgress", CurrentSuccessActionCount, CurrentActionCount, MaxActionCount);
}
2023-11-07 16:51:42 +00:00
public bool IsCorrectAction(List<Point> personPoints, AvatarAction actionType)
2023-11-07 13:55:35 +00:00
{
2023-11-07 16:51:42 +00:00
if (!_actions.ContainsKey(actionType))
2023-11-07 13:55:35 +00:00
{
2023-11-07 16:51:42 +00:00
Debug.LogError("ActionType is not exist");
return false;
2023-11-07 13:55:35 +00:00
}
2023-11-07 16:51:42 +00:00
var result = _actions[actionType].CheckPose(personPoints);
Debug.LogWarning("ActionType: " + actionType + " result: " + result);
return result;
2023-11-07 13:55:35 +00:00
}
}