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(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(); shape.radius = info.radius; var owTriggerVolume = go.AddComponent(); owTriggerVolume._shape = shape; var volume = go.AddComponent(); go.SetActive(true); return volume; } } }