Add base volume abstract class

This commit is contained in:
Noah Pilarski 2022-08-31 15:51:11 -04:00
parent 55640c157f
commit 2352d5f2d8
3 changed files with 34 additions and 39 deletions

View File

@ -0,0 +1,28 @@
using UnityEngine;
namespace NewHorizons.Components
{
[RequireComponent(typeof(OWTriggerVolume))]
public abstract class BaseVolume : MonoBehaviour
{
private OWTriggerVolume _triggerVolume;
public virtual void Awake()
{
_triggerVolume = this.GetRequiredComponent<OWTriggerVolume>();
_triggerVolume.OnEntry += OnTriggerVolumeEntry;
_triggerVolume.OnExit += OnTriggerVolumeExit;
}
public virtual void OnDestroy()
{
if (_triggerVolume == null) return;
_triggerVolume.OnEntry -= OnTriggerVolumeEntry;
_triggerVolume.OnExit -= OnTriggerVolumeExit;
}
public abstract void OnTriggerVolumeEntry(GameObject hitObj);
public abstract void OnTriggerVolumeExit(GameObject hitObj);
}
}

View File

@ -5,26 +5,9 @@ using UnityEngine;
namespace NewHorizons.Components namespace NewHorizons.Components
{ {
[RequireComponent(typeof(OWTriggerVolume))] public class MapRestrictionVolume : BaseVolume
public class MapRestrictionVolume : MonoBehaviour
{ {
private OWTriggerVolume _triggerVolume; public override void OnTriggerVolumeEntry(GameObject hitObj)
public void Awake()
{
_triggerVolume = this.GetRequiredComponent<OWTriggerVolume>();
_triggerVolume.OnEntry += OnTriggerVolumeEntry;
_triggerVolume.OnExit += OnTriggerVolumeExit;
}
public void OnDestroy()
{
if (_triggerVolume == null) return;
_triggerVolume.OnEntry -= OnTriggerVolumeEntry;
_triggerVolume.OnExit -= OnTriggerVolumeExit;
}
public void OnTriggerVolumeEntry(GameObject hitObj)
{ {
if (hitObj.CompareTag("PlayerDetector")) if (hitObj.CompareTag("PlayerDetector"))
{ {
@ -32,7 +15,7 @@ namespace NewHorizons.Components
} }
} }
public void OnTriggerVolumeExit(GameObject hitObj) public override void OnTriggerVolumeExit(GameObject hitObj)
{ {
if (hitObj.CompareTag("PlayerDetector")) if (hitObj.CompareTag("PlayerDetector"))
{ {

View File

@ -7,29 +7,13 @@ using UnityEngine;
namespace NewHorizons.Components namespace NewHorizons.Components
{ {
[RequireComponent(typeof(OWTriggerVolume))] public class NotificationVolume : BaseVolume
public class NotificationVolume : MonoBehaviour
{ {
private NotificationTarget _target = NotificationTarget.All; private NotificationTarget _target = NotificationTarget.All;
private bool _pin = false; private bool _pin = false;
private OWTriggerVolume _triggerVolume;
private NotificationData _entryNotification; private NotificationData _entryNotification;
private NotificationData _exitNotification; private NotificationData _exitNotification;
public void Awake()
{
_triggerVolume = this.GetRequiredComponent<OWTriggerVolume>();
_triggerVolume.OnEntry += OnTriggerVolumeEntry;
_triggerVolume.OnExit += OnTriggerVolumeExit;
}
public void OnDestroy()
{
if (_triggerVolume == null) return;
_triggerVolume.OnEntry -= OnTriggerVolumeEntry;
_triggerVolume.OnExit -= OnTriggerVolumeExit;
}
public void SetPinned(bool pin) => _pin = pin; public void SetPinned(bool pin) => _pin = pin;
public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse<NotificationTarget>(target.ToString(), NotificationTarget.All)); public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse<NotificationTarget>(target.ToString(), NotificationTarget.All));
@ -46,7 +30,7 @@ namespace NewHorizons.Components
_exitNotification = new NotificationData(_target, TranslationHandler.GetTranslation(displayMessage, TranslationHandler.TextType.UI), duration); _exitNotification = new NotificationData(_target, TranslationHandler.GetTranslation(displayMessage, TranslationHandler.TextType.UI), duration);
} }
public void OnTriggerVolumeEntry(GameObject hitObj) public override void OnTriggerVolumeEntry(GameObject hitObj)
{ {
if (_target == NotificationTarget.All) if (_target == NotificationTarget.All)
{ {
@ -71,7 +55,7 @@ namespace NewHorizons.Components
} }
} }
public void OnTriggerVolumeExit(GameObject hitObj) public override void OnTriggerVolumeExit(GameObject hitObj)
{ {
if (_target == NotificationTarget.All) if (_target == NotificationTarget.All)
{ {