using DG.Tweening; using System.Collections; using System.Collections.Generic; using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; /// /// 手指动画类型 /// public enum E_HandAniKindType { /// /// 点击 /// Tap, /// /// 滑 /// Slide, /// /// 双击 /// DoubleClick, } /// /// 遮罩形状类型 /// public enum E_FocusType { /// /// 方形 /// Square, /// /// 圆形 /// Round, } /// /// 引导UI /// public class TeachUI : UIBaseClass { /// /// 遮罩形状 /// public Image focus; /// /// 点击事件 /// public Image tapEvent; /// /// 聚焦底图 /// public Image focusBM; /// /// 对话类容 /// public TextMeshProUGUI talkText; /// /// 带点按钮 /// public Button withDotsBtn; /// /// 聚焦RectTransform /// public RectTransform lookRect; /// /// 聚焦对象 /// public GameObject lookNode; /// /// 指引对象 /// public GameObject handNode; /// /// 指引动画 /// public Animator handAni; /// /// 对话对象 /// public GameObject talkObj; /// /// 上点 /// public Transform upPoint; /// /// 遮罩背景 /// public CanvasGroup maskBGCG; /// /// 引导提示 /// public CanvasGroup dialogueCG; /// /// 手指 /// public CanvasGroup guidelinesCG; public override void OnShow() { base.OnShow(); HideAll(); SetTapEvent(false); dialogueCG.alpha = 0; guidelinesCG.alpha = 0; maskBGCG.alpha = 0; } /// /// 设置聚焦 /// /// 位置 /// 大小 /// 点击事件 public void SetLookState(Vector3 pos, bool isUI,Vector2 size) { SetMaskBGCG(true); lookNode.gameObject.SetActive(true); if (isUI) { lookRect.position = pos; } else { bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent().transform as RectTransform, pos, UIManager.Instance.uICamera, out Vector2 localPoint); if (isRect) { lookRect.anchoredPosition = localPoint; } } lookRect.sizeDelta = new Vector2(1000, 1000); lookRect.DOKill(); lookRect.DOSizeDelta(size, 0.5f).SetUpdate(true); } /// /// 设置带点按钮 /// /// 位置 /// 大小 /// 点击事件 public void SetBtnState(Vector3 pos, Vector2 size, UnityAction unityAction) { withDotsBtn.gameObject.SetActive(true); withDotsBtn.transform.position = pos; (withDotsBtn.transform as RectTransform).sizeDelta = size; withDotsBtn.onClick.RemoveAllListeners(); withDotsBtn.onClick.AddListener(() => { unityAction?.Invoke(); }); } /// /// 设置对话 /// /// public void SetTalkText(string str) { SetDialogueCGCG(true); talkObj.gameObject.SetActive(true); talkObj.transform.position = upPoint.transform.position; talkText.text=str; talkText.transform.DOKill(); talkText.transform.localScale = Vector3.one; talkText.transform.DOScale(Vector3.one * 1.1f, 0.5f).SetLoops(-1, LoopType.Yoyo).SetUpdate(true); } /// /// 设置指引动画 /// /// 位置 /// 动画类型 public void SetHandState(Vector3 pos, E_HandAniKindType e_HandAniKind_Type) { SetGuidelinesCG(true); handNode.gameObject.SetActive(true); handNode.transform.position = pos; switch (e_HandAniKind_Type) { case E_HandAniKindType.Tap: handAni.Play("Tap"); break; case E_HandAniKindType.Slide: handAni.Play("Slide"); break; case E_HandAniKindType.DoubleClick: handAni.Play("DoubleClick"); break; } } /// /// 设置遮罩背景 /// public void SetMaskBGRay(bool isShow) { maskBGCG.blocksRaycasts = isShow; } public void SetFocus(E_FocusType e_FocusType) { switch (e_FocusType) { case E_FocusType.Square: focus.sprite = null; focusBM.sprite= YooAssetManager.Instance.LoadAssetSync(PackagesName.GameData, "Square"); break; case E_FocusType.Round: focus.sprite = YooAssetManager.Instance.LoadAssetSync(PackagesName.GameData, "NumberButton_Fill@2x"); focusBM.sprite = YooAssetManager.Instance.LoadAssetSync(PackagesName.GameData, "Handle_Outline"); break; } } public void SetGuidelinesCG(bool isShow) { if (isShow) { guidelinesCG.DOFade(1, 0.5f).SetUpdate(true).SetUpdate(true); } else { guidelinesCG.DOFade(0, 0.5f).SetUpdate(true).SetUpdate(true); } } public void SetDialogueCGCG(bool isShow) { if (isShow) { dialogueCG.DOFade(1, 0.5f).SetUpdate(true).SetUpdate(true); } else { dialogueCG.DOFade(0, 0.5f).SetUpdate(true).SetUpdate(true); } } public void SetTapEvent(bool isShow) { tapEvent.gameObject.SetActive(isShow); } public void SetMaskBGCG(bool isShow) { maskBGCG.DOKill(); if(isShow) { maskBGCG.DOFade(1, 0.5f).SetUpdate(true); } else { maskBGCG.DOFade(0, 0.5f).SetUpdate(true); } } /// /// 关闭所有 /// public void HideAll() { handNode.gameObject.SetActive(false); withDotsBtn.gameObject.SetActive(false); lookNode.gameObject.SetActive(false); talkObj.gameObject.SetActive(false); maskBGCG.alpha = 0; } }