2026-04-21 22:21:01 +08:00

83 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using TH1Resource;
using UnityEngine;
using UnityEngine.UI;
namespace TH1_Renderer.Prefab
{
public class BubbleMono : MonoBehaviour
{
// 普通气泡的IconUpgrade/Capture等- 原有字段保持prefab兼容性
public Image img;
// 英雄选择气泡的特殊显示
public GameObject HeroIconMask;
public Image HeroIcon;
public Image BG;
public Button btn;
public Sprite BubbleRed;
public Sprite BubbleGreen;
public Sprite BubbleYellow;
public Sprite CaptureIcon;
public Sprite RecoverIcon;
public Sprite GatherIcon;
public Sprite ExamineIcon;
public Sprite UpgradeIcon;
public void SetContent(BubbleType type, Action onClick, Sprite customSprite = null)
{
btn?.onClick.RemoveAllListeners();
btn?.onClick.AddListener(onClick.Invoke);
if (type == BubbleType.HeroSelect)
{
// 英雄选择气泡显示HeroIconMask和HeroIcon隐藏普通icon
if (img != null)
img.gameObject.SetActive(false);
if (HeroIconMask != null)
HeroIconMask.SetActive(true);
if (HeroIcon != null)
{
HeroIcon.gameObject.SetActive(true);
HeroIcon.sprite = customSprite;
}
}
else
{
// 普通气泡显示普通Icon隐藏HeroIcon相关
if (img != null)
{
img.gameObject.SetActive(true);
img.sprite = type switch
{
BubbleType.Capture => CaptureIcon,
BubbleType.Examine => ExamineIcon,
BubbleType.Gather => GatherIcon,
_ => UpgradeIcon
};
}
if (HeroIconMask != null)
HeroIconMask.SetActive(false);
if (HeroIcon != null)
HeroIcon.gameObject.SetActive(false);
}
if (BG != null)
BG.sprite = type switch
{
BubbleType.Capture => BubbleRed,
BubbleType.Examine => BubbleYellow,
BubbleType.Gather => BubbleYellow,
_ => BubbleGreen
};
}
}
}