Add map restriction volume

This commit is contained in:
Noah Pilarski 2022-08-31 15:26:05 -04:00
parent 8d04dc23b4
commit 6e843ee09b
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,35 @@
using NewHorizons.Components;
using NewHorizons.External.Modules;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Builder.Volumes
{
public static class MapRestrictionVolumeBuilder
{
public static MapRestrictionVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info)
{
var go = new GameObject("MapRestrictionVolume");
go.SetActive(false);
go.transform.parent = sector?.transform ?? planetGO.transform;
go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero);
go.layer = LayerMask.NameToLayer("BasicEffectVolume");
var shape = go.AddComponent<SphereShape>();
shape.radius = info.radius;
var owTriggerVolume = go.AddComponent<OWTriggerVolume>();
owTriggerVolume._shape = shape;
var mapRestrictionVolume = go.AddComponent<MapRestrictionVolume>();
go.SetActive(true);
return mapRestrictionVolume;
}
}
}

View File

@ -49,6 +49,13 @@ namespace NewHorizons.Builder.Volumes
HazardVolumeBuilder.Make(go, sector, planetBody, hazardVolume, mod); HazardVolumeBuilder.Make(go, sector, planetBody, hazardVolume, mod);
} }
} }
if (config.Volumes.mapRestrictionVolumes != null)
{
foreach (var mapRestrictionVolume in config.Volumes.mapRestrictionVolumes)
{
MapRestrictionVolumeBuilder.Make(go, sector, mapRestrictionVolume);
}
}
} }
} }
} }

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Components
{
[RequireComponent(typeof(OWTriggerVolume))]
public class MapRestrictionVolume : MonoBehaviour
{
private OWTriggerVolume _triggerVolume;
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"))
{
Locator.GetMapController()?.OnPlayerEnterMapRestriction();
}
}
public void OnTriggerVolumeExit(GameObject hitObj)
{
if (hitObj.CompareTag("PlayerDetector"))
{
Locator.GetMapController()?.OnPlayerExitMapRestriction();
}
}
}
}

View File

@ -24,6 +24,11 @@ namespace NewHorizons.External.Modules
/// </summary> /// </summary>
public HazardVolumeInfo[] hazardVolumes; public HazardVolumeInfo[] hazardVolumes;
/// <summary>
/// Add map restriction volumes to this planet
/// </summary>
public VolumeInfo[] mapRestrictionVolumes;
/// <summary> /// <summary>
/// Add notification volumes to this planet /// Add notification volumes to this planet
/// </summary> /// </summary>