revival/game/Assets/Scripts/Util/Events/GameEventTrigger.cs

45 lines
1012 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
namespace Ktyl.Util
{
[RequireComponent(typeof(BoxCollider))]
public class GameEventTrigger : MonoBehaviour
{
[Serializable]
private struct Event
{
public GameEvent game;
public UnityEvent unity;
public void Raise()
{
if (game) game.Raise();
unity.Invoke();
}
}
[SerializeField] private Event _onEnter;
[SerializeField] private Event _onExit;
private void Start()
{
GetComponent<BoxCollider>().isTrigger = true;
}
private void OnTriggerEnter(Collider other)
{
_onEnter.Raise();
}
private void OnTriggerExit(Collider other)
{
_onExit.Raise();
}
}
}