using System; using System.Collections.Generic; using UnityEngine; public class ContinuePickUpHandler : MonoBehaviour { private List _curZoneList; private ConutinuePickUpZone _curZone; public event Action onEnterContinueItem; public event Action onExitContinueItem; public void Setup() { _curZoneList = new List(); } private void OnTriggerEnter(Collider other) { ConutinuePickUpZone zone = other.GetComponentInParent(); if (zone != null) { _curZoneList.Add(zone); } UpdateZone(); } private void OnTriggerExit(Collider other) { ConutinuePickUpZone zone = other.GetComponentInParent(); if (zone != null) { zone.ActiveZone(active: false); _curZoneList.Remove(zone); } UpdateZone(); } private void UpdateZone() { if (_curZoneList.Count == 0) { if (_curZone != null) { _curZone.ActiveZone(active: false); _curZone = null; } if (this.onExitContinueItem != null) { this.onExitContinueItem(); } return; } ConutinuePickUpZone last = _curZoneList[_curZoneList.Count - 1]; if (_curZone != last) { if (_curZone != null) { _curZone.ActiveZone(active: false); } last.ActiveZone(active: true); _curZone = last; if (this.onEnterContinueItem != null) { this.onEnterContinueItem(last); } } } }