MatchManager: new Radar Ping Sound property; MsgRadarPing now goes to all clients (spawnBlips flag keeps blips hunter-only), sound plays 3D at each pinged hider. Distance-based stagger (speed of sound + 35 ms min gap) prevents phase cancellation when multiple hiders ping. SoundEffect: new spatialize toggle (per asset, applied only to 3D instances -> Steam Audio HRTF); removed unused fade field. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using System.Collections;
|
|
|
|
using UnityEngine;
|
|
|
|
namespace Prototype
|
|
{
|
|
[AddComponentMenu("/")]
|
|
public class SoundEffectInstance : MonoBehaviour
|
|
{
|
|
public AudioClip clip { get; set; }
|
|
public SoundEffectOptions options { get; set; }
|
|
|
|
AudioSource audioSource;
|
|
|
|
void Awake()
|
|
{
|
|
audioSource = gameObject.AddComponent<AudioSource>();
|
|
{
|
|
audioSource.playOnAwake = false;
|
|
audioSource.dopplerLevel = 0;
|
|
audioSource.outputAudioMixerGroup = options.audioMixerGroup;
|
|
audioSource.clip = clip;
|
|
audioSource.volume = options.GetVolume();
|
|
audioSource.pitch = options.GetPitch();
|
|
|
|
var range = options.GetDistanceRange();
|
|
|
|
audioSource.spatialBlend = range.x == 0 && range.y == 0 ? 0 : 1;
|
|
audioSource.spatialize = options.GetSpatialize() && audioSource.spatialBlend > 0;
|
|
audioSource.rolloffMode = AudioRolloffMode.Linear;
|
|
audioSource.minDistance = range.x;
|
|
audioSource.maxDistance = range.y;
|
|
audioSource.loop = options.GetLoop();
|
|
}
|
|
|
|
if (!options.ShouldDestroyOnLoad())
|
|
{
|
|
DontDestroyOnLoad(this);
|
|
}
|
|
}
|
|
|
|
IEnumerator Start()
|
|
{
|
|
var delay = options.GetDelay();
|
|
if (delay > 0)
|
|
{
|
|
yield return new WaitForSeconds(delay);
|
|
}
|
|
|
|
audioSource.Play();
|
|
|
|
if (audioSource.loop)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
yield return new WaitForSecondsRealtime(audioSource.clip.length + .1f);
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|