162 lines
4.8 KiB
C#
162 lines
4.8 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class GuideUI : UIPanelBase
|
||
{
|
||
private GameObject _guide;
|
||
private Animator _effectAnimator;
|
||
private Transform _content;
|
||
|
||
public GudieAnimationManager GuideMgr => _guide.GetComponent<GudieAnimationManager>();
|
||
private void Awake()
|
||
{
|
||
_guide = GameObject.FindWithTag("Guide");
|
||
if (_guide == null)
|
||
{
|
||
Debug.LogError("Guide is null");
|
||
}
|
||
|
||
_effectAnimator = transform.Find("Content").GetComponentInChildren<Animator>();
|
||
_content = transform.Find("Content");
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
EventManager.Instance.AddEventListener("PlayAnimation", PlayAnimation);
|
||
EventManager.Instance.AddEventListener("ActionSuccess", ShowSuccessEffect);
|
||
EventManager.Instance.AddEventListener("UpdateProgress", UpdateSuccessCount);
|
||
EventManager.Instance.AddEventListener("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);
|
||
}
|
||
|
||
#region Event Func
|
||
private void PlayAnimation(params object[] args)
|
||
{
|
||
var animeType = args.FirstOrDefault();
|
||
if (animeType == null)
|
||
{
|
||
Debug.LogError("PlayAnimation animeType is null");
|
||
return;
|
||
}
|
||
|
||
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)
|
||
{
|
||
//args[0] = successCount args[1] = excutedCount args[2] = totalCount
|
||
if (args.Length < 3)
|
||
{
|
||
Debug.LogError("UpdateSuccessCount args is not enough");
|
||
return;
|
||
}
|
||
|
||
var successCount = (int)args[0];
|
||
var excutedCount = (int)args[1];
|
||
var totalCount = (int)args[2];
|
||
var totalProgress = (float)excutedCount / totalCount;
|
||
|
||
var radial = _content.Find("Radial");
|
||
var img = radial.Find("Background/Loading Bar").GetComponent<Image>();
|
||
if (img != null)
|
||
{
|
||
if (totalCount > excutedCount)
|
||
img.fillAmount = totalProgress;
|
||
else
|
||
img.fillAmount = 1;
|
||
}
|
||
var text = radial.Find("Text").GetComponent<TextMeshProUGUI>();
|
||
if (text != null)
|
||
{
|
||
if (totalCount > excutedCount)
|
||
text.text = $"{(int)(totalProgress * 100)}%";
|
||
else
|
||
text.text = "100%";
|
||
}
|
||
|
||
var successDisplay = _content.Find("SuccessDisplay");
|
||
var successText = successDisplay.Find("SuccessCount").GetComponent<TextMeshProUGUI>();
|
||
if (successText != null)
|
||
{
|
||
successText.text = successCount.ToString();
|
||
}
|
||
|
||
var totalText = successDisplay.Find("TotalCount").GetComponent<TextMeshProUGUI>();
|
||
if (totalText != null)
|
||
{
|
||
totalText.text = $"/ {totalCount}";
|
||
}
|
||
}
|
||
|
||
private void ShowFailEffect()
|
||
{
|
||
_effectAnimator.Play("WindowEffectError", 0, 0f);//<2F>߿<EFBFBD><DFBF><EFBFBD>˸
|
||
}
|
||
|
||
private void ShowSuccessEffect()
|
||
{
|
||
_effectAnimator.Play("WindowEffectCorrect", 0, 0f);//<2F>߿<EFBFBD><DFBF><EFBFBD>˸
|
||
}
|
||
#endregion
|
||
|
||
|
||
public override void Init(object[] pageData)
|
||
{
|
||
base.Init(pageData);
|
||
if (_guide == null)
|
||
_guide = GameObject.FindWithTag("Guide");
|
||
}
|
||
|
||
public override void OnEnter()
|
||
{
|
||
base.OnEnter();
|
||
_guide.SetActive(true);
|
||
EventManager.Instance.Dispatch("StartMotionCapture");
|
||
EventManager.Instance.Dispatch("PlayAnimation", YogaManager.Instance.Action.Action);
|
||
}
|
||
|
||
public override void OnExit()
|
||
{
|
||
base.OnExit();
|
||
_guide.SetActive(false);
|
||
GuideMgr.Stop();
|
||
EventManager.Instance.Dispatch("StopMotionCapture");
|
||
}
|
||
}
|