备份CatanBuilding瘦身独立工程
This commit is contained in:
59
Assets/Scripts/EventPinball/PinballSwitcherCloseDetection.cs
Normal file
59
Assets/Scripts/EventPinball/PinballSwitcherCloseDetection.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user