57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
// Assets/Scripts/World/Liquid/LiquidZone.cs
|
||
using BaseGames.Core.Events;
|
||
using MoreMountains.Feedbacks;
|
||
using UnityEngine;
|
||
|
||
namespace BaseGames.World.Liquid
|
||
{
|
||
/// <summary>
|
||
/// 挂在液态区域根 GameObject 上。
|
||
/// 酸液/熔岩时需同时挂载 HazardZone(InstantKill 类型)。
|
||
/// </summary>
|
||
[RequireComponent(typeof(Collider2D))]
|
||
public class LiquidZone : MonoBehaviour
|
||
{
|
||
[Header("液体类型")]
|
||
[SerializeField] private LiquidType _liquidType = LiquidType.Water;
|
||
|
||
[Header("区域标识(存档/跨系统识别)")]
|
||
[SerializeField] private string _zoneId;
|
||
|
||
[Header("伤害(Water 类型专用;Acid/Lava 由子节点 HazardZone 处理)")]
|
||
#pragma warning disable CS0414
|
||
[SerializeField] private bool _dealsDrowningDamage = false;
|
||
[SerializeField] private float _drowningDamagePerSecond = 5f;
|
||
#pragma warning restore CS0414
|
||
|
||
[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));
|
||
}
|
||
}
|
||
}
|