Files
tcg-client/Assets/TcgEngine/Scripts/UI/IconBar.cs
xianyi f6262481dc 调整卡牌攻击
- 场上存在卡牌时无法直接攻击敌方玩家
- 取消卡牌攻击敌方玩家高亮显示
- 一回合只能上场一张角色卡
2025-08-06 11:35:29 +08:00

63 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace TcgEngine.UI
{
/// <summary>
/// Bar that contain multiple icons to represent a value
/// Such as the mana bar during the game
/// </summary>
public class IconBar : MonoBehaviour
{
public int value = 0;
public int max_value = 4;
public bool auto_refresh = true;
public Image[] icons;
public Sprite sprite_full;
public Sprite sprite_empty;
void Awake()
{
}
void Update()
{
if (auto_refresh)
Refresh();
}
public void Refresh()
{
if (icons == null)
return;
int index = 0;
foreach (Image icon in icons)
{
if (icon == null)
continue;
icon.gameObject.SetActive(index < value || index < max_value);
icon.sprite = (index < value) ? sprite_full : sprite_empty;
index++;
}
}
public void SetMat(Material mat)
{
if (icons == null)
return;
foreach (Image icon in icons)
{
if (icon != null)
icon.material = mat;
}
}
}
}