291 lines
7.0 KiB
C#
291 lines
7.0 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 手指动画类型
|
|
/// </summary>
|
|
public enum E_HandAniKindType
|
|
{
|
|
/// <summary>
|
|
/// 点击
|
|
/// </summary>
|
|
Tap,
|
|
/// <summary>
|
|
/// 滑
|
|
/// </summary>
|
|
Slide,
|
|
/// <summary>
|
|
/// 双击
|
|
/// </summary>
|
|
DoubleClick,
|
|
}
|
|
/// <summary>
|
|
/// 遮罩形状类型
|
|
/// </summary>
|
|
public enum E_FocusType
|
|
{
|
|
/// <summary>
|
|
/// 方形
|
|
/// </summary>
|
|
Square,
|
|
/// <summary>
|
|
/// 圆形
|
|
/// </summary>
|
|
Round,
|
|
}
|
|
|
|
/// <summary>
|
|
/// 引导UI
|
|
/// </summary>
|
|
public class TeachUI : UIBaseClass
|
|
{
|
|
/// <summary>
|
|
/// 遮罩形状
|
|
/// </summary>
|
|
public Image focus;
|
|
|
|
/// <summary>
|
|
/// 点击事件
|
|
/// </summary>
|
|
public Image tapEvent;
|
|
|
|
/// <summary>
|
|
/// 聚焦底图
|
|
/// </summary>
|
|
public Image focusBM;
|
|
|
|
/// <summary>
|
|
/// 对话类容
|
|
/// </summary>
|
|
public TextMeshProUGUI talkText;
|
|
|
|
/// <summary>
|
|
/// 带点按钮
|
|
/// </summary>
|
|
public Button withDotsBtn;
|
|
|
|
/// <summary>
|
|
/// 聚焦RectTransform
|
|
/// </summary>
|
|
public RectTransform lookRect;
|
|
|
|
/// <summary>
|
|
/// 聚焦对象
|
|
/// </summary>
|
|
public GameObject lookNode;
|
|
|
|
/// <summary>
|
|
/// 指引对象
|
|
/// </summary>
|
|
public GameObject handNode;
|
|
|
|
/// <summary>
|
|
/// 指引动画
|
|
/// </summary>
|
|
public Animator handAni;
|
|
|
|
/// <summary>
|
|
/// 对话对象
|
|
/// </summary>
|
|
public GameObject talkObj;
|
|
|
|
/// <summary>
|
|
/// 上点
|
|
/// </summary>
|
|
public Transform upPoint;
|
|
|
|
/// <summary>
|
|
/// 遮罩背景
|
|
/// </summary>
|
|
public CanvasGroup maskBGCG;
|
|
|
|
/// <summary>
|
|
/// 引导提示
|
|
/// </summary>
|
|
public CanvasGroup dialogueCG;
|
|
|
|
/// <summary>
|
|
/// 手指
|
|
/// </summary>
|
|
public CanvasGroup guidelinesCG;
|
|
|
|
public override void OnShow()
|
|
{
|
|
base.OnShow();
|
|
HideAll();
|
|
SetTapEvent(false);
|
|
dialogueCG.alpha = 0;
|
|
guidelinesCG.alpha = 0;
|
|
maskBGCG.alpha = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置聚焦
|
|
/// </summary>
|
|
/// <param name="pos">位置</param>
|
|
/// <param name="size">大小</param>
|
|
/// <param name="unityAction">点击事件</param>
|
|
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<Canvas>().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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置带点按钮
|
|
/// </summary>
|
|
/// <param name="pos">位置</param>
|
|
/// <param name="size">大小</param>
|
|
/// <param name="unityAction">点击事件</param>
|
|
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();
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置对话
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置指引动画
|
|
/// </summary>
|
|
/// <param name="pos">位置</param>
|
|
/// <param name="kind">动画类型</param>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置遮罩背景
|
|
/// </summary>
|
|
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<Sprite>(PackagesName.GameData, "Square");
|
|
break;
|
|
case E_FocusType.Round:
|
|
focus.sprite = YooAssetManager.Instance.LoadAssetSync<Sprite>(PackagesName.GameData, "NumberButton_Fill@2x");
|
|
focusBM.sprite = YooAssetManager.Instance.LoadAssetSync<Sprite>(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);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 关闭所有
|
|
/// </summary>
|
|
public void HideAll()
|
|
{
|
|
handNode.gameObject.SetActive(false);
|
|
withDotsBtn.gameObject.SetActive(false);
|
|
lookNode.gameObject.SetActive(false);
|
|
talkObj.gameObject.SetActive(false);
|
|
maskBGCG.alpha = 0;
|
|
}
|
|
}
|