主页与Task任务处理
This commit is contained in:
@@ -17,13 +17,13 @@ namespace TcgEngine.UI
|
||||
public Text progressBar_text;
|
||||
|
||||
public Button reward_button;
|
||||
public Image reward_icon;
|
||||
|
||||
public Image taskEnd_img;
|
||||
|
||||
private PlayerTask playerTask;
|
||||
private TaskData taskConfig;
|
||||
|
||||
public GameObject rewardItem;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
@@ -50,12 +50,25 @@ namespace TcgEngine.UI
|
||||
reward_button.interactable = task.status == TaskStatus.Completed;
|
||||
reward_button.onClick.RemoveAllListeners();
|
||||
reward_button.onClick.AddListener(OnClickReward);
|
||||
|
||||
// 奖品
|
||||
for (int i = 0; i < config.rewardTypes.Length; i++)
|
||||
{
|
||||
TaskRewardType rewardType = config.rewardTypes[i];
|
||||
int rewardNum = (config.rewardNums != null && i < config.rewardNums.Length)
|
||||
? config.rewardNums[i] : 1; // 没配数量就默认为1
|
||||
|
||||
GameObject go = Instantiate(rewardItem, reward_button.transform);
|
||||
var reward = go.GetComponent<TaskReward>();
|
||||
reward.SetPrize(rewardType, rewardNum, reward_button.interactable); // 改成传两个参数
|
||||
}
|
||||
|
||||
if (task.status == TaskStatus.Expired || task.status == TaskStatus.Claimed)
|
||||
{
|
||||
taskEnd_img.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
RefreshStatus();
|
||||
|
||||
}
|
||||
@@ -74,13 +87,5 @@ namespace TcgEngine.UI
|
||||
progressBar_slider.value = playerTask.progress;
|
||||
progressBar_text.text = playerTask.progress + "/" + taskConfig.value1;
|
||||
}
|
||||
|
||||
private void RewardColl(Sprite icon)
|
||||
{
|
||||
if (reward_icon != null)
|
||||
{
|
||||
reward_icon.sprite = icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/TcgEngine/Scripts/Tasks/TaskReward.cs.meta
Normal file
11
Assets/TcgEngine/Scripts/Tasks/TaskReward.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55af7dcd22f203d43b3ff26368c1ef5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user