building falling from orbit sound
This commit is contained in:
parent
ffe38ed8b1
commit
4a37d3747c
7 changed files with 109 additions and 1 deletions
46
Assets/_Project/Scripts/Combat/TowerFallingSound.cs
Normal file
46
Assets/_Project/Scripts/Combat/TowerFallingSound.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Assets/_Project/Scripts/Combat/TowerFallingSound.cs
|
||||
using TD.Audio;
|
||||
using TD.Gameplay;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TD.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Local-only audio for the tower falling from the sky. Attached to
|
||||
/// <see cref="BuildSiteVisual"/> (not <see cref="TowerInstance"/>, which doesn't exist
|
||||
/// yet) and polled every frame: plays a sound on every peer once construction has
|
||||
/// <see cref="triggerSecondsBeforeCompletion"/> seconds or less remaining, so the whoosh
|
||||
/// leads the tower's actual fall/land animation (see <see cref="TowerLandingVisual"/>,
|
||||
/// which starts once <see cref="BuildSiteVisual"/> is replaced by the real
|
||||
/// <see cref="TowerInstance"/> at construction-complete).
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(BuildSiteVisual))]
|
||||
public class TowerFallingSound : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private SoundConfig fallingSound;
|
||||
|
||||
[Tooltip("Sound fires once remaining construction time drops to this many seconds " +
|
||||
"or less.")]
|
||||
[SerializeField] private float triggerSecondsBeforeCompletion = 1f;
|
||||
|
||||
private BuildSiteVisual buildSiteVisual;
|
||||
private bool played;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
buildSiteVisual = GetComponent<BuildSiteVisual>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (played || buildSiteVisual == null) return;
|
||||
if (buildSiteVisual.CurrentStage != BuildStage.Constructing) return;
|
||||
|
||||
if (buildSiteVisual.ComputeRemainingSeconds() <= triggerSecondsBeforeCompletion)
|
||||
{
|
||||
played = true;
|
||||
AudioManager.Instance?.Play(fallingSound.clip, AudioCategory.UI, fallingSound.RandomPitch(), fallingSound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/_Project/Scripts/Combat/TowerFallingSound.cs.meta
Normal file
3
Assets/_Project/Scripts/Combat/TowerFallingSound.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5712fbfba2f64c3aa653bebe31773d54
|
||||
timeCreated: 1783406173
|
||||
|
|
@ -184,6 +184,20 @@ namespace TD.Gameplay
|
|||
return Mathf.Clamp01((currentRunElapsed + accumulatedConstructionTime.Value) / bt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns seconds remaining until construction completes. Safe to call on any
|
||||
/// client. Returns 0 while Queued (no timer running yet) or once complete.
|
||||
/// </summary>
|
||||
public float ComputeRemainingSeconds()
|
||||
{
|
||||
float bt = buildTime.Value;
|
||||
if (bt <= 0f) return 0f;
|
||||
float currentRunElapsed = constructionStartServerTime.Value > 0f
|
||||
? (float)NetworkManager.Singleton.ServerTime.Time - constructionStartServerTime.Value
|
||||
: 0f;
|
||||
return Mathf.Max(0f, bt - (currentRunElapsed + accumulatedConstructionTime.Value));
|
||||
}
|
||||
|
||||
// ----- ISelectable ------------------------------------------------
|
||||
|
||||
/// <summary>Name shown in the HUD portrait. Pulls from the resolved
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue