chore: initial commit
This commit is contained in:
24
Assets/Scripts/Audio/AudioZone.cs
Normal file
24
Assets/Scripts/Audio/AudioZone.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user