2022-03-12 21:14:07 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 进入式触发器的基类,继承自事件,每一个进入式触发器都必须继承这个类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EntryTrigger : Event
|
|
|
|
|
{
|
|
|
|
|
private Collider2D m_collider;
|
2022-04-02 21:46:10 +08:00
|
|
|
|
public Event m_event;
|
|
|
|
|
public Stage m_stage;
|
2022-03-12 21:14:07 +08:00
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
//如果没有挂载碰撞盒,则报错
|
|
|
|
|
if(!TryGetComponent<Collider2D>(out m_collider))
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError(this.GetType() + gameObject.name + "没有挂载碰撞盒,请检查!");
|
|
|
|
|
}
|
|
|
|
|
//如果不是触发器,则报错
|
|
|
|
|
if(!m_collider.isTrigger)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError(this.GetType() + gameObject.name + "碰撞盒没有设置为触发器,请检查!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual public void OnTriggerEnter2D(Collider2D other)
|
|
|
|
|
{
|
|
|
|
|
//如果玩家进入碰撞盒则触发事件
|
|
|
|
|
if(other.TryGetComponent<Player>(out Player player)) OnCall();
|
|
|
|
|
}
|
2022-04-02 21:46:10 +08:00
|
|
|
|
|
|
|
|
|
public override void OnCall()
|
|
|
|
|
{
|
|
|
|
|
//如果链接了事件或者演出,则执行
|
|
|
|
|
if(m_event != null) m_event.OnCall();
|
|
|
|
|
if(m_stage != null) m_stage.OnCall();
|
|
|
|
|
//如果二者都为null,则报告
|
|
|
|
|
if(m_event == null && m_stage == null) Debug.Log(this.GetType() + gameObject.name + "没有链接事件或者演出,你确定吗?");
|
|
|
|
|
}
|
2022-03-12 21:14:07 +08:00
|
|
|
|
}
|