补充参战防御塔进入战斗逻辑
- 将 Inventory 中参战的防御塔数据传递到 CombatSelectForm 中 - 为防御塔的图标展示添加 TowerRepoItem 与 TowerIconArea 适配防御塔的三层 Image
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -14,15 +13,17 @@ namespace GeometryTD.UI
|
||||
|
||||
private IconAreaContext _context;
|
||||
|
||||
public Sprite CurrentIconSprite => _icon != null ? _icon.sprite : null;
|
||||
public virtual Sprite CurrentIconSprite => _icon != null ? _icon.sprite : null;
|
||||
|
||||
public Color CurrentIconColor => _icon != null ? _icon.color : Color.white;
|
||||
public virtual Color CurrentIconColor => _icon != null ? _icon.color : Color.white;
|
||||
|
||||
public Vector2 CurrentIconSize => _icon != null ? _icon.rectTransform.rect.size : Vector2.zero;
|
||||
public virtual Vector2 CurrentIconSize => _icon != null ? _icon.rectTransform.rect.size : Vector2.zero;
|
||||
|
||||
public Material CurrentIconMaterial => _icon != null ? _icon.material : null;
|
||||
public virtual Material CurrentIconMaterial => _icon != null ? _icon.material : null;
|
||||
|
||||
public void OnInit(IconAreaContext context)
|
||||
public virtual RectTransform IconRectTransform => _icon != null ? _icon.rectTransform : null;
|
||||
|
||||
public virtual void OnInit(IconAreaContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
@@ -46,9 +47,10 @@ namespace GeometryTD.UI
|
||||
|
||||
SetRarity(_context.Rarity);
|
||||
SetIconColor(_context.Color);
|
||||
SetIconVisible(true);
|
||||
}
|
||||
|
||||
public void SetIcon(Sprite sprite)
|
||||
public virtual void SetIcon(Sprite sprite)
|
||||
{
|
||||
if (_icon != null)
|
||||
{
|
||||
@@ -56,7 +58,7 @@ namespace GeometryTD.UI
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRarity(RarityType rarity)
|
||||
public virtual void SetRarity(RarityType rarity)
|
||||
{
|
||||
if (_board == null)
|
||||
{
|
||||
@@ -74,7 +76,7 @@ namespace GeometryTD.UI
|
||||
};
|
||||
}
|
||||
|
||||
public void SetIconColor(Color color)
|
||||
public virtual void SetIconColor(Color color)
|
||||
{
|
||||
if (_icon == null)
|
||||
{
|
||||
@@ -84,11 +86,20 @@ namespace GeometryTD.UI
|
||||
_icon.color = color;
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
public virtual void SetIconVisible(bool visible)
|
||||
{
|
||||
if (_icon != null)
|
||||
{
|
||||
_icon.enabled = visible;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnReset()
|
||||
{
|
||||
SetIcon(null);
|
||||
SetRarity(RarityType.None);
|
||||
SetIconColor(Color.clear);
|
||||
SetIconVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TowerIconArea : IconArea
|
||||
{
|
||||
[SerializeField] private Image _baseIcon;
|
||||
|
||||
[SerializeField] private Image _bearingIcon;
|
||||
|
||||
[SerializeField] private Image _muzzleIcon;
|
||||
|
||||
public Sprite BaseIconSprite => _baseIcon != null ? _baseIcon.sprite : null;
|
||||
|
||||
public Sprite BearingIconSprite => _bearingIcon != null ? _bearingIcon.sprite : null;
|
||||
|
||||
public Sprite MuzzleIconSprite => _muzzleIcon != null ? _muzzleIcon.sprite : null;
|
||||
|
||||
public Color BaseIconColor => _baseIcon != null ? _baseIcon.color : Color.white;
|
||||
|
||||
public Color BearingIconColor => _bearingIcon != null ? _bearingIcon.color : Color.white;
|
||||
|
||||
public Color MuzzleIconColor => _muzzleIcon != null ? _muzzleIcon.color : Color.white;
|
||||
|
||||
public Material BaseIconMaterial => _baseIcon != null ? _baseIcon.material : null;
|
||||
|
||||
public Material BearingIconMaterial => _bearingIcon != null ? _bearingIcon.material : null;
|
||||
|
||||
public Material MuzzleIconMaterial => _muzzleIcon != null ? _muzzleIcon.material : null;
|
||||
|
||||
public override void OnInit(IconAreaContext context)
|
||||
{
|
||||
if (!(context is TowerIconAreaContext towerContext))
|
||||
{
|
||||
base.OnInit(context);
|
||||
return;
|
||||
}
|
||||
|
||||
SetRarity(towerContext.Rarity);
|
||||
SetIconVisible(false);
|
||||
|
||||
SetLayerColor(_baseIcon, towerContext.BaseColor);
|
||||
SetLayerColor(_bearingIcon, towerContext.BearingColor);
|
||||
SetLayerColor(_muzzleIcon, towerContext.MuzzleColor);
|
||||
}
|
||||
|
||||
public void OnInit(TowerIconAreaContext context)
|
||||
{
|
||||
OnInit((IconAreaContext)context);
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
base.OnReset();
|
||||
SetLayerColor(_baseIcon, Color.clear);
|
||||
SetLayerColor(_bearingIcon, Color.clear);
|
||||
SetLayerColor(_muzzleIcon, Color.clear);
|
||||
SetIconVisible(false);
|
||||
}
|
||||
|
||||
private static void SetLayerColor(Image icon, Color color)
|
||||
{
|
||||
if (icon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
icon.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33a1436bff53c844e858f3bced1565ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user