83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using System;
|
||
using TH1Resource;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TH1_Renderer.Prefab
|
||
{
|
||
public class BubbleMono : MonoBehaviour
|
||
{
|
||
// 普通气泡的Icon(Upgrade/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
|
||
};
|
||
|
||
}
|
||
}
|
||
}
|