2025-09-24 09:50:39 +08:00

73 lines
2.6 KiB
C#

using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using ZXKFramework;
namespace YiLiao.XinFeiTingZhen
{
public class ArrowPanel : UIBase
{
public override string GroupName => "ArrowPanel";
public override string Name => "ArrowPanel";
GameObject tip;
GameObject bg;
Text txt;
Button btn;
Coroutine coroutine;
Coroutine coroutine2;
public override void Init(IUIManager uictrl)
{
base.Init(uictrl);
txt = transform.FindFirst<Text>("指引文字");
tip = transform.FindFirst("文字提示");
bg = transform.FindFirst("黑色背景");
btn = transform.FindFirst<Button>("指引按钮");
}
public void ShowTip(string str,Vector2 v, bool mask, int delayShowTime, int duration, UnityAction action)
{
coroutine = Game.Instance.IEnumeratorManager.Run(delayShowTime, () => {
bg.SetActive(mask);
SetActive(true);
tip.SetActive(true);
tip.GetComponent<RectTransform>().anchoredPosition = v;
txt.text = str;
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(() => {
SetActive(false);
action?.Invoke();
});
coroutine2 = Game.Instance.IEnumeratorManager.Run(duration, () => {
SetActive(false);
action?.Invoke();
});
});
}
public void ShowTip(string str, Transform v, bool mask, int delayShowTime, int duration, UnityAction action)
{
coroutine = Game.Instance.IEnumeratorManager.Run(delayShowTime, () => {
bg.SetActive(mask);
SetActive(true);
tip.SetActive(true);
tip.transform.position = Camera.main.WorldToScreenPoint(v.position);
txt.text = str;
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(() => {
SetActive(false);
action?.Invoke();
});
coroutine2 = Game.Instance.IEnumeratorManager.Run(duration, () => {
SetActive(false);
action?.Invoke();
});
});
}
public override void Hide()
{
base.Hide();
Game.Instance.IEnumeratorManager.Stop(coroutine);
Game.Instance.IEnumeratorManager.Stop(coroutine2);
}
}
}