主页与Task任务处理
This commit is contained in:
52
Assets/TcgEngine/Scripts/Tasks/TaskReward.cs
Normal file
52
Assets/TcgEngine/Scripts/Tasks/TaskReward.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user