补充参战防御塔进入战斗逻辑
- 将 Inventory 中参战的防御塔数据传递到 CombatSelectForm 中 - 为防御塔的图标展示添加 TowerRepoItem 与 TowerIconArea 适配防御塔的三层 Image
This commit is contained in:
@@ -7,8 +7,11 @@ namespace Components
|
||||
public class BasicBaseComp : MonoBehaviour
|
||||
{
|
||||
[SerializeField] [Min(0.01f)] private float _attackSpeed = 1f;
|
||||
|
||||
[SerializeField] private AttackPropertyType _attackPropertyType = AttackPropertyType.Physics;
|
||||
|
||||
[SerializeField] private SpriteRenderer _renderer;
|
||||
|
||||
private float _cooldownRemaining;
|
||||
|
||||
public float AttackSpeed => _attackSpeed;
|
||||
@@ -29,6 +32,14 @@ namespace Components
|
||||
_cooldownRemaining = 0f;
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (_renderer != null)
|
||||
{
|
||||
_renderer.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(float deltaTime)
|
||||
{
|
||||
if (_cooldownRemaining <= 0f)
|
||||
|
||||
@@ -6,10 +6,15 @@ namespace Components
|
||||
public class BasicBearingComp : MonoBehaviour
|
||||
{
|
||||
[SerializeField] [Min(1f)] private float _rotateSpeed = 180f;
|
||||
|
||||
[SerializeField] [Min(0.1f)] private float _attackRange = 5f;
|
||||
|
||||
[SerializeField] [Min(0.1f)] private float _aimToleranceAngle = 2f;
|
||||
|
||||
[SerializeField] private Transform _rotateRoot;
|
||||
|
||||
[SerializeField] private SpriteRenderer _renderer;
|
||||
|
||||
public float RotateSpeed => _rotateSpeed;
|
||||
public float AttackRange => _attackRange;
|
||||
public float AimToleranceAngle => _aimToleranceAngle;
|
||||
@@ -26,6 +31,14 @@ namespace Components
|
||||
_attackRange = 5f;
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (_renderer != null)
|
||||
{
|
||||
_renderer.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTargetInRange(Transform target, Transform origin = null)
|
||||
{
|
||||
if (target == null)
|
||||
|
||||
@@ -9,11 +9,17 @@ namespace Components
|
||||
public class ShooterMuzzleComp : MonoBehaviour
|
||||
{
|
||||
[SerializeField] [Min(1f)] private int _attackDamage = 100;
|
||||
|
||||
[SerializeField] private AttackMethodType _attackMethodType = AttackMethodType.NormalBullet;
|
||||
|
||||
[SerializeField] [Min(1)] private int _bulletTypeId = 501;
|
||||
|
||||
[SerializeField] private Transform _muzzlePoint;
|
||||
|
||||
[SerializeField] [Min(0.1f)] private float _bulletSpeed = 12f;
|
||||
|
||||
[SerializeField] private SpriteRenderer _renderer;
|
||||
|
||||
public int AttackDamage => _attackDamage;
|
||||
public AttackMethodType AttackMethodType => _attackMethodType;
|
||||
|
||||
@@ -31,6 +37,14 @@ namespace Components
|
||||
_bulletTypeId = 501;
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (_renderer != null)
|
||||
{
|
||||
_renderer.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Attack(Transform target)
|
||||
{
|
||||
return Attack(target, AttackPropertyType.None);
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Components
|
||||
private const string AttackRangeIndicatorObjectName = "AttackRangeIndicator";
|
||||
private const int MinTowerLevel = 0;
|
||||
private const int MaxTowerLevel = 4;
|
||||
private static Material s_AttackRangeSharedMaterial;
|
||||
|
||||
private static Material _attackRangeSharedMaterial;
|
||||
|
||||
[SerializeField] private ShooterMuzzleComp _muzzleComp;
|
||||
[SerializeField] private BasicBearingComp _bearingComp;
|
||||
@@ -27,6 +28,9 @@ namespace Components
|
||||
private float _retargetTimer;
|
||||
private float _attackRange;
|
||||
private int _towerLevel;
|
||||
private Color _muzzleColor = Color.white;
|
||||
private Color _bearingColor = Color.white;
|
||||
private Color _baseColor = Color.white;
|
||||
|
||||
public Transform CurrentTarget => _currentTarget;
|
||||
|
||||
@@ -40,6 +44,12 @@ namespace Components
|
||||
OnInit(stats, MinTowerLevel);
|
||||
}
|
||||
|
||||
public void OnInit(TowerStatsData stats, int towerLevel, Color muzzleColor, Color bearingColor, Color baseColor)
|
||||
{
|
||||
SetComponentColors(muzzleColor, bearingColor, baseColor);
|
||||
OnInit(stats, towerLevel);
|
||||
}
|
||||
|
||||
public void OnInit(TowerStatsData stats, int towerLevel)
|
||||
{
|
||||
ResolveComponents();
|
||||
@@ -57,6 +67,7 @@ namespace Components
|
||||
_muzzleComp?.OnInit(attackDamage, stats.AttackMethodType);
|
||||
_bearingComp?.OnInit(rotateSpeed, attackRange);
|
||||
_baseComp?.OnInit(attackSpeed, stats.AttackPropertyType);
|
||||
ApplyComponentColors();
|
||||
SetAttackRange(attackRange);
|
||||
SetAttackRangeVisible(false);
|
||||
_currentTarget = null;
|
||||
@@ -90,6 +101,14 @@ namespace Components
|
||||
RebuildAttackRangeGeometry();
|
||||
}
|
||||
|
||||
public void SetComponentColors(Color muzzleColor, Color bearingColor, Color baseColor)
|
||||
{
|
||||
_muzzleColor = muzzleColor;
|
||||
_bearingColor = bearingColor;
|
||||
_baseColor = baseColor;
|
||||
ApplyComponentColors();
|
||||
}
|
||||
|
||||
public void SetTarget(Transform target)
|
||||
{
|
||||
_currentTarget = target;
|
||||
@@ -141,9 +160,9 @@ namespace Components
|
||||
|
||||
EnemyEntity bestEnemy = null;
|
||||
float bestDistanceSquared = float.MaxValue;
|
||||
for (int i = 0; i < EnemyEntity.ActiveEnemies.Count; i++)
|
||||
|
||||
foreach (var enemy in EnemyEntity.ActiveEnemies)
|
||||
{
|
||||
EnemyEntity enemy = EnemyEntity.ActiveEnemies[i];
|
||||
if (enemy == null || !enemy.isActiveAndEnabled)
|
||||
{
|
||||
continue;
|
||||
@@ -164,6 +183,13 @@ namespace Components
|
||||
return bestEnemy != null ? bestEnemy.transform : null;
|
||||
}
|
||||
|
||||
private void ApplyComponentColors()
|
||||
{
|
||||
_muzzleComp?.SetColor(_muzzleColor);
|
||||
_bearingComp?.SetColor(_bearingColor);
|
||||
_baseComp?.SetColor(_baseColor);
|
||||
}
|
||||
|
||||
private void ResolveComponents()
|
||||
{
|
||||
if (_muzzleComp == null)
|
||||
@@ -181,6 +207,7 @@ namespace Components
|
||||
_baseComp = GetComponent<BasicBaseComp>();
|
||||
}
|
||||
|
||||
ApplyComponentColors();
|
||||
EnsureAttackRangeRenderer();
|
||||
}
|
||||
|
||||
@@ -250,18 +277,18 @@ namespace Components
|
||||
_attackRangeRenderer.allowOcclusionWhenDynamic = false;
|
||||
_attackRangeRenderer.enabled = false;
|
||||
|
||||
if (s_AttackRangeSharedMaterial == null)
|
||||
if (_attackRangeSharedMaterial == null)
|
||||
{
|
||||
Shader lineShader = Shader.Find("Sprites/Default");
|
||||
if (lineShader != null)
|
||||
{
|
||||
s_AttackRangeSharedMaterial = new Material(lineShader);
|
||||
_attackRangeSharedMaterial = new Material(lineShader);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_AttackRangeSharedMaterial != null)
|
||||
if (_attackRangeSharedMaterial != null)
|
||||
{
|
||||
_attackRangeRenderer.sharedMaterial = s_AttackRangeSharedMaterial;
|
||||
_attackRangeRenderer.sharedMaterial = _attackRangeSharedMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user