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

45 lines
1012 B
C#
Raw Normal View History

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