补充参战防御塔进入战斗逻辑
- 将 Inventory 中参战的防御塔数据传递到 CombatSelectForm 中 - 为防御塔的图标展示添加 TowerRepoItem 与 TowerIconArea 适配防御塔的三层 Image
This commit is contained in:
@@ -2,20 +2,23 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using GeometryTD.CustomEvent;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TowerSelectItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image _icon;
|
||||
|
||||
|
||||
[SerializeField] private TMP_Text _price;
|
||||
|
||||
|
||||
[SerializeField] private CommonButton _button;
|
||||
|
||||
|
||||
[SerializeField] private TowerIconArea _towerIconArea;
|
||||
|
||||
private TowerSelectItemContext _context;
|
||||
|
||||
private Sprite _defaultIcon;
|
||||
|
||||
private bool _hasCachedDefaultIcon;
|
||||
|
||||
public void OnInit(TowerSelectItemContext context)
|
||||
@@ -23,28 +26,45 @@ namespace GeometryTD.UI
|
||||
CacheDefaultIcon();
|
||||
_context = context;
|
||||
|
||||
if (_icon != null)
|
||||
if (context.ActionType == CombatSelectActionType.BuildTower)
|
||||
{
|
||||
if (context != null && context.Icon != null)
|
||||
_icon?.gameObject.SetActive(false);
|
||||
_towerIconArea?.OnInit(_context.TowerIconAreaContext);
|
||||
|
||||
if (_price != null)
|
||||
{
|
||||
_icon.sprite = context.Icon;
|
||||
}
|
||||
else if (_defaultIcon != null)
|
||||
{
|
||||
_icon.sprite = _defaultIcon;
|
||||
_price.text = context.PriceText ?? string.Empty;
|
||||
}
|
||||
|
||||
_icon.enabled = _icon.sprite != null;
|
||||
if (_button != null)
|
||||
{
|
||||
_button.Interactive = context.IsInteractable;
|
||||
}
|
||||
}
|
||||
|
||||
if (_price != null)
|
||||
else if (context.ActionType is CombatSelectActionType.UpgradeTower or CombatSelectActionType.DestroyTower)
|
||||
{
|
||||
_price.text = context?.PriceText ?? string.Empty;
|
||||
if (_icon != null)
|
||||
{
|
||||
_icon.sprite = _context.Icon ?? _defaultIcon;
|
||||
_icon.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
_towerIconArea?.OnReset();
|
||||
|
||||
if (_price != null)
|
||||
{
|
||||
_price.text = context.PriceText ?? string.Empty;
|
||||
}
|
||||
|
||||
if (_button != null)
|
||||
{
|
||||
_button.Interactive = context.IsInteractable;
|
||||
}
|
||||
}
|
||||
|
||||
if (_button != null)
|
||||
else
|
||||
{
|
||||
_button.Interactive = context != null && context.IsInteractable;
|
||||
_icon?.gameObject.SetActive(false);
|
||||
_towerIconArea?.OnReset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +79,8 @@ namespace GeometryTD.UI
|
||||
_icon.enabled = _icon.sprite != null;
|
||||
}
|
||||
|
||||
_towerIconArea.OnReset();
|
||||
|
||||
if (_price != null)
|
||||
{
|
||||
_price.text = string.Empty;
|
||||
@@ -93,4 +115,4 @@ namespace GeometryTD.UI
|
||||
_hasCachedDefaultIcon = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user