You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace HJDFrameWork
{
public class EventColChecker : MonoBehaviour
{
[Header("进入事件")]
public string[] EnterEventList;
[Header("退出碰撞体事件")]
public string[] ExitEventList;
[Header("Tag标签(为空则自动填Player)")]
public string[] _tagName;
// Start is called before the first frame update
void Start()
{
if (_tagName.Length == 0)
{
_tagName = new string[1];
_tagName[0] = "Player";
}
}
private void OnTriggerEnter(Collider other)
{
for (int i = 0; i < _tagName.Length; i++)
{
if (other.gameObject.tag == _tagName[i])
{
for (int j = 0; j < EnterEventList.Length; j++)
{
EventManager.Instance.Trigger(EnterEventList[i]);
}
}
}
Debug.Log(gameObject.name + "碰撞进入事件触发");
}
private void OnTriggerExit(Collider other)
{
for (int i = 0; i < _tagName.Length; i++)
{
if (other.gameObject.tag == _tagName[i])
{
for (int j = 0; j < EnterEventList.Length; j++)
{
EventManager.Instance.Trigger(ExitEventList[i]);
}
}
}
Debug.Log(gameObject.name + "碰撞进入事件触发");
}
private void OnCollisionEnter(Collision collision)
{
for (int i = 0; i < _tagName.Length; i++)
{
if (collision.gameObject.tag == _tagName[i])
{
for (int j = 0; j < EnterEventList.Length; j++)
{
EventManager.Instance.Trigger(EnterEventList[i]);
}
}
}
Debug.Log(gameObject.name + "碰撞进入事件触发");
}
private void OnCollisionExit(Collision collision)
{
for (int i = 0; i < _tagName.Length; i++)
{
if (collision.gameObject.tag == _tagName[i])
{
for (int j = 0; j < EnterEventList.Length; j++)
{
EventManager.Instance.Trigger(ExitEventList[i]);
}
}
}
Debug.Log(gameObject.name + "碰撞进入事件触发");
}
}
}