231 lines
7.1 KiB
C#
231 lines
7.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Yoga;
|
|
|
|
public class GuideUI : UIPanelBase
|
|
{
|
|
private GameObject _guide;
|
|
private Animator _effectAnimator;
|
|
private Transform _content;
|
|
|
|
//计时进度条
|
|
private Image _progressBar;
|
|
private DateTime _startTime;
|
|
|
|
//面板显示数据
|
|
private TextMeshProUGUI _successText;
|
|
private TextMeshProUGUI _totalText;
|
|
private TextMeshProUGUI _kcalText;
|
|
|
|
public GudieAnimationManager GuideMgr => _guide.GetComponent<GudieAnimationManager>();
|
|
private void Awake()
|
|
{
|
|
_guide = GameObject.FindWithTag("Guide");
|
|
if (_guide == null)
|
|
{
|
|
LogPrint.Error("Guide is null");
|
|
}
|
|
|
|
_effectAnimator = transform.Find("Content").GetComponentInChildren<Animator>();
|
|
_content = transform.Find("Content");
|
|
_progressBar = _content.Find("Guide/ProgressBar/Background/ProgressBar").GetComponent<Image>();
|
|
|
|
var detailPanel = _content.Find("DetailPanel");
|
|
_successText = detailPanel.Find("SuccessCount").GetComponent<TextMeshProUGUI>();
|
|
_totalText = detailPanel.Find("TotalCount").GetComponent<TextMeshProUGUI>();
|
|
_kcalText = detailPanel.Find("KcalNum").GetComponent<TextMeshProUGUI>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
EventManager.Instance.AddEventListener(YogaEventType.PlayAnimation, PlayAnimation);
|
|
EventManager.Instance.AddEventListener(YogaEventType.Action_Success, ShowSuccessEffect);
|
|
EventManager.Instance.AddEventListener(YogaEventType.UpdateProgress, UpdateSuccessCount);
|
|
EventManager.Instance.AddEventListener(YogaEventType.Action_Fail, ShowFailEffect);
|
|
EventManager.Instance.AddEventListener(YogaEventType.DEBUG_CONSOLE_ChangeCamMode, ChangeCameraCaptureMode);
|
|
|
|
//倒计时音效
|
|
EventManager.Instance.AddEventListener(YogaEventType.Sound_CountDownAudio, PlayCountDownAudio);
|
|
EventManager.Instance.AddEventListener(YogaEventType.Sound_CountDownEndAudio, PlayCountDownEndAudio);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
EventManager.Instance.RemoveEventListener(YogaEventType.PlayAnimation, PlayAnimation);
|
|
EventManager.Instance.RemoveEventListener(YogaEventType.Action_Success, ShowSuccessEffect);
|
|
EventManager.Instance.RemoveEventListener(YogaEventType.UpdateProgress, UpdateSuccessCount);
|
|
EventManager.Instance.RemoveEventListener(YogaEventType.Action_Fail, ShowFailEffect);
|
|
EventManager.Instance.RemoveEventListener(YogaEventType.DEBUG_CONSOLE_ChangeCamMode, ChangeCameraCaptureMode);
|
|
|
|
//倒计时音效
|
|
EventManager.Instance.RemoveEventListener(YogaEventType.Sound_CountDownAudio, PlayCountDownAudio);
|
|
EventManager.Instance.RemoveEventListener(YogaEventType.Sound_CountDownEndAudio, PlayCountDownEndAudio);
|
|
}
|
|
|
|
#region Event Func
|
|
private void PlayAnimation(params object[] args)
|
|
{
|
|
var animeType = args.FirstOrDefault();
|
|
if (animeType == null)
|
|
{
|
|
LogPrint.Error("PlayAnimation animeType is null");
|
|
return;
|
|
}
|
|
|
|
if (animeType is List<AvatarAction>)
|
|
{
|
|
var actionList = animeType as List<AvatarAction>;
|
|
if (actionList == null)
|
|
{
|
|
LogPrint.Error("PlayAnimation actionList is null");
|
|
return;
|
|
}
|
|
|
|
GuideMgr.PlayCurrentActionList(actionList);
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void UpdateSuccessCount(params object[] args)
|
|
{
|
|
//args[0] = successCount args[1] = excutedCount args[2] = totalCount
|
|
if (args.Length < 3)
|
|
{
|
|
LogPrint.Error("UpdateSuccessCount args is not enough");
|
|
return;
|
|
}
|
|
|
|
var successCount = (int)args[0];
|
|
var excutedCount = (int)args[1];
|
|
|
|
if (_successText != null)
|
|
{
|
|
_successText.text = successCount.ToString();
|
|
}
|
|
|
|
if (_kcalText != null)
|
|
{
|
|
_kcalText.text = (successCount * 0.1f + (excutedCount - successCount) * 0.5f).ToString("F1");
|
|
}
|
|
}
|
|
|
|
private void ShowFailEffect()
|
|
{
|
|
_effectAnimator.Play("WindowEffectError", 0, 0f);//边框闪烁
|
|
}
|
|
|
|
private void ShowSuccessEffect()
|
|
{
|
|
_effectAnimator.Play("WindowEffectCorrect", 0, 0f);//边框闪烁
|
|
}
|
|
#endregion
|
|
|
|
|
|
public override void Init(object[] pageData)
|
|
{
|
|
base.Init(pageData);
|
|
if (_guide == null)
|
|
_guide = GameObject.FindWithTag("Guide");
|
|
|
|
if (pageData[0] == null)
|
|
{
|
|
LogPrint.Error("Guide is null");
|
|
return;
|
|
}
|
|
|
|
YogaData data = pageData[0] as YogaData;
|
|
|
|
//重置显示数据
|
|
if (_successText != null)
|
|
{
|
|
_successText.text = "0";
|
|
}
|
|
|
|
if (_totalText != null)
|
|
{
|
|
_totalText.text = data.MaxCheckPointCount.ToString();
|
|
}
|
|
|
|
if (_kcalText != null)
|
|
{
|
|
_kcalText.text = "0";
|
|
}
|
|
}
|
|
|
|
//播放倒计时音效
|
|
private void PlayCountDownAudio()
|
|
{
|
|
AudioManager.Instance.PlaySE("CountDown");
|
|
}
|
|
//播放开始音效
|
|
private void PlayCountDownEndAudio()
|
|
{
|
|
AudioManager.Instance.PlaySE("CountDownEnd");
|
|
}
|
|
|
|
//更新进度条
|
|
private void ProgressUpdate()
|
|
{
|
|
var passedTime = Math.Abs((_startTime - DateTime.Now).TotalSeconds);
|
|
_progressBar.fillAmount = (float)(passedTime / GuideMgr.AnimationLength);
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
base.OnEnter();
|
|
_guide.SetActive(true);
|
|
EventManager.Instance.Dispatch(YogaEventType.StartMotionCapture);
|
|
YogaManager.Instance.ActionIndex = 0;
|
|
EventManager.Instance.Dispatch(YogaEventType.PlayAnimation, YogaManager.Instance.LevelData.Actions);
|
|
_startTime = DateTime.Now;
|
|
InvokeRepeating("ProgressUpdate", 0, 0.1f); //20fps
|
|
}
|
|
|
|
public override void OnExit()
|
|
{
|
|
base.OnExit();
|
|
if (_guide != null)
|
|
_guide.SetActive(false);
|
|
GuideMgr.Stop();
|
|
EventManager.Instance.Dispatch(YogaEventType.StopMotionCapture);
|
|
}
|
|
|
|
private void ChangeCameraCaptureMode()
|
|
{
|
|
Transform webCam = _content.Find("WebCameraCaptureManager");
|
|
Transform usbCam = _content.Find("USBCameraCaptureManager");
|
|
CaptureManagerBase manager;
|
|
if (webCam == null || usbCam == null)
|
|
{
|
|
LogPrint.Error("ChangeCameraCaptureMode webCam or usbCam is null");
|
|
return;
|
|
}
|
|
if (webCam.gameObject.activeSelf)
|
|
{
|
|
webCam.gameObject.SetActive(false);
|
|
usbCam.gameObject.SetActive(true);
|
|
manager = usbCam.GetComponent<MotionUSBCameraCaptureManager>();
|
|
}
|
|
else
|
|
{
|
|
webCam.gameObject.SetActive(true);
|
|
usbCam.gameObject.SetActive(false);
|
|
manager = webCam.GetComponent<MotionWebCaptureManager>();
|
|
}
|
|
manager.Init();
|
|
manager.IsOnCamCapture = true;
|
|
CVEstimator.Instance.StartEstimation();
|
|
}
|
|
|
|
public void OnBackClicked()
|
|
{
|
|
UIManager.Instance.CloseCurrent();
|
|
LoadingManager.Instance.Load("Boot");
|
|
}
|
|
}
|