Files
zeling_v2/Assets/_Game/Scripts/Audio/AudioZone.cs

25 lines
823 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using BaseGames.Core.Events;
namespace BaseGames.Audio
{
/// <summary>
/// 区域音效触发器:玩家进入 Collider2D 时广播 _onRegionEntered 事件频道。
/// 挂在区域边界的 GameObject 上Collider2D 设置为 Is Trigger。
/// _zoneId 须与 AudioConfigSO.ZoneBGMs 中的 ZoneId 一致。
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class AudioZone : MonoBehaviour
{
[SerializeField] private string _zoneId;
[SerializeField] private StringEventChannelSO _onRegionEntered;
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
if (_onRegionEntered != null)
_onRegionEntered.Raise(_zoneId);
}
}
}