Files
zeling_v2/Assets/Scripts/World/Liquid/LiquidZone.cs
2026-05-13 09:19:54 +08:00

53 lines
1.9 KiB
C#
Raw 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.
// Assets/Scripts/World/Liquid/LiquidZone.cs
using BaseGames.Core.Events;
using MoreMountains.Feedbacks;
using UnityEngine;
namespace BaseGames.World.Liquid
{
/// <summary>
/// 挂在液态区域根 GameObject 上。
/// 酸液/熔岩时需同时挂载 HazardZoneInstantKill 类型)。
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class LiquidZone : MonoBehaviour
{
[Header("液体类型")]
[SerializeField] private LiquidType _liquidType = LiquidType.Water;
[Header("区域标识(存档/跨系统识别)")]
[SerializeField] private string _zoneId;
[Header("伤害Acid/Lava 由子节点 HazardZone 处理Water 类型溺死由 WaterDangerState 处理)")]
[Header("物理配置")]
[SerializeField] private LiquidPhysicsConfigSO _physicsConfig;
[Header("Event Channels")]
[SerializeField] private LiquidEventChannelSO _onPlayerEntered;
[SerializeField] private LiquidEventChannelSO _onPlayerExited;
[Header("Feedback")]
[SerializeField] private MMFeedbacks _splashEnterFeedback;
[SerializeField] private MMFeedbacks _splashExitFeedback;
public LiquidType Type => _liquidType;
public LiquidPhysicsConfigSO Physics => _physicsConfig;
public string ZoneId => _zoneId;
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
_splashEnterFeedback?.PlayFeedbacks();
_onPlayerEntered?.Raise(new LiquidEvent(_zoneId, _liquidType));
}
private void OnTriggerExit2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
_splashExitFeedback?.PlayFeedbacks();
_onPlayerExited?.Raise(new LiquidEvent(_zoneId, _liquidType));
}
}
}