Files
tcg-client/Assets/TcgEngine/Scripts/Tasks/TaskReward.cs
2025-09-12 11:39:17 +08:00

52 lines
1.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 UnityEngine;
using UnityEngine.UI;
namespace TcgEngine.UI
{
public class TaskReward : MonoBehaviour
{
public TaskRewardData database; // 存放所有奖励图标的 ScriptableObject
public Image rewardIcon; // 图标 Image
public Text amountText; // 数量文本
public float fixedHeight = 80f; // 固定高度
private RectTransform rect;
public void SetPrize(TaskRewardType type, int amount,bool isVis)
{
if (!isVis)
{
rewardIcon.color = Color.gray;
amountText.color = Color.gray;
}
else
{
rewardIcon.color = Color.white;
amountText.color = Color.white;
}
// 图标
Sprite sprite = database.GetIcon(type);
rewardIcon.sprite = sprite;
// 数量
if (amountText != null)
{
amountText.text = amount > 1 ? "x" + amount.ToString() : "";
}
// 高度固定80等比例缩放
if (sprite != null)
{
float ratio = sprite.rect.width / sprite.rect.height;
rect = rewardIcon.GetComponent<RectTransform>();
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, fixedHeight);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, fixedHeight * ratio);
}
}
}
}