Files
2026-05-26 16:15:54 +08:00

127 lines
4.1 KiB
C#

using GameCore;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
public class item_tips : MonoBehaviour
{
static item_tips _instance;
static bool isShowing = false;
public static async Task<item_tips> Show()
{
await ShowInit();
if (_instance == null)
{
return null;
}
_instance.transform.SetAsLastSibling();
return _instance;
}
private static async Task ShowInit()
{
if (!isShowing)
{
GameObject loading = await UIManager.Instance.GetUIAsync(UITypes.item_tips);
if (loading != null)
{
_instance = loading.GetComponent<item_tips>();
}
}
_instance.gameObject.SetActive(true);
}
Button btn_close;
RectTransform content;
public item_tips_fish_card item_fish_card;
public item_tips_box item_box;
public item_tips_box_2 item_box_2;
public item_tips_item item_tips_item;
public buff_tips buff_Tips;
public buff_tips buff_target;
public item_perk item_Perk;
//public int clickInstanceID { get; set; }
private void Awake()
{
btn_close = transform.Find("btn_close").GetComponent<Button>();
}
private void Start()
{
btn_close.onClick.AddListener(OnClickClose);
}
private void OnDestroy()
{
isShowing = false;
}
public void OnClickClose()
{
UIManager.Instance.HideUI(UITypes.item_tips);
}
public void Init(int clickInstanceID, Vector3 pos, cfg.Item item, double count)
{
buff_Tips.gameObject.SetActive(false);
buff_target.gameObject.SetActive(false);
item_fish_card.gameObject.SetActive(item.Type == 5);
item_box.gameObject.SetActive(item.Type == 9 && item.SubType == 2);
item_box_2.gameObject.SetActive(item.Type == 9 && (item.SubType == 1 || item.SubType == 3 || item.SubType == 7));
item_Perk.gameObject.SetActive(false);
item_tips_item.gameObject.SetActive(false);
if (item.Type == 5)
{
item_fish_card.Init(item);
content = item_fish_card.transform as RectTransform;
}
else if (item.Type == 9 && item.SubType == 2)
{
item_box.Show(item, count);
content = item_box.transform as RectTransform;
}
else if (item.Type == 9 && (item.SubType == 1 || item.SubType == 3 || item.SubType == 7))
{
item_box_2.Show(item, count);
content = item_box_2.transform as RectTransform;
}
else
{
item_tips_item.gameObject.SetActive(true);
item_tips_item.Init(item, count);
content = item_tips_item.transform as RectTransform;
}
SetContent(pos);
}
void SetContent(Vector3 pos)
{
content.position = pos;
RectTransform rectTransform = transform.GetComponent<RectTransform>();
//float limit = (rectTransform.rect.width - content.rect.width - 80) / 2;
//边界检测
var localPosition = content.transform.localPosition;
localPosition.x = 0;
float height = rectTransform.rect.height / 2;
if (localPosition.y < -height)
{
localPosition.y = -height;
}
else if (localPosition.y > height - 2 * content.rect.height)
{
localPosition.y = localPosition.y - content.rect.height;
}
content.transform.localPosition = localPosition;
}
public void ShowPerk(int rodID, int index, Vector3 pos, int addLevel = -1)
{
item_Perk.transform.position = pos;
item_Perk.transform.localPosition = new Vector3(0, item_Perk.transform.localPosition.y, 0);
item_fish_card.gameObject.SetActive(false);
item_box.gameObject.SetActive(false);
item_box_2.gameObject.SetActive(false);
item_tips_item.gameObject.SetActive(false);
buff_Tips.gameObject.SetActive(false);
buff_target.gameObject.SetActive(false);
item_Perk.gameObject.SetActive(true);
item_Perk.Show(rodID, index, addLevel);
}
}