主页与Task任务处理

This commit is contained in:
YiHan0621
2025-09-12 11:39:17 +08:00
parent 2151631c59
commit 8506590b12
20 changed files with 579 additions and 60 deletions

View File

@@ -0,0 +1,52 @@
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);
}
}
}
}