mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using NewHorizons.Components;
|
|
using NewHorizons.External.Modules;
|
|
using UnityEngine;
|
|
using Logger = NewHorizons.Utility.Logger;
|
|
|
|
namespace NewHorizons.Builder.Volumes
|
|
{
|
|
public static class VolumeBuilder
|
|
{
|
|
public static TVolume Make<TVolume>(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) where TVolume : MonoBehaviour //Could be BaseVolume but I need to create vanilla volumes too.
|
|
{
|
|
var go = new GameObject(typeof(TVolume).Name);
|
|
go.SetActive(false);
|
|
|
|
go.transform.parent = sector?.transform ?? planetGO.transform;
|
|
|
|
if (!string.IsNullOrEmpty(info.rename))
|
|
{
|
|
go.name = info.rename;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(info.parentPath))
|
|
{
|
|
var newParent = planetGO.transform.Find(info.parentPath);
|
|
if (newParent != null)
|
|
{
|
|
go.transform.parent = newParent;
|
|
}
|
|
else
|
|
{
|
|
Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}");
|
|
}
|
|
}
|
|
|
|
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 volume = go.AddComponent<TVolume>();
|
|
|
|
go.SetActive(true);
|
|
|
|
return volume;
|
|
}
|
|
}
|
|
}
|