45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class BottleSlot : MonoBehaviour
|
|
{
|
|
private CoolingMachineViewer _coolingMachine;
|
|
|
|
private void Awake()
|
|
{
|
|
InitComponentRefs();
|
|
}
|
|
|
|
private void InitComponentRefs()
|
|
{
|
|
_coolingMachine = GetComponentInParent<CoolingMachineViewer>();
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (_coolingMachine.isLocked) return;
|
|
|
|
if (other.gameObject.TryGetComponent<CoolingBottle>(out var bottle))
|
|
{
|
|
// 进入时只给吸附标记,松手才吸附
|
|
bottle.isSnapped = true;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D other)
|
|
{
|
|
if (_coolingMachine.isLocked) return;
|
|
|
|
if (other.gameObject.TryGetComponent<CoolingBottle>(out var bottle))
|
|
{
|
|
// 离开时直接触发拔出逻辑,不等松手
|
|
bottle.isSnapped = false;
|
|
// 拔出
|
|
_coolingMachine.MoveOutBottle();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|