72 lines
1.4 KiB
C#
72 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ContinuePickUpHandler : MonoBehaviour
|
|
{
|
|
private List<ConutinuePickUpZone> _curZoneList;
|
|
|
|
private ConutinuePickUpZone _curZone;
|
|
|
|
public event Action<ConutinuePickUpZone> onEnterContinueItem;
|
|
|
|
public event Action onExitContinueItem;
|
|
|
|
public void Setup()
|
|
{
|
|
_curZoneList = new List<ConutinuePickUpZone>();
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
ConutinuePickUpZone zone = other.GetComponentInParent<ConutinuePickUpZone>();
|
|
if (zone != null)
|
|
{
|
|
_curZoneList.Add(zone);
|
|
}
|
|
UpdateZone();
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
ConutinuePickUpZone zone = other.GetComponentInParent<ConutinuePickUpZone>();
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|