136 lines
4.0 KiB
C#
136 lines
4.0 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Vanguard.Battle;
|
|
|
|
namespace Vanguard.Board3D
|
|
{
|
|
/// <summary>
|
|
/// Единое управление красной attack-стрелкой и синими boost-стрелками.
|
|
/// Геометрия/анимация общая, различие — цвет и толщина.
|
|
/// </summary>
|
|
public sealed class ArrowDirector
|
|
{
|
|
private readonly Transform _parent;
|
|
private AnimationConfig _animation;
|
|
private ArrowConfig _config;
|
|
private AttackArrowView _attack;
|
|
private readonly List<AttackArrowView> _boosts =
|
|
new List<AttackArrowView>();
|
|
|
|
public ArrowDirector(
|
|
Transform parent,
|
|
AnimationConfig animation,
|
|
ArrowConfig config)
|
|
{
|
|
_parent = parent;
|
|
_animation = animation;
|
|
_config = config != null ? config : ArrowConfig.Default;
|
|
}
|
|
|
|
public bool AttackVisible =>
|
|
_attack != null && _attack.IsVisible;
|
|
|
|
public void SetConfig(AnimationConfig animation, ArrowConfig config)
|
|
{
|
|
_animation = animation;
|
|
_config = config != null ? config : ArrowConfig.Default;
|
|
if (_attack != null)
|
|
{
|
|
_attack.SetConfig(_animation);
|
|
_attack.SetStyle(
|
|
_config.attackColor,
|
|
_config.thickness,
|
|
_animation != null ? _animation.growDuration : _config.growDuration,
|
|
_config.fadeDuration,
|
|
_config.arcHeight);
|
|
}
|
|
}
|
|
|
|
public void SetAttack(Vector3 from, Vector3 to)
|
|
{
|
|
EnsureAttack();
|
|
_attack.Show(from, to);
|
|
_attack.SetPoints(from, to);
|
|
}
|
|
|
|
public void HideAttack()
|
|
{
|
|
_attack?.Hide();
|
|
}
|
|
|
|
public void SetBoosts(IReadOnlyList<(Vector3 From, Vector3 To)> boosts)
|
|
{
|
|
for (var i = 0; i < boosts.Count; i++)
|
|
{
|
|
var arrow = i < _boosts.Count
|
|
? _boosts[i]
|
|
: null;
|
|
if (arrow == null)
|
|
{
|
|
arrow = new AttackArrowView();
|
|
arrow.Build(_parent, _animation);
|
|
_boosts.Add(arrow);
|
|
}
|
|
|
|
arrow.SetStyle(
|
|
_config.boostColor,
|
|
_config.boostThickness,
|
|
_animation != null
|
|
? _animation.boostGrowDuration
|
|
: _config.growDuration,
|
|
_config.fadeDuration,
|
|
_config.arcHeight);
|
|
arrow.Show(boosts[i].From, boosts[i].To);
|
|
}
|
|
|
|
for (var i = boosts.Count; i < _boosts.Count; i++)
|
|
_boosts[i].Hide();
|
|
}
|
|
|
|
public void HideAll()
|
|
{
|
|
_attack?.Hide();
|
|
foreach (var arrow in _boosts)
|
|
arrow.Hide();
|
|
}
|
|
|
|
public void HideImmediate()
|
|
{
|
|
_attack?.HideImmediate();
|
|
foreach (var arrow in _boosts)
|
|
arrow.HideImmediate();
|
|
}
|
|
|
|
public void Tick(float deltaTime)
|
|
{
|
|
_attack?.Tick(deltaTime);
|
|
foreach (var arrow in _boosts)
|
|
arrow?.Tick(deltaTime);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_attack?.Dispose();
|
|
_attack = null;
|
|
foreach (var arrow in _boosts)
|
|
arrow?.Dispose();
|
|
_boosts.Clear();
|
|
}
|
|
|
|
private void EnsureAttack()
|
|
{
|
|
if (_attack != null)
|
|
return;
|
|
|
|
_attack = new AttackArrowView();
|
|
_attack.Build(_parent, _animation);
|
|
_attack.SetStyle(
|
|
_config.attackColor,
|
|
_config.thickness,
|
|
_animation != null ? _animation.growDuration : _config.growDuration,
|
|
_config.fadeDuration,
|
|
_config.arcHeight);
|
|
}
|
|
}
|
|
}
|