mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add map restriction volume
This commit is contained in:
parent
8d04dc23b4
commit
6e843ee09b
35
NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs
Normal file
35
NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,6 +49,13 @@ namespace NewHorizons.Builder.Volumes
|
||||
HazardVolumeBuilder.Make(go, sector, planetBody, hazardVolume, mod);
|
||||
}
|
||||
}
|
||||
if (config.Volumes.mapRestrictionVolumes != null)
|
||||
{
|
||||
foreach (var mapRestrictionVolume in config.Volumes.mapRestrictionVolumes)
|
||||
{
|
||||
MapRestrictionVolumeBuilder.Make(go, sector, mapRestrictionVolume);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
NewHorizons/Components/MapRestrictionVolume.cs
Normal file
43
NewHorizons/Components/MapRestrictionVolume.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,11 @@ namespace NewHorizons.External.Modules
|
||||
/// </summary>
|
||||
public HazardVolumeInfo[] hazardVolumes;
|
||||
|
||||
/// <summary>
|
||||
/// Add map restriction volumes to this planet
|
||||
/// </summary>
|
||||
public VolumeInfo[] mapRestrictionVolumes;
|
||||
|
||||
/// <summary>
|
||||
/// Add notification volumes to this planet
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user