using UnityEngine;
|
|
public class GuildAtkDefBatTreasureGrid : MonoBehaviour
|
{
|
[SerializeField] ImageEx bdImage;
|
[SerializeField] ButtonEx clickButton;
|
[SerializeField] ImageEx topImage;
|
[SerializeField] TextEx topNumText;
|
[SerializeField] OutlineEx topNumOutline;
|
[SerializeField] UIEffectPlayer uiEffectPlayer;
|
|
[SerializeField] Color32 topGoldOddColor;
|
[SerializeField] Color32 topGoldEvenColor;
|
[SerializeField] Color32 topSilverOddColor;
|
[SerializeField] Color32 topSilverEvenColor;
|
|
[SerializeField] Color32 topGoldOddOutlineColor;
|
[SerializeField] Color32 topGoldEvenOutlineColor;
|
[SerializeField] Color32 topSilverOddOutlineColor;
|
[SerializeField] Color32 topSilverEvenOutlineColor;
|
|
[SerializeField] ImageEx qualityImage;
|
[SerializeField] TextEx numText;
|
[SerializeField] ImageEx itemImage;
|
[SerializeField] TextEx itemCntText;
|
[SerializeField] TextEx itemNameText;
|
|
private int gridIndex;
|
private bool isOpened;
|
private ushort awardID;
|
|
/// <summary>
|
/// 初始化格子
|
/// </summary>
|
/// <param name="index">格子序号 1~n</param>
|
/// <param name="isWin">是否胜利</param>
|
/// <param name="opened">是否已开启</param>
|
/// <param name="awardId">奖励ID(已开启时有效)</param>
|
/// <param name="playOpenAnim">是否播放开启动画(翻牌破碎特效)</param>
|
public void Init(int index, bool isWin, bool opened, ushort awardId, bool playOpenAnim = false)
|
{
|
gridIndex = index;
|
isOpened = opened;
|
awardID = awardId;
|
|
// 格子序号
|
topNumText.text = index.ToString();
|
numText.text = index.ToString();
|
|
// topImage按胜负/奇偶设置不同颜色和图片
|
bool isOdd = index % 2 == 1;
|
string topSpriteKey;
|
Color32 numColor;
|
Color32 outlineColor;
|
|
if (isWin)
|
{
|
topSpriteKey = isOdd ? "GuildAtkDefBatGridTopGoldOdd" : "GuildAtkDefBatGridTopGoldEven";
|
numColor = isOdd ? topGoldOddColor : topGoldEvenColor;
|
outlineColor = isOdd ? topGoldOddOutlineColor : topGoldEvenOutlineColor;
|
}
|
else
|
{
|
topSpriteKey = isOdd ? "GuildAtkDefBatGridTopSilverOdd" : "GuildAtkDefBatGridTopSilverEven";
|
numColor = isOdd ? topSilverOddColor : topSilverEvenColor;
|
outlineColor = isOdd ? topSilverOddOutlineColor : topSilverEvenOutlineColor;
|
}
|
bdImage.SetSprite(isWin ? "GuildAtkDefBatGridGoldBg" : "GuildAtkDefBatGridSilverBg");
|
topImage.SetSprite(topSpriteKey);
|
topNumText.color = numColor;
|
topNumOutline.OutlineColor = outlineColor;
|
|
clickButton.SetListener(OnClickGrid);
|
uiEffectPlayer.onComplete = null; // 清理回调,防止格子复用时残留
|
|
if (playOpenAnim)
|
PlayOpenEffect();
|
else
|
RefreshDisplay();
|
}
|
|
private void RefreshDisplay()
|
{
|
topImage.SetActive(!isOpened);
|
topNumText.SetActive(!isOpened);
|
|
qualityImage.SetActive(isOpened);
|
if (isOpened && awardID > 0)
|
{
|
var config = FamilyAtkDefBatTreasureConfig.Get(awardID);
|
if (config != null)
|
{
|
var itemConfig = ItemConfig.Get(config.ItemID);
|
if (itemConfig != null)
|
{
|
itemImage.SetItemSprite(config.ItemID);
|
itemCntText.text = config.ItemCount > 1 ? $"x{config.ItemCount}" : string.Empty;
|
itemNameText.text = itemConfig.ItemName;
|
}
|
|
qualityImage.SetSprite($"GuildAtkDefBatTreasureAwardColor{config.AwardColor}");
|
}
|
}
|
}
|
|
private void OnClickGrid()
|
{
|
if (isOpened)
|
{
|
if (awardID > 0)
|
{
|
var config = FamilyAtkDefBatTreasureConfig.Get(awardID);
|
if (config != null)
|
ItemTipUtility.Show(config.ItemID);
|
}
|
return;
|
}
|
|
var mgr = GuildAtkDefBatManager.Instance;
|
if (mgr.GetMyOpenRemainCount() <= 0)
|
{
|
SysNotifyMgr.Instance.ShowTip("GuildAtkDefBat4");
|
return;
|
}
|
|
mgr.SendOpenTreasure((byte)gridIndex);
|
}
|
|
/// <summary>
|
/// 播放开启动画(隐藏topImage,播放格子破碎特效)
|
/// </summary>
|
private void PlayOpenEffect()
|
{
|
topImage.SetActive(false);
|
topNumText.SetActive(false);
|
uiEffectPlayer.Play();
|
RefreshDisplay();
|
uiEffectPlayer.onComplete = OnOpenEffectComplete;
|
}
|
|
private void OnOpenEffectComplete()
|
{
|
uiEffectPlayer.onComplete = null; // 清除回调,防止重复调用
|
GuildAtkDefBatManager.Instance.ShowTreasureAward();
|
}
|
}
|