Merge branch 'fireball-vfx'
This commit is contained in:
commit
826d7b5037
12 changed files with 3121 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
|||
// Assets/_Project/Scripts/Gameplay/BuilderSpells/FireballSpellDefinition.cs
|
||||
using UnityEngine;
|
||||
using TD.Audio;
|
||||
using TD.Core;
|
||||
|
||||
namespace TD.Gameplay.BuilderSpells
|
||||
|
|
@ -10,7 +11,7 @@ namespace TD.Gameplay.BuilderSpells
|
|||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="BuilderSpellDefinition.TargetType"/> is <see cref="SpellTargetType.PointTarget"/>
|
||||
/// — the cast controller shows only a fixed-size reticle, even though
|
||||
/// — the cast controller shows only a fixed-size reticule, even though
|
||||
/// <see cref="BuilderSpellDefinition.Radius"/> is still used internally here as the splash
|
||||
/// radius (0 = no splash, direct hit only).
|
||||
/// </remarks>
|
||||
|
|
@ -19,6 +20,20 @@ namespace TD.Gameplay.BuilderSpells
|
|||
{
|
||||
public override BuilderSpellKind Kind => BuilderSpellKind.Fireball;
|
||||
|
||||
[Header("Impact VFX")]
|
||||
[Tooltip("Prefab spawned at the target point on a successful cast. Optional — leave empty for no visual.")]
|
||||
[SerializeField] private GameObject impactVfxPrefab;
|
||||
|
||||
[Tooltip("Seconds before the spawned VFX instance is destroyed.")]
|
||||
[Min(0f)]
|
||||
[SerializeField] private float impactVfxLifetime = 2f;
|
||||
|
||||
[Header("Impact Sound")]
|
||||
[Tooltip("Sound played on every peer when this spell resolves successfully. Same " +
|
||||
"SoundConfig struct TowerBuiltSound uses — reuse a tower's clip directly if " +
|
||||
"you want the same sound.")]
|
||||
[SerializeField] private SoundConfig impactSound;
|
||||
|
||||
[Header("Fireball")]
|
||||
[Tooltip("Damage dealt to every enemy within Radius of the target point.")]
|
||||
[Min(0f)]
|
||||
|
|
@ -43,5 +58,15 @@ namespace TD.Gameplay.BuilderSpells
|
|||
|
||||
return hitAny;
|
||||
}
|
||||
|
||||
public override void ClientPlayVfx(Vector3 targetPoint)
|
||||
{
|
||||
if (impactVfxPrefab != null)
|
||||
Destroy(Instantiate(impactVfxPrefab, targetPoint, Quaternion.identity), impactVfxLifetime);
|
||||
|
||||
if (impactSound.clip != null)
|
||||
AudioManager.Instance?.Play(impactSound.clip, AudioCategory.TowerFire,
|
||||
impactSound.RandomPitch(), impactSound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
82
Assets/_Project/Scripts/VFX/FallFromSkyVisual.cs
Normal file
82
Assets/_Project/Scripts/VFX/FallFromSkyVisual.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// Assets/_Project/Scripts/VFX/FallFromSkyVisual.cs
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TD.VFX
|
||||
{
|
||||
/// <summary>
|
||||
/// Animates this object falling from the sky down to its own spawn position. Intended for
|
||||
/// a one-shot placeholder VFX prefab (e.g. <c>FireballSpellDefinition.impactVfxPrefab</c>)
|
||||
/// that gets instantiated already at the correct landing point — on <c>Start</c>, it snaps
|
||||
/// itself up by <see cref="dropHeight"/> and animates back down over
|
||||
/// <see cref="duration"/> seconds.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mirrors <see cref="TD.Combat.TowerLandingVisual"/>'s fall coroutine, minus the
|
||||
/// <c>TowerInstance</c> coupling — this is a plain local one-shot visual, not tied to any
|
||||
/// networked gameplay state, so it can run from <c>Start()</c> instead of waiting on a
|
||||
/// spawn event.
|
||||
/// </remarks>
|
||||
public class FallFromSkyVisual : MonoBehaviour
|
||||
{
|
||||
[Tooltip("How high above the landing point this object starts.")]
|
||||
[SerializeField] private float dropHeight = 20f;
|
||||
|
||||
[Tooltip("Seconds for the fall animation to complete.")]
|
||||
[Min(0.01f)]
|
||||
[SerializeField] private float duration = 0.5f;
|
||||
|
||||
[Tooltip("Eases the fall over Duration. X = normalized time, Y = normalized fraction " +
|
||||
"of DropHeight already descended (0 = still at drop height, 1 = landed).")]
|
||||
[SerializeField] private AnimationCurve fallCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
||||
|
||||
[Header("Angle (optional — 0 = straight down)")]
|
||||
[Tooltip("Angle from vertical, in degrees. 0 = falls straight down. Higher values = " +
|
||||
"a shallower, more meteor-like diagonal approach. Capped below 90 — at 90 the " +
|
||||
"object would never actually descend.")]
|
||||
[Range(0f, 80f)]
|
||||
[SerializeField] private float fallAngleDegrees = 0f;
|
||||
|
||||
[Tooltip("Horizontal direction the object travels as it falls (only used when " +
|
||||
"FallAngleDegrees > 0). Magnitude is ignored — normalized automatically.")]
|
||||
[SerializeField] private Vector3 fallDirection = Vector3.forward;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(AnimateDrop());
|
||||
}
|
||||
|
||||
private IEnumerator AnimateDrop()
|
||||
{
|
||||
Vector3 landedPosition = transform.position; // already correct — spawned at the target point
|
||||
|
||||
// Split dropHeight into a vertical component (unchanged from the straight-down case)
|
||||
// plus a horizontal component derived from the angle via basic trig: at angle θ from
|
||||
// vertical, horizontal distance = dropHeight * tan(θ). At θ = 0 this is 0, so the
|
||||
// whole angle path collapses back to the original straight-down offset.
|
||||
float angleRad = fallAngleDegrees * Mathf.Deg2Rad;
|
||||
float horizontalDistance = dropHeight * Mathf.Tan(angleRad);
|
||||
|
||||
// Only the horizontal (XZ) part of fallDirection matters — a Y component would just
|
||||
// be double-counting dropHeight, so it's dropped before normalizing.
|
||||
Vector3 flatDirection = new Vector3(fallDirection.x, 0f, fallDirection.z);
|
||||
Vector3 horizontalDir = flatDirection.sqrMagnitude > 0.0001f
|
||||
? flatDirection.normalized
|
||||
: Vector3.zero;
|
||||
|
||||
Vector3 startOffset = Vector3.up * dropHeight - horizontalDir * horizontalDistance;
|
||||
transform.position = landedPosition + startOffset;
|
||||
|
||||
float t = 0f;
|
||||
while (t < duration)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float u = fallCurve.Evaluate(Mathf.Clamp01(t / duration));
|
||||
transform.position = landedPosition + startOffset * (1f - u);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
transform.position = landedPosition; // snap exactly, avoid float drift
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/_Project/Scripts/VFX/FallFromSkyVisual.cs.meta
Normal file
2
Assets/_Project/Scripts/VFX/FallFromSkyVisual.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 883bd1d14f70a623ea1b252cf7015a92
|
||||
Loading…
Add table
Add a link
Reference in a new issue