60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace game
|
|
{
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
[RequireComponent(typeof(Collider2D))]
|
|
public class PinballSwitcherCloseDetection : MonoBehaviour
|
|
{
|
|
public PinballPellet m_Pellet;
|
|
public PinballSwitcher m_Switcher;
|
|
public int m_WaitFrames = 3;
|
|
|
|
#region Switcher
|
|
public IEnumerator CloseSwitcher()
|
|
{
|
|
int index = 0;
|
|
while (index < m_WaitFrames)
|
|
{
|
|
yield return null;
|
|
index++;
|
|
}
|
|
|
|
FishingPinballAct.Publish(new EventPinballSwitcherClose());
|
|
}
|
|
#endregion
|
|
|
|
#region Collider2D
|
|
private void OnCollisionExit2D(Collision2D collision)
|
|
{
|
|
if (m_Pellet != null && m_Switcher != null && m_Switcher.IsOpen() && collision.gameObject == m_Pellet.gameObject)
|
|
{
|
|
StartCoroutine(CloseSwitcher());
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 事件相关
|
|
public void InitEvent()
|
|
{
|
|
FishingPinballAct.Subscribe<EventPinballSetDummyPelletData>(SetData);
|
|
}
|
|
|
|
public void SetData(EventPinballSetDummyPelletData data)
|
|
{
|
|
if (data == null) return;
|
|
m_Pellet = data.Pellet;
|
|
}
|
|
#endregion
|
|
|
|
#region 生命周期
|
|
private void Awake()
|
|
{
|
|
InitEvent();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|