Get prefabs from solar system and then head back to eye

This commit is contained in:
Noah Pilarski 2022-09-10 23:09:56 -04:00
parent d0a5b35a35
commit 6caa2d8991
30 changed files with 788 additions and 410 deletions

View File

@ -1,6 +1,7 @@
using NewHorizons.External.Modules;
using NewHorizons.Utility;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Builder.Atmosphere
{
@ -18,18 +19,26 @@ namespace NewHorizons.Builder.Atmosphere
Skys.Clear();
}
private static GameObject _atmospherePrefab;
private static GameObject _proxyAtmospherePrefab;
internal static void InitPrefabs()
{
if (_atmospherePrefab == null) _atmospherePrefab = SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere").InstantiateInactive().Rename("Atmosphere").DontDestroyOnLoad();
if (_proxyAtmospherePrefab == null) _proxyAtmospherePrefab = GameObject.FindObjectOfType<DistantProxyManager>()._proxies.FirstOrDefault(apt => apt.astroName == AstroObject.Name.TimberHearth).proxyPrefab.FindChild("Atmosphere_TH/Atmosphere_LOD3").InstantiateInactive().Rename("ProxyAtmosphere").DontDestroyOnLoad();
}
public static GameObject Make(GameObject planetGO, Sector sector, AtmosphereModule atmosphereModule, float surfaceSize, bool proxy = false)
{
InitPrefabs();
GameObject atmoGO = new GameObject("Atmosphere");
atmoGO.SetActive(false);
atmoGO.transform.parent = sector?.transform ?? planetGO.transform;
if (atmosphereModule.useAtmosphereShader)
{
GameObject prefab;
if (proxy) prefab = (SearchUtilities.Find("TimberHearth_DistantProxy", false) ?? SearchUtilities.Find("TimberHearth_DistantProxy(Clone)", false))?
.FindChild("Atmosphere_TH/Atmosphere_LOD3");
else prefab = SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere");
GameObject prefab = proxy ? _proxyAtmospherePrefab : _atmospherePrefab;
if (prefab != null)
{

View File

@ -5,12 +5,18 @@ using OWML.Common;
using System;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
using System.Collections.Generic;
using Tessellation;
namespace NewHorizons.Builder.Atmosphere
{
public static class CloudsBuilder
{
private static Material[] _gdCloudMaterials;
private static Material[] _qmCloudMaterials;
private static Material[] _qmBottomMaterials;
private static Mesh _gdTopCloudMesh;
private static Tessellation.MeshGroup _qmBottomMeshGroup;
private static Material _transparentCloud;
private static GameObject _lightningPrefab;
private static Texture2D _colorRamp;
@ -21,10 +27,35 @@ namespace NewHorizons.Builder.Atmosphere
private static readonly int CapTex = Shader.PropertyToID("_CapTex");
private static readonly int Smoothness = Shader.PropertyToID("_Glossiness");
internal static void InitPrefabs()
{
if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD").InstantiateInactive().Rename("LightningGenerator").DontDestroyOnLoad();
if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Clouds_Bottom_ramp.png");
if (_gdTopCloudMesh == null) _gdTopCloudMesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh.DontDestroyOnLoad();
if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials.MakePrefabMaterials();
if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent<MeshRenderer>().sharedMaterials.MakePrefabMaterials();
if (_qmBottomMaterials == null) _qmBottomMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent<TessellatedSphereRenderer>().sharedMaterials.MakePrefabMaterials();
if (_qmBottomMeshGroup == null)
{
var originalMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
_qmBottomMeshGroup = ScriptableObject.CreateInstance<MeshGroup>().Rename("BottomClouds").DontDestroyOnLoad();
var variants = new List<Mesh>();
foreach (var variant in originalMeshGroup.variants)
{
var mesh = new Mesh();
mesh.CopyPropertiesFrom(variant);
mesh.name = variant.name;
mesh.DontDestroyOnLoad();
variants.Add(mesh);
}
_qmBottomMeshGroup.variants = variants.ToArray();
}
if (_transparentCloud == null) _transparentCloud = Main.NHAssetBundle.LoadAsset<Material>("Assets/Resources/TransparentCloud.mat");
}
public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, bool cloaked, IModBehaviour mod)
{
if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD");
if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Clouds_Bottom_ramp.png");
InitPrefabs();
GameObject cloudsMainGO = new GameObject("Clouds");
cloudsMainGO.SetActive(false);
@ -46,8 +77,8 @@ namespace NewHorizons.Builder.Atmosphere
cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius;
TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent<TessellatedSphereRenderer>();
bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent<TessellatedSphereRenderer>().sharedMaterials;
bottomTSR.tessellationMeshGroup = _qmBottomMeshGroup;
var bottomTSRMaterials = _qmBottomMaterials;
// If they set a colour apply it to all the materials else keep the default QM one
if (atmo.clouds.tint != null)
@ -118,6 +149,8 @@ namespace NewHorizons.Builder.Atmosphere
public static CloudLightningGenerator MakeLightning(GameObject rootObject, Sector sector, AtmosphereModule atmo, bool noAudio = false)
{
InitPrefabs();
var lightning = _lightningPrefab.InstantiateInactive();
lightning.name = "LightningGenerator";
lightning.transform.parent = rootObject.transform;
@ -149,6 +182,8 @@ namespace NewHorizons.Builder.Atmosphere
public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod)
{
InitPrefabs();
Texture2D image, cap, ramp;
try
@ -173,12 +208,10 @@ namespace NewHorizons.Builder.Atmosphere
cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius;
MeshFilter topMF = cloudsTopGO.AddComponent<MeshFilter>();
topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
topMF.mesh = _gdTopCloudMesh;
MeshRenderer topMR = cloudsTopGO.AddComponent<MeshRenderer>();
if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials;
if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent<MeshRenderer>().sharedMaterials;
Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials;
var tempArray = new Material[2];
@ -231,6 +264,8 @@ namespace NewHorizons.Builder.Atmosphere
public static GameObject MakeTransparentClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod, bool isProxy = false)
{
InitPrefabs();
Texture2D image;
try
@ -249,10 +284,9 @@ namespace NewHorizons.Builder.Atmosphere
cloudsTransparentGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius;
MeshFilter filter = cloudsTransparentGO.AddComponent<MeshFilter>();
filter.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
filter.mesh = _gdTopCloudMesh;
MeshRenderer renderer = cloudsTransparentGO.AddComponent<MeshRenderer>();
if (_transparentCloud == null) _transparentCloud = Main.NHAssetBundle.LoadAsset<Material>("Assets/Resources/TransparentCloud.mat");
var material = new Material(_transparentCloud);
material.name = "TransparentClouds_" + image.name;
material.SetTexture(MainTex, image);

View File

@ -6,8 +6,19 @@ namespace NewHorizons.Builder.Atmosphere
{
public static class EffectsBuilder
{
private static GameObject _rainEmitterPrefab;
private static GameObject _snowEmitterPrefab;
internal static void InitPrefabs()
{
if (_rainEmitterPrefab == null) _rainEmitterPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain").InstantiateInactive().Rename("Prefab_Effects_Rain").DontDestroyOnLoad();
if (_snowEmitterPrefab == null) _snowEmitterPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Effects_BH/Effects_BH_Snowflakes").InstantiateInactive().Rename("Prefab_Effects_Snowflakes").DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, Sector sector, PlanetConfig config, float surfaceSize)
{
InitPrefabs();
GameObject effectsGO = new GameObject("Effects");
effectsGO.SetActive(false);
effectsGO.transform.parent = sector?.transform ?? planetGO.transform;
@ -34,7 +45,7 @@ namespace NewHorizons.Builder.Atmosphere
if (config.Atmosphere.hasRain)
{
var rainGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform);
var rainGO = GameObject.Instantiate(_rainEmitterPrefab, effectsGO.transform);
rainGO.name = "RainEmitter";
rainGO.transform.position = planetGO.transform.position;
@ -58,7 +69,7 @@ namespace NewHorizons.Builder.Atmosphere
snowGO.transform.position = planetGO.transform.position;
for (int i = 0; i < 5; i++)
{
var snowEmitter = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Effects_BH/Effects_BH_Snowflakes"), snowGO.transform);
var snowEmitter = GameObject.Instantiate(_snowEmitterPrefab, snowGO.transform);
snowEmitter.name = "SnowEmitter";
snowEmitter.transform.position = planetGO.transform.position;

View File

@ -14,31 +14,39 @@ namespace NewHorizons.Builder.Atmosphere
private static readonly int DensityExponent = Shader.PropertyToID("_DensityExp");
private static readonly int ColorRampTexture = Shader.PropertyToID("_ColorRampTex");
public static PlanetaryFogController Make(GameObject planetGO, Sector sector, AtmosphereModule atmo)
private static Texture3D _lookupTexture;
private static Mesh _dbImpostorMesh;
private static Material[] _dbImpostorMaterials;
internal static void InitPrefabs()
{
if (_ramp == null) _ramp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/FogColorRamp.png");
// Going to copy from dark bramble
if (_lookupTexture == null) _lookupTexture = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogSphere_DB")?.GetComponent<PlanetaryFogController>()?.fogLookupTexture.DontDestroyOnLoad();
if (_dbImpostorMesh == null) _dbImpostorMesh = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogLOD").GetComponent<MeshFilter>().mesh.DontDestroyOnLoad();
if (_dbImpostorMaterials == null) _dbImpostorMaterials = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogLOD").GetComponent<MeshRenderer>().sharedMaterials.MakePrefabMaterials();
}
public static PlanetaryFogController Make(GameObject planetGO, Sector sector, AtmosphereModule atmo)
{
InitPrefabs();
GameObject fogGO = new GameObject("FogSphere");
fogGO.SetActive(false);
fogGO.transform.parent = sector?.transform ?? planetGO.transform;
fogGO.transform.localScale = Vector3.one * atmo.fogSize;
// Going to copy from dark bramble
var dbFog = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogLOD");
if (dbFog == null) return null;
var dbPlanetaryFogController = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogSphere_DB")?.GetComponent<PlanetaryFogController>();
if (dbPlanetaryFogController == null) return null;
MeshFilter MF = fogGO.AddComponent<MeshFilter>();
MF.mesh = dbFog.GetComponent<MeshFilter>().mesh;
MF.mesh = _dbImpostorMesh;
MeshRenderer MR = fogGO.AddComponent<MeshRenderer>();
MR.materials = dbFog.GetComponent<MeshRenderer>().materials;
MR.materials = _dbImpostorMaterials;
MR.allowOcclusionWhenDynamic = true;
PlanetaryFogController PFC = fogGO.AddComponent<PlanetaryFogController>();
PFC._fogImpostor = MR;
PFC.fogLookupTexture = dbPlanetaryFogController.fogLookupTexture;
PFC.fogLookupTexture = _lookupTexture;
PFC.fogRadius = atmo.fogSize;
PFC.lodFadeDistance = PFC.fogRadius * 0.5f;
PFC.fogDensity = atmo.fogDensity;
@ -65,21 +73,18 @@ namespace NewHorizons.Builder.Atmosphere
public static Renderer MakeProxy(GameObject proxyGO, AtmosphereModule atmo)
{
if (_ramp == null) _ramp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/FogColorRamp.png");
InitPrefabs();
GameObject fogGO = new GameObject("FogSphere");
fogGO.SetActive(false);
fogGO.transform.parent = proxyGO.transform;
fogGO.transform.localScale = Vector3.one * atmo.fogSize;
var fog = (SearchUtilities.Find("TimberHearth_DistantProxy", false) ?? SearchUtilities.Find("TimberHearth_DistantProxy(Clone)", false))?.FindChild("Atmosphere_TH/FogSphere");
if (fog == null) return null;
MeshFilter MF = fogGO.AddComponent<MeshFilter>();
MF.mesh = fog.GetComponent<MeshFilter>().mesh;
MF.mesh = _dbImpostorMesh;
MeshRenderer MR = fogGO.AddComponent<MeshRenderer>();
MR.materials = fog.GetComponent<MeshRenderer>().materials;
MR.materials = _dbImpostorMaterials;
MR.allowOcclusionWhenDynamic = true;
var colorRampTexture = atmo.fogTint == null ? _ramp : ImageUtilities.TintImage(_ramp, atmo.fogTint.ToColor());

View File

@ -7,8 +7,19 @@ namespace NewHorizons.Builder.Atmosphere
{
private static readonly int FogColor = Shader.PropertyToID("_FogColor");
private static Material _gdMaterial;
private static Material _gdCloudMaterial;
internal static void InitPrefabs()
{
if (_gdMaterial == null) _gdMaterial = new Material(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent<EffectRuleset>()._material).DontDestroyOnLoad();
if (_gdCloudMaterial == null) _gdCloudMaterial = new Material(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent<EffectRuleset>()._cloudMaterial).DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, OWRigidbody owrb, PlanetConfig config, float sphereOfInfluence)
{
InitPrefabs();
var innerRadius = config.Base.surfaceSize;
GameObject volumesGO = new GameObject("Volumes");
@ -37,21 +48,17 @@ namespace NewHorizons.Builder.Atmosphere
rulesetGO.AddComponent<AntiTravelMusicRuleset>();
var gdRuleset = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD")?.GetComponent<EffectRuleset>();
if (gdRuleset != null)
{
EffectRuleset ER = rulesetGO.AddComponent<EffectRuleset>();
ER._type = EffectRuleset.BubbleType.Underwater;
ER._material = gdRuleset._material;
ER._material = _gdMaterial;
var cloudMaterial = new Material(gdRuleset._cloudMaterial);
var cloudMaterial = new Material(_gdCloudMaterial);
if (config.Atmosphere?.clouds?.tint != null)
{
cloudMaterial.SetColor(FogColor, config.Atmosphere.clouds.tint.ToColor());
}
ER._cloudMaterial = cloudMaterial;
}
if (config.Base.zeroGravityRadius != 0)
{

View File

@ -47,23 +47,43 @@ namespace NewHorizons.Builder.Body
_unpairedDimensions = new();
}
private static GameObject _atmosphere;
private static GameObject _volumes;
private static GameObject _effects;
private static GameObject _geometry;
private static GameObject _exitWarps;
private static GameObject _repelVolume;
private static Material _material;
internal static void InitPrefabs()
{
if (_atmosphere == null) _atmosphere = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Atmosphere_HubDimension").InstantiateInactive().Rename("Prefab_Bramble_Atmosphere").DontDestroyOnLoad();
if (_volumes == null) _volumes = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Volumes_HubDimension").InstantiateInactive().Rename("Prefab_Bramble_Volumes").DontDestroyOnLoad();
if (_effects == null) _effects = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Effects_HubDimension").InstantiateInactive().Rename("Prefab_Bramble_Effects").DontDestroyOnLoad();
if (_geometry == null) _geometry = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Geometry_HubDimension").InstantiateInactive().Rename("Prefab_Bramble_Geometry").DontDestroyOnLoad();
if (_exitWarps == null) _exitWarps = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/OuterWarp_Hub").InstantiateInactive().Rename("Prefab_Bramble_OuterWarp").DontDestroyOnLoad();
if (_repelVolume == null) _repelVolume = SearchUtilities.Find("DB_HubDimension_Body/BrambleRepelVolume").InstantiateInactive().Rename("Prefab_Bramble_RepelVolume").DontDestroyOnLoad();
if (_material == null) _material = new Material(GameObject.Find("DB_PioneerDimension_Body/Sector_PioneerDimension").GetComponent<EffectRuleset>()._material).DontDestroyOnLoad();
}
public static GameObject Make(NewHorizonsBody body, GameObject go, NHAstroObject ao, Sector sector, OWRigidbody owRigidBody)
{
InitPrefabs();
var config = body.Config.Bramble.dimension;
ao.IsDimension = true;
sector._name = Sector.Name.BrambleDimension;
var atmo = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Atmosphere_HubDimension").InstantiateInactive();
var volumes = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Volumes_HubDimension").InstantiateInactive();
var effects = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Effects_HubDimension").InstantiateInactive();
var atmo = _atmosphere.InstantiateInactive();
var volumes = _volumes.InstantiateInactive();
var effects = _effects.InstantiateInactive();
var prefab = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Geometry_HubDimension");
var detailInfo = new PropModule.DetailInfo();
var geometry = DetailBuilder.Make(go, sector, prefab, detailInfo);
var geometry = DetailBuilder.Make(go, sector, _geometry, detailInfo);
var exitWarps = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/OuterWarp_Hub").InstantiateInactive();
var repelVolume = SearchUtilities.Find("DB_HubDimension_Body/BrambleRepelVolume").InstantiateInactive();
var exitWarps = _exitWarps.InstantiateInactive();
var repelVolume = _repelVolume.InstantiateInactive();
atmo.name = "Atmosphere";
atmo.transform.parent = sector.transform;
@ -124,7 +144,7 @@ namespace NewHorizons.Builder.Body
effectRuleset._underwaterDistortScale = 0.001f;
effectRuleset._underwaterMaxDistort = 0.1f;
effectRuleset._underwaterMinDistort = 0.005f;
effectRuleset._material = GameObject.Find("DB_PioneerDimension_Body/Sector_PioneerDimension").GetComponent<EffectRuleset>()._material; // TODO: cache this
effectRuleset._material = _material;
var antiTravelMusicRuleset = sector.gameObject.AddComponent<AntiTravelMusicRuleset>();
antiTravelMusicRuleset._attachedBody = owRigidBody;

View File

@ -9,18 +9,32 @@ namespace NewHorizons.Builder.Body
{
public static class CloakBuilder
{
public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame, IModBehaviour mod)
{
var radius = module.radius;
private static GameObject _prefab;
var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP");
if (cloak == null)
internal static void InitPrefab()
{
if (_prefab == null)
{
_prefab = SearchUtilities.Find("RingWorld_Body/CloakingField_IP")?.InstantiateInactive()?.Rename("CloakingField")?.DontDestroyOnLoad();
if (_prefab == null)
{
Logger.LogWarning($"Tried to make a cloak but couldn't. Do you have the DLC installed?");
return;
}
else
_prefab.AddComponent<DestroyOnDLC>()._destroyOnDLCNotOwned = true;
}
}
var newCloak = GameObject.Instantiate(cloak, sector?.transform ?? planetGO.transform);
public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame, IModBehaviour mod)
{
InitPrefab();
if (_prefab == null) return;
var radius = module.radius;
var newCloak = GameObject.Instantiate(_prefab, sector?.transform ?? planetGO.transform);
newCloak.transform.position = planetGO.transform.position;
newCloak.transform.name = "CloakingField";
newCloak.transform.localScale = Vector3.one * radius;

View File

@ -5,9 +5,18 @@ namespace NewHorizons.Builder.Body
{
public static class CometTailBuilder
{
private static GameObject _tailPrefab;
internal static void InitPrefab()
{
if (_tailPrefab == null) _tailPrefab = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes").InstantiateInactive().Rename("Prefab_CO_Tail").DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, Sector sector, PlanetConfig config)
{
var cometTail = GameObject.Instantiate(SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes"), sector?.transform ?? planetGO.transform);
InitPrefab();
var cometTail = GameObject.Instantiate(_tailPrefab, sector?.transform ?? planetGO.transform);
cometTail.transform.position = planetGO.transform.position;
cometTail.name = "CometTail";
cometTail.transform.localScale = Vector3.one * config.Base.surfaceSize / 110;

View File

@ -13,8 +13,25 @@ namespace NewHorizons.Builder.Body
private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");
private static readonly int HeightScale = Shader.PropertyToID("_HeightScale");
private static GameObject _proxySandFunnel;
private static GameObject _geoSandFunnel;
private static GameObject _volumesSandFunnel;
private static Material[] _waterMaterials;
private static Material _lavaMaterial;
internal static void InitPrefabs()
{
if (_proxySandFunnel == null) _proxySandFunnel = SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel").InstantiateInactive().Rename("Prefab_Funnel_Proxy").DontDestroyOnLoad();
if (_geoSandFunnel == null) _geoSandFunnel = SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel").InstantiateInactive().Rename("Prefab_Funnel_Geo").DontDestroyOnLoad();
if (_volumesSandFunnel == null) _volumesSandFunnel = SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel").InstantiateInactive().Rename("Prefab_Funnel_Volumes").DontDestroyOnLoad();
if (_waterMaterials == null) _waterMaterials = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Geometry_TH/Terrain_TH_Water_v3/Village_Upper_Water/Village_Upper_Water_Geo").GetComponent<MeshRenderer>().sharedMaterials.MakePrefabMaterials();
if (_lavaMaterial == null) _lavaMaterial = new Material(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent<MeshRenderer>().sharedMaterial).DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, ConstantForceDetector detector, OWRigidbody rigidbody, FunnelModule module)
{
InitPrefabs();
var funnelType = module.type;
var funnelGO = new GameObject($"{planetGO.name.Replace("_Body", "")}Funnel_Body");
@ -43,13 +60,13 @@ namespace NewHorizons.Builder.Body
scaleRoot.transform.localPosition = Vector3.zero;
scaleRoot.transform.localScale = new Vector3(1, 1, 1);
var proxyGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform);
var proxyGO = GameObject.Instantiate(_proxySandFunnel, scaleRoot.transform);
proxyGO.name = "Proxy_Funnel";
var geoGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel"), scaleRoot.transform);
var geoGO = GameObject.Instantiate(_geoSandFunnel, scaleRoot.transform);
geoGO.name = "Geo_Funnel";
var volumesGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform);
var volumesGO = GameObject.Instantiate(_volumesSandFunnel, scaleRoot.transform);
volumesGO.name = "Volumes_Funnel";
var sfv = volumesGO.GetComponentInChildren<SimpleFluidVolume>();
var fluidVolume = sfv.gameObject;
@ -64,7 +81,7 @@ namespace NewHorizons.Builder.Body
GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject);
var waterMaterials = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Geometry_TH/Terrain_TH_Water_v3/Village_Upper_Water/Village_Upper_Water_Geo").GetComponent<MeshRenderer>().materials;
var waterMaterials = _waterMaterials;
var materials = new Material[waterMaterials.Length];
for (int i = 0; i < waterMaterials.Length; i++)
{
@ -112,7 +129,7 @@ namespace NewHorizons.Builder.Body
GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject);
var lavaMaterial = new Material(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent<MeshRenderer>().material);
var lavaMaterial = new Material(_lavaMaterial);
lavaMaterial.mainTextureOffset = new Vector2(0.1f, 0.2f);
lavaMaterial.mainTextureScale = new Vector2(1f, 3f);

View File

@ -4,18 +4,26 @@ namespace NewHorizons.Builder.Body
{
public static class GeometryBuilder
{
private static Mesh _topLayerMesh;
internal static void InitPrefab()
{
if (_topLayerMesh == null) _topLayerMesh = SearchUtilities.Find("CloudsTopLayer_GD")?.GetComponent<MeshFilter>()?.mesh?.DontDestroyOnLoad();
}
public static GameObject Make(GameObject planetGO, Sector sector, float groundScale)
{
InitPrefab();
GameObject groundGO = GameObject.CreatePrimitive(PrimitiveType.Sphere);
groundGO.transform.name = "GroundSphere";
groundGO.transform.parent = sector?.transform ?? planetGO.transform;
groundGO.transform.localScale = new Vector3(groundScale, groundScale, groundScale);
groundGO.transform.position = planetGO.transform.position;
var topLayer = SearchUtilities.Find("CloudsTopLayer_GD");
if (topLayer != null)
if (_topLayerMesh != null)
{
groundGO.GetComponent<MeshFilter>().mesh = topLayer.GetComponent<MeshFilter>().mesh;
groundGO.GetComponent<MeshFilter>().mesh = _topLayerMesh;
groundGO.GetComponent<SphereCollider>().radius = 1f;
}
else

View File

@ -10,8 +10,21 @@ namespace NewHorizons.Builder.Body
private static readonly int HeightScale = Shader.PropertyToID("_HeightScale");
private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");
private static GameObject _lavaSphere;
private static GameObject _moltenCoreProxy;
private static GameObject _destructionVolume;
internal static void InitPrefabs()
{
if (_lavaSphere == null) _lavaSphere = SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").InstantiateInactive().Rename("Prefab_VM_LavaSphere").DontDestroyOnLoad();
if (_moltenCoreProxy == null) _moltenCoreProxy = SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/MoltenCore_Proxy").InstantiateInactive().Rename("Prefab_VM_MoltenCore_Proxy").DontDestroyOnLoad();
if (_destructionVolume == null) _destructionVolume = SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/DestructionVolume").InstantiateInactive().Rename("Prefab_VM_DestructionVolume").DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, Sector sector, OWRigidbody rb, LavaModule module)
{
InitPrefabs();
var heightScale = module.size;
if (module.curve != null)
{
@ -29,7 +42,7 @@ namespace NewHorizons.Builder.Body
moltenCore.transform.position = planetGO.transform.position;
moltenCore.transform.localScale = Vector3.one * module.size;
var lavaSphere = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform);
var lavaSphere = GameObject.Instantiate(_lavaSphere, moltenCore.transform);
lavaSphere.transform.localScale = Vector3.one;
lavaSphere.transform.name = "LavaSphere";
lavaSphere.GetComponent<MeshRenderer>().material.SetFloat(HeightScale, heightScale);
@ -38,7 +51,7 @@ namespace NewHorizons.Builder.Body
var sectorCullGroup = lavaSphere.GetComponent<SectorCullGroup>();
sectorCullGroup.SetSector(sector);
var moltenCoreProxy = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/MoltenCore_Proxy"), moltenCore.transform); ;
var moltenCoreProxy = GameObject.Instantiate(_moltenCoreProxy, moltenCore.transform); ;
moltenCoreProxy.name = "MoltenCore_Proxy";
var proxyLavaSphere = moltenCoreProxy.transform.Find("LavaSphere (1)");
@ -51,7 +64,7 @@ namespace NewHorizons.Builder.Body
sectorProxy._renderers = new List<Renderer> { proxyLavaSphere.GetComponent<MeshRenderer>() };
sectorProxy.SetSector(sector);
var destructionVolume = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/DestructionVolume"), moltenCore.transform);
var destructionVolume = GameObject.Instantiate(_destructionVolume, moltenCore.transform);
destructionVolume.name = "DestructionVolume";
destructionVolume.GetComponent<SphereCollider>().radius = 1;
destructionVolume.SetActive(true);

View File

@ -6,12 +6,28 @@ namespace NewHorizons.Builder.Body
{
public static class SandBuilder
{
private static GameObject _sandSphere;
private static GameObject _sandCollider;
private static GameObject _sandOcclusion;
private static GameObject _sandProxyShadowCaster;
internal static void InitPrefabs()
{
if (_sandSphere == null) _sandSphere = SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/SandSphere").InstantiateInactive().Rename("Prefab_TT_SandSphere").DontDestroyOnLoad();
if (_sandCollider == null) _sandCollider = SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/Collider").InstantiateInactive().Rename("Prefab_TT_SandCollider").DontDestroyOnLoad();
if (_sandOcclusion == null) _sandOcclusion = SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/OcclusionSphere").InstantiateInactive().Rename("Prefab_TT_SandOcclusion").DontDestroyOnLoad();
if (_sandProxyShadowCaster == null) _sandProxyShadowCaster = SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/ProxyShadowCaster").InstantiateInactive().Rename("Prefab_TT_SandProxyShadowCaster").DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, Sector sector, OWRigidbody rb, SandModule module)
{
InitPrefabs();
var sandGO = new GameObject("Sand");
sandGO.SetActive(false);
var sandSphere = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/SandSphere"), sandGO.transform);
var sandSphere = GameObject.Instantiate(_sandSphere, sandGO.transform);
sandSphere.name = "Sphere";
if (module.tint != null)
{
var oldMR = sandSphere.GetComponent<TessellatedSphereRenderer>();
@ -28,13 +44,15 @@ namespace NewHorizons.Builder.Body
sandMR.sharedMaterials[1].color = module.tint.ToColor();
}
var collider = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/Collider"), sandGO.transform);
var sphereCollider = collider.GetComponent<SphereCollider>();
var collider = GameObject.Instantiate(_sandCollider, sandGO.transform);
collider.name = "Collider";
collider.SetActive(true);
var occlusionSphere = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/OcclusionSphere"), sandGO.transform);
var occlusionSphere = GameObject.Instantiate(_sandOcclusion, sandGO.transform);
occlusionSphere.name = "Occlusion";
var proxyShadowCasterGO = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/ProxyShadowCaster"), sandGO.transform);
var proxyShadowCasterGO = GameObject.Instantiate(_sandProxyShadowCaster, sandGO.transform);
proxyShadowCasterGO.name = "ProxyShadowCaster";
var proxyShadowCaster = proxyShadowCasterGO.GetComponent<ProxyShadowCaster>();
proxyShadowCaster.SetSuperGroup(sandGO.GetComponent<ProxyShadowCasterSuperGroup>());

View File

@ -30,8 +30,41 @@ namespace NewHorizons.Builder.Body
private static Dictionary<string, GameObject> _singularitiesByID;
private static Mesh _blackHoleMesh;
private static GameObject _blackHoleAmbience;
private static GameObject _blackHoleEmissionOneShot;
private static GameObject _blackHoleVolume;
private static Mesh _whiteHoleMesh;
private static GameObject _whiteHoleAmbientLight;
private static GameObject _whiteHoleZeroGVolume;
private static GameObject _whiteHoleRulesetVolume;
private static GameObject _whiteHoleVolume;
internal static void InitPrefabs()
{
if (_blackHoleProxyPrefab == null) _blackHoleProxyPrefab = SearchUtilities.Find(_blackHoleProxyPath).InstantiateInactive().Rename("BlackHoleSingularity").DontDestroyOnLoad();
if (_whiteHoleProxyPrefab == null) _whiteHoleProxyPrefab = SearchUtilities.Find(_whiteHoleProxyPath).InstantiateInactive().Rename("WhiteHoleSingularity").DontDestroyOnLoad();
if (blackHoleShader == null) blackHoleShader = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshRenderer>().sharedMaterial.shader;
if (whiteHoleShader == null) whiteHoleShader = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshRenderer>().sharedMaterial.shader;
if (_blackHoleMesh == null) _blackHoleMesh = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshFilter>().mesh.DontDestroyOnLoad();
if (_blackHoleAmbience == null) _blackHoleAmbience = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleAmbience").InstantiateInactive().Rename("BlackHoleAmbience").DontDestroyOnLoad();
if (_blackHoleEmissionOneShot == null) _blackHoleEmissionOneShot = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleEmissionOneShot").InstantiateInactive().Rename("BlackHoleEmissionOneShot").DontDestroyOnLoad();
if (_blackHoleVolume == null) _blackHoleVolume = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume").InstantiateInactive().Rename("BlackHoleVolume").DontDestroyOnLoad();
if (_whiteHoleMesh == null) _whiteHoleMesh = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshFilter>().mesh.DontDestroyOnLoad();
if (_whiteHoleAmbientLight == null) _whiteHoleAmbientLight = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH").InstantiateInactive().Rename("WhiteHoleAmbientLight").DontDestroyOnLoad();
if (_whiteHoleZeroGVolume == null) _whiteHoleZeroGVolume = SearchUtilities.Find("WhiteHole_Body/ZeroGVolume").InstantiateInactive().Rename("WhiteHoleZeroGVolume").DontDestroyOnLoad();
if (_whiteHoleRulesetVolume == null) _whiteHoleRulesetVolume = SearchUtilities.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole").InstantiateInactive().Rename("WhiteHoleRulesetVolume").DontDestroyOnLoad();
if (_whiteHoleVolume == null) _whiteHoleVolume = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVolume").InstantiateInactive().Rename("WhiteHoleVolume").DontDestroyOnLoad();
}
public static void Make(GameObject go, Sector sector, OWRigidbody OWRB, PlanetConfig config, SingularityModule singularity)
{
InitPrefabs();
// If we've reloaded the first one will now be null so we have to refresh the list
if (_singularitiesByID?.Values?.FirstOrDefault() == null) _singularitiesByID = new Dictionary<string, GameObject>();
@ -81,6 +114,8 @@ namespace NewHorizons.Builder.Body
public static void PairSingularities(string blackHoleID, string whiteHoleID, GameObject blackHole, GameObject whiteHole)
{
InitPrefabs();
if (blackHole == null || whiteHole == null) return;
Logger.LogVerbose($"Pairing singularities [{blackHoleID}], [{whiteHoleID}]");
@ -102,6 +137,8 @@ namespace NewHorizons.Builder.Body
public static GameObject MakeBlackHole(GameObject planetGO, Sector sector, Vector3 localPosition, float size,
bool hasDestructionVolume, string targetSolarSystem = null, TimeValuePair[] curve = null, bool makeAudio = true)
{
InitPrefabs();
var blackHole = new GameObject("BlackHole");
blackHole.SetActive(false);
blackHole.transform.parent = sector?.transform ?? planetGO.transform;
@ -120,7 +157,7 @@ namespace NewHorizons.Builder.Body
if (makeAudio)
{
var blackHoleAmbience = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleAmbience"), blackHole.transform);
var blackHoleAmbience = GameObject.Instantiate(_blackHoleAmbience, blackHole.transform);
blackHoleAmbience.name = "BlackHoleAmbience";
blackHoleAmbience.GetComponent<SectorAudioGroup>().SetSector(sector);
@ -130,7 +167,7 @@ namespace NewHorizons.Builder.Body
blackHoleAmbience.transform.localPosition = Vector3.zero;
if (sizeController != null) sizeController.audioSource = blackHoleAudioSource;
var blackHoleOneShot = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleEmissionOneShot"), blackHole.transform);
var blackHoleOneShot = GameObject.Instantiate(_blackHoleEmissionOneShot, blackHole.transform);
blackHoleOneShot.name = "BlackHoleEmissionOneShot";
var oneShotAudioSource = blackHoleOneShot.GetComponent<AudioSource>();
oneShotAudioSource.maxDistance = size * 3f;
@ -160,7 +197,7 @@ namespace NewHorizons.Builder.Body
}
else
{
var blackHoleVolume = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume"), blackHole.transform);
var blackHoleVolume = GameObject.Instantiate(_blackHoleVolume, blackHole.transform);
blackHoleVolume.name = "BlackHoleVolume";
var blackHoleSphereCollider = blackHoleVolume.GetComponent<SphereCollider>();
blackHoleSphereCollider.radius = size * 0.4f;
@ -173,16 +210,17 @@ namespace NewHorizons.Builder.Body
public static MeshRenderer MakeBlackHoleGraphics(GameObject blackHole, float size)
{
InitPrefabs();
var blackHoleRender = new GameObject("BlackHoleRender");
blackHoleRender.transform.parent = blackHole.transform;
blackHoleRender.transform.localPosition = Vector3.zero;
blackHoleRender.transform.localScale = Vector3.one * size;
var meshFilter = blackHoleRender.AddComponent<MeshFilter>();
meshFilter.mesh = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshFilter>().mesh;
meshFilter.mesh = _blackHoleMesh;
var meshRenderer = blackHoleRender.AddComponent<MeshRenderer>();
if (blackHoleShader == null) blackHoleShader = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshRenderer>().sharedMaterial.shader;
meshRenderer.material = new Material(blackHoleShader);
meshRenderer.material.SetFloat(Radius, size * 0.4f);
meshRenderer.material.SetFloat(MaxDistortRadius, size * 0.95f);
@ -195,6 +233,8 @@ namespace NewHorizons.Builder.Body
public static GameObject MakeWhiteHole(GameObject planetGO, Sector sector, OWRigidbody OWRB, Vector3 localPosition, float size,
TimeValuePair[] curve, bool makeZeroGVolume = true)
{
InitPrefabs();
var whiteHole = new GameObject("WhiteHole");
whiteHole.SetActive(false);
whiteHole.transform.parent = sector?.transform ?? planetGO.transform;
@ -214,10 +254,9 @@ namespace NewHorizons.Builder.Body
}
var meshFilter = whiteHoleRenderer.AddComponent<MeshFilter>();
meshFilter.mesh = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshFilter>().mesh;
meshFilter.mesh = _whiteHoleMesh;
var meshRenderer = whiteHoleRenderer.AddComponent<MeshRenderer>();
if (whiteHoleShader == null) whiteHoleShader = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshRenderer>().sharedMaterial.shader;
meshRenderer.material = new Material(whiteHoleShader);
meshRenderer.sharedMaterial.SetFloat(Radius, size * 0.4f);
meshRenderer.sharedMaterial.SetFloat(DistortFadeDist, size);
@ -226,7 +265,7 @@ namespace NewHorizons.Builder.Body
meshRenderer.sharedMaterial.SetColor(Color1, new Color(1.88f, 1.88f, 1.88f, 1f));
if (sizeController != null) sizeController.material = meshRenderer.sharedMaterial;
var ambientLight = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH"));
var ambientLight = GameObject.Instantiate(_whiteHoleAmbientLight);
ambientLight.transform.parent = whiteHole.transform;
ambientLight.transform.localScale = Vector3.one;
ambientLight.transform.localPosition = Vector3.zero;
@ -235,7 +274,7 @@ namespace NewHorizons.Builder.Body
light.range = size * 7f;
if (sizeController != null) sizeController.light = light;
GameObject whiteHoleVolumeGO = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/WhiteHoleVolume"));
GameObject whiteHoleVolumeGO = GameObject.Instantiate(_whiteHoleVolume);
whiteHoleVolumeGO.transform.parent = whiteHole.transform;
whiteHoleVolumeGO.transform.localPosition = Vector3.zero;
whiteHoleVolumeGO.transform.localScale = Vector3.one;
@ -264,13 +303,13 @@ namespace NewHorizons.Builder.Body
if (makeZeroGVolume)
{
var zeroGVolume = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/ZeroGVolume"), whiteHole.transform);
var zeroGVolume = GameObject.Instantiate(_whiteHoleZeroGVolume, whiteHole.transform);
zeroGVolume.name = "ZeroGVolume";
zeroGVolume.transform.localPosition = Vector3.zero;
zeroGVolume.GetComponent<SphereCollider>().radius = size * 10f;
zeroGVolume.GetComponent<ZeroGVolume>()._attachedBody = OWRB;
var rulesetVolume = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole"), planetGO.transform);
var rulesetVolume = GameObject.Instantiate(_whiteHoleRulesetVolume, planetGO.transform);
rulesetVolume.name = "RulesetVolume";
rulesetVolume.transform.localPosition = Vector3.zero;
rulesetVolume.transform.localScale = Vector3.one * size / 100f;
@ -289,7 +328,7 @@ namespace NewHorizons.Builder.Body
public static GameObject MakeBlackHoleProxy(GameObject rootObject, MVector3 position, float size, TimeValuePair[] curve = null)
{
if (_blackHoleProxyPrefab == null) _blackHoleProxyPrefab = SearchUtilities.Find(_blackHoleProxyPath);
InitPrefabs();
var blackHoleShader = _blackHoleProxyPrefab.GetComponent<MeshRenderer>().material.shader;
if (blackHoleShader == null) blackHoleShader = _blackHoleProxyPrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;
@ -318,7 +357,7 @@ namespace NewHorizons.Builder.Body
public static GameObject MakeWhiteHoleProxy(GameObject rootObject, MVector3 position, float size, TimeValuePair[] curve = null)
{
if (_whiteHoleProxyPrefab == null) _whiteHoleProxyPrefab = SearchUtilities.Find(_whiteHoleProxyPath);
InitPrefabs();
var whiteHoleShader = _whiteHoleProxyPrefab.GetComponent<MeshRenderer>().material.shader;
if (whiteHoleShader == null) whiteHoleShader = _whiteHoleProxyPrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;

View File

@ -23,11 +23,39 @@ namespace NewHorizons.Builder.Body
private static readonly int InnerRadius = Shader.PropertyToID("_InnerRadius");
private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius");
private static GameObject _starAudio;
private static GameObject _starAtmosphere;
private static GameObject _starProxyAtmosphere;
private static GameObject _starAmbientLight;
private static GameObject _sunLight;
private static GameObject _starSurface;
private static GameObject _starSolarFlareEmitter;
private static GameObject _supernovaPrefab;
private static Material _mainSequenceMaterial;
private static Material _giantMaterial;
internal static void InitPrefabs()
{
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/StarColorOverTime.png");
if (_starAudio == null) _starAudio = SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN").InstantiateInactive().Rename("Prefab_Audio_Star").DontDestroyOnLoad();
if (_starAtmosphere == null) _starAtmosphere = SearchUtilities.Find("Sun_Body/Atmosphere_SUN").InstantiateInactive().Rename("Prefab_Atmosphere_Star").DontDestroyOnLoad();
if (_starAmbientLight == null) _starAmbientLight = SearchUtilities.Find("Sun_Body/AmbientLight_SUN").InstantiateInactive().Rename("Prefab_AmbientLight_Star").DontDestroyOnLoad();
if (_sunLight == null) _sunLight = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").InstantiateInactive().Rename("Prefab_SunLight").DontDestroyOnLoad();
if (_starProxyAtmosphere == null) _starProxyAtmosphere = GameObject.FindObjectOfType<DistantProxyManager>()._sunProxyPrefab.FindChild("Sun_Proxy_Body/Atmosphere_SUN").InstantiateInactive().Rename("Prefab_ProxyAtmosphere_Star").DontDestroyOnLoad();
if (_starSurface == null) _starSurface = SearchUtilities.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface").InstantiateInactive().Rename("Prefab_Surface_Star").DontDestroyOnLoad();
if (_starSolarFlareEmitter == null) _starSolarFlareEmitter = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter").InstantiateInactive().Rename("Prefab_SolarFlareEmitter_Star").DontDestroyOnLoad();
if (_supernovaPrefab == null) _supernovaPrefab = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive().Rename("Prefab_Supernova").DontDestroyOnLoad();
if (_mainSequenceMaterial == null) _mainSequenceMaterial = new Material(SearchUtilities.Find("Sun_Body").GetComponent<SunController>()._startSurfaceMaterial).DontDestroyOnLoad();
if (_giantMaterial == null) _giantMaterial = new Material(SearchUtilities.Find("Sun_Body").GetComponent<SunController>()._endSurfaceMaterial).DontDestroyOnLoad();
}
public static (GameObject, StarController, StarEvolutionController) Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)
{
InitPrefabs();
var (starGO, starEvolutionController, supernova) = SharedStarGeneration(planetGO, sector, mod, starModule, isStellarRemnant);
var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform);
var sunAudio = Object.Instantiate(_starAudio, starGO.transform);
sunAudio.transform.localPosition = Vector3.zero;
sunAudio.transform.localScale = Vector3.one;
sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent<AudioSource>().maxDistance = starModule.size * 2f;
@ -42,7 +70,7 @@ namespace NewHorizons.Builder.Body
GameObject sunAtmosphere = null;
if (starModule.hasAtmosphere)
{
sunAtmosphere = Object.Instantiate(SearchUtilities.Find("Sun_Body/Atmosphere_SUN"), starGO.transform);
sunAtmosphere = Object.Instantiate(_starAtmosphere, starGO.transform);
sunAtmosphere.transform.position = planetGO.transform.position;
sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio;
sunAtmosphere.name = "Atmosphere_Star";
@ -71,7 +99,7 @@ namespace NewHorizons.Builder.Body
}
}
var ambientLightGO = Object.Instantiate(SearchUtilities.Find("Sun_Body/AmbientLight_SUN"), starGO.transform);
var ambientLightGO = Object.Instantiate(_starAmbientLight, starGO.transform);
ambientLightGO.transform.localPosition = Vector3.zero;
ambientLightGO.name = "AmbientLight_Star";
@ -123,7 +151,7 @@ namespace NewHorizons.Builder.Body
sunLight.transform.localScale = Vector3.one;
var light = sunLight.AddComponent<Light>();
light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
light.CopyPropertiesFrom(_sunLight.GetComponent<Light>());
light.intensity *= starModule.solarLuminosity;
light.range = starModule.lightRadius;
light.range *= Mathf.Sqrt(starModule.solarLuminosity);
@ -135,12 +163,12 @@ namespace NewHorizons.Builder.Body
ambientLight.color = new Color(lightColour.r, lightColour.g, lightColour.b, lightColour.a == 0 ? 0.0001f : lightColour.a);
var faceActiveCamera = sunLight.AddComponent<FaceActiveCamera>();
faceActiveCamera.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<FaceActiveCamera>());
faceActiveCamera.CopyPropertiesFrom(_sunLight.GetComponent<FaceActiveCamera>());
var csmTextureCacher = sunLight.AddComponent<CSMTextureCacher>();
csmTextureCacher.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<CSMTextureCacher>());
csmTextureCacher.CopyPropertiesFrom(_sunLight.GetComponent<CSMTextureCacher>());
csmTextureCacher._light = light;
var proxyShadowLight = sunLight.AddComponent<ProxyShadowLight>();
proxyShadowLight.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<ProxyShadowLight>());
proxyShadowLight.CopyPropertiesFrom(_sunLight.GetComponent<ProxyShadowLight>());
proxyShadowLight._light = light;
// Star controller (works on atmospheric shaders)
@ -187,13 +215,15 @@ namespace NewHorizons.Builder.Body
public static (GameObject, Renderer, Renderer) MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)
{
InitPrefabs();
var (starGO, controller, supernova) = SharedStarGeneration(proxyGO, null, mod, starModule, isStellarRemnant);
Renderer atmosphere = null;
Renderer fog = null;
if (starModule.hasAtmosphere)
{
GameObject sunAtmosphere = Object.Instantiate(SearchUtilities.Find("SunProxy/Sun_Proxy_Body/Atmosphere_SUN", false) ?? SearchUtilities.Find("SunProxy(Clone)/Sun_Proxy_Body/Atmosphere_SUN"), starGO.transform);
GameObject sunAtmosphere = Object.Instantiate(_starProxyAtmosphere, starGO.transform);
sunAtmosphere.transform.position = proxyGO.transform.position;
sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio;
sunAtmosphere.name = "Atmosphere_Star";
@ -236,6 +266,8 @@ namespace NewHorizons.Builder.Body
private static (GameObject, StarEvolutionController, StellarDeathController) SharedStarGeneration(GameObject planetGO, Sector sector, IModBehaviour mod, StarModule starModule, bool isStellarRemnant)
{
InitPrefabs();
var starGO = MakeStarGraphics(planetGO, sector, starModule, mod);
starGO.SetActive(false);
@ -280,17 +312,17 @@ namespace NewHorizons.Builder.Body
public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule, IModBehaviour mod)
{
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/StarColorOverTime.png");
InitPrefabs();
var starGO = new GameObject("Star");
starGO.transform.parent = sector?.transform ?? rootObject.transform;
var sunSurface = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform);
var sunSurface = Object.Instantiate(_starSurface, starGO.transform);
sunSurface.transform.position = rootObject.transform.position;
sunSurface.transform.localScale = Vector3.one;
sunSurface.name = "Surface";
var solarFlareEmitter = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform);
var solarFlareEmitter = Object.Instantiate(_starSolarFlareEmitter, starGO.transform);
solarFlareEmitter.transform.localPosition = Vector3.zero;
solarFlareEmitter.transform.localScale = Vector3.one;
solarFlareEmitter.name = "SolarFlareEmitter";
@ -318,11 +350,7 @@ namespace NewHorizons.Builder.Body
{
var colour = starModule.tint.ToColor();
var sun = SearchUtilities.Find("Sun_Body");
var mainSequenceMaterial = sun.GetComponent<SunController>()._startSurfaceMaterial;
var giantMaterial = sun.GetComponent<SunController>()._endSurfaceMaterial;
surface.sharedMaterial = new Material(starModule.size >= 3000 ? giantMaterial : mainSequenceMaterial);
surface.sharedMaterial = new Material(starModule.size >= 3000 ? _giantMaterial : _mainSequenceMaterial);
var modifier = Mathf.Max(1f, 2f * Mathf.Sqrt(starModule.solarLuminosity));
var adjustedColour = new Color(colour.r * modifier, colour.g * modifier, colour.b * modifier);
surface.sharedMaterial.color = adjustedColour;
@ -353,7 +381,9 @@ namespace NewHorizons.Builder.Body
public static StellarDeathController MakeSupernova(GameObject starGO, StarModule starModule, bool noAudio = false)
{
var supernovaGO = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive();
InitPrefabs();
var supernovaGO = _supernovaPrefab.InstantiateInactive();
supernovaGO.name = "Supernova";
supernovaGO.transform.SetParent(starGO.transform);
supernovaGO.transform.localPosition = Vector3.zero;

View File

@ -10,10 +10,18 @@ namespace NewHorizons.Builder.Body
{
public static class SupernovaEffectBuilder
{
private static Mesh _shockLayerMesh;
private static Material _shockLayerMaterial;
internal static void InitPrefabs()
{
if (_shockLayerMesh == null) _shockLayerMesh = SearchUtilities.Find("GiantsDeep_Body/Shocklayer_GD").GetComponent<MeshFilter>().sharedMesh.DontDestroyOnLoad();
if (_shockLayerMaterial == null) _shockLayerMaterial = new Material(SearchUtilities.Find("GiantsDeep_Body/Shocklayer_GD").GetComponent<MeshRenderer>().sharedMaterial).Rename("ShockLayer_mat").DontDestroyOnLoad();
}
public static NHSupernovaPlanetEffectController Make(GameObject planetGO, Sector sector, PlanetConfig config, IModBehaviour mod, GameObject procGen, Light ambientLight, PlanetaryFogController fog, LODGroup atmosphere, Renderer atmosphereRenderer, Renderer fogImpostor)
{
var shockLayerGD = SearchUtilities.Find("GiantsDeep_Body/Shocklayer_GD");
if (shockLayerGD == null) return null;
InitPrefabs();
var vanillaController = planetGO.GetComponentInChildren<SupernovaPlanetEffectController>();
if (vanillaController != null)
@ -53,13 +61,10 @@ namespace NewHorizons.Builder.Body
var shockLayer = new GameObject("ShockLayer");
shockLayer.transform.SetParent(sector?.transform ?? planetGO.transform, false);
shockLayer.AddComponent<MeshFilter>().sharedMesh = shockLayerGD.GetComponent<MeshFilter>().sharedMesh;
var shockLayerMaterial = new Material(shockLayerGD.GetComponent<MeshRenderer>().sharedMaterial);
shockLayerMaterial.name = "ShockLayer_mat";
shockLayer.AddComponent<MeshFilter>().sharedMesh = _shockLayerMesh;
var shockLayerRenderer = shockLayer.AddComponent<MeshRenderer>();
shockLayerRenderer.sharedMaterial = shockLayerMaterial;
shockLayerRenderer.sharedMaterial = new Material(_shockLayerMaterial);
supernovaEffectController._shockLayer = shockLayerRenderer;
var biggestSize = config.Base.surfaceSize;
@ -180,7 +185,7 @@ namespace NewHorizons.Builder.Body
supernovaEffectController.shockLayerStartRadius = vanillaController._shockLayerStartRadius;
supernovaEffectController.shockLayerTrailFlare = vanillaController._shockLayerTrailFlare;
supernovaEffectController.shockLayerTrailLength = vanillaController._shockLayerTrailLength;
supernovaEffectController.SunController = SearchUtilities.Find("Sun_Body").GetComponent<SunController>();
supernovaEffectController.SunController = SearchUtilities.Find("Sun_Body")?.GetComponent<SunController>();
Object.Destroy(vanillaController);
}
}

View File

@ -9,8 +9,33 @@ namespace NewHorizons.Builder.Body
{
public static class WaterBuilder
{
private static MeshGroup _oceanMeshGroup;
private static Material[] _oceanLowAltitudeMaterials;
private static GameObject _oceanFog;
internal static void InitPrefabs()
{
if (_oceanMeshGroup == null)
{
_oceanMeshGroup = ScriptableObject.CreateInstance<MeshGroup>().Rename("Ocean").DontDestroyOnLoad();
var gdVariants = SearchUtilities.Find("Ocean_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup.variants;
for (int i = 0; i < 16; i++)
{
var mesh = new Mesh();
mesh.CopyPropertiesFrom(gdVariants[i]);
mesh.name = gdVariants[i].name;
mesh.DontDestroyOnLoad();
_oceanMeshGroup.variants[i] = mesh;
}
}
if (_oceanLowAltitudeMaterials == null) _oceanLowAltitudeMaterials = SearchUtilities.Find("Ocean_GD").GetComponent<TessellatedSphereLOD>()._lowAltitudeMaterials.MakePrefabMaterials();
if (_oceanFog == null) _oceanFog = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/OceanFog").InstantiateInactive().Rename("Prefab_GD_OceanFog").DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, Sector sector, OWRigidbody rb, WaterModule module)
{
InitPrefabs();
var waterSize = module.size;
GameObject waterGO = new GameObject("Water");
@ -19,18 +44,16 @@ namespace NewHorizons.Builder.Body
waterGO.transform.parent = sector?.transform ?? planetGO.transform;
waterGO.transform.localScale = new Vector3(waterSize, waterSize, waterSize);
var GDTSR = SearchUtilities.Find("Ocean_GD").GetComponent<TessellatedSphereRenderer>();
TessellatedSphereRenderer TSR = waterGO.AddComponent<TessellatedSphereRenderer>();
TSR.tessellationMeshGroup = ScriptableObject.CreateInstance<MeshGroup>();
for (int i = 0; i < 16; i++)
{
var mesh = new Mesh();
mesh.CopyPropertiesFrom(GDTSR.tessellationMeshGroup.variants[i]);
mesh.CopyPropertiesFrom(_oceanMeshGroup.variants[i]);
TSR.tessellationMeshGroup.variants[i] = mesh;
}
var GDSharedMaterials = SearchUtilities.Find("Ocean_GD").GetComponent<TessellatedSphereLOD>()._lowAltitudeMaterials;
var GDSharedMaterials = _oceanLowAltitudeMaterials;
var tempArray = new Material[GDSharedMaterials.Length];
for (int i = 0; i < GDSharedMaterials.Length; i++)
{
@ -49,10 +72,9 @@ namespace NewHorizons.Builder.Body
OEC._sector = sector;
OEC._ocean = TSR;
var GDOLC = GDTSR.GetComponent<OceanLODController>();
var OLC = waterGO.AddComponent<OceanLODController>();
OLC._sector = sector;
OLC._ambientLight = GDOLC._ambientLight; // this needs to be set or else is black
OLC._ambientLight = null; // this needs to be set or else is black
// trigger sector enter
Delay.FireOnNextUpdate(() =>
@ -87,7 +109,7 @@ namespace NewHorizons.Builder.Body
fluidVolume._radius = waterSize;
fluidVolume._layer = LayerMask.NameToLayer("BasicEffectVolume");
var fogGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/OceanFog"), waterGO.transform);
var fogGO = GameObject.Instantiate(_oceanFog, waterGO.transform);
fogGO.name = "OceanFog";
fogGO.transform.localPosition = Vector3.zero;
fogGO.transform.localScale = Vector3.one;

View File

@ -8,8 +8,69 @@ namespace NewHorizons.Builder.General
{
public static class DetectorBuilder
{
private static List<SplashEffect> _splashEffects;
internal static void InitPrefabs()
{
if (_splashEffects == null)
{
_splashEffects = new List<SplashEffect>();
var cometDetector = SearchUtilities.Find("Comet_Body/Detector_CO")?.GetComponent<FluidDetector>();
if (cometDetector != null)
{
foreach (var splashEffect in cometDetector._splashEffects)
{
_splashEffects.Add(new SplashEffect
{
fluidType = splashEffect.fluidType,
ignoreSphereAligment = splashEffect.ignoreSphereAligment,
triggerEvent = splashEffect.triggerEvent,
minImpactSpeed = 15,
splashPrefab = splashEffect.splashPrefab
});
}
}
var islandDetector = SearchUtilities.Find("GabbroIsland_Body/Detector_GabbroIsland")?.GetComponent<FluidDetector>();
if (islandDetector != null)
{
foreach (var splashEffect in islandDetector._splashEffects)
{
_splashEffects.Add(new SplashEffect
{
fluidType = splashEffect.fluidType,
ignoreSphereAligment = splashEffect.ignoreSphereAligment,
triggerEvent = splashEffect.triggerEvent,
minImpactSpeed = 15,
splashPrefab = splashEffect.splashPrefab
});
}
}
var shipDetector = SearchUtilities.Find("Ship_Body/ShipDetector")?.GetComponent<FluidDetector>();
if (shipDetector != null)
{
foreach (var splashEffect in shipDetector._splashEffects)
{
if (splashEffect.fluidType == FluidVolume.Type.SAND)
_splashEffects.Add(new SplashEffect
{
fluidType = splashEffect.fluidType,
ignoreSphereAligment = splashEffect.ignoreSphereAligment,
triggerEvent = splashEffect.triggerEvent,
minImpactSpeed = 15,
splashPrefab = splashEffect.splashPrefab
});
}
}
}
}
public static GameObject Make(GameObject planetGO, OWRigidbody OWRB, AstroObject primaryBody, AstroObject astroObject, PlanetConfig config)
{
InitPrefabs();
GameObject detectorGO = new GameObject("FieldDetector");
detectorGO.SetActive(false);
detectorGO.transform.parent = planetGO.transform;
@ -35,58 +96,7 @@ namespace NewHorizons.Builder.General
OWRB.RegisterAttachedFluidDetector(fluidDetector);
var splashEffects = new List<SplashEffect>();
var cometDetector = SearchUtilities.Find("Comet_Body/Detector_CO")?.GetComponent<FluidDetector>();
if (cometDetector != null)
{
foreach (var splashEffect in cometDetector._splashEffects)
{
splashEffects.Add(new SplashEffect
{
fluidType = splashEffect.fluidType,
ignoreSphereAligment = splashEffect.ignoreSphereAligment,
triggerEvent = splashEffect.triggerEvent,
minImpactSpeed = 15,
splashPrefab = splashEffect.splashPrefab
});
}
}
var islandDetector = SearchUtilities.Find("GabbroIsland_Body/Detector_GabbroIsland")?.GetComponent<FluidDetector>();
if (islandDetector != null)
{
foreach (var splashEffect in islandDetector._splashEffects)
{
splashEffects.Add(new SplashEffect
{
fluidType = splashEffect.fluidType,
ignoreSphereAligment = splashEffect.ignoreSphereAligment,
triggerEvent = splashEffect.triggerEvent,
minImpactSpeed = 15,
splashPrefab = splashEffect.splashPrefab
});
}
}
var shipDetector = SearchUtilities.Find("Ship_Body/ShipDetector")?.GetComponent<FluidDetector>();
if (shipDetector != null)
{
foreach (var splashEffect in shipDetector._splashEffects)
{
if (splashEffect.fluidType == FluidVolume.Type.SAND)
splashEffects.Add(new SplashEffect
{
fluidType = splashEffect.fluidType,
ignoreSphereAligment = splashEffect.ignoreSphereAligment,
triggerEvent = splashEffect.triggerEvent,
minImpactSpeed = 15,
splashPrefab = splashEffect.splashPrefab
});
}
}
fluidDetector._splashEffects = splashEffects.ToArray();
fluidDetector._splashEffects = _splashEffects.ToArray();
}
if (!config.Orbit.isStatic) SetDetector(primaryBody, astroObject, forceDetector);

View File

@ -27,7 +27,7 @@ namespace NewHorizons.Builder.General
owRigidBody._maintainOriginalCenterOfMass = true;
owRigidBody._rigidbody = rigidBody;
owRigidBody._kinematicRigidbody = kinematicRigidBody;
owRigidBody._origParent = SearchUtilities.Find("SolarSystemRoot").transform;
owRigidBody._origParent = SearchUtilities.Find("SolarSystemRoot")?.transform;
owRigidBody.EnableKinematicSimulation();
owRigidBody.MakeKinematic();

View File

@ -47,6 +47,8 @@ namespace NewHorizons.Builder.General
spawnPoint._triggerVolumes = new OWTriggerVolume[0];
var ship = SearchUtilities.Find("Ship_Body");
if (ship != null)
{
ship.transform.position = spawnPoint.transform.position;
if (module.shipSpawnRotation != null)
@ -76,6 +78,7 @@ namespace NewHorizons.Builder.General
playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
}
}
if ((Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && module.startWithSuit)) && !suitUpQueued)
{

View File

@ -28,8 +28,8 @@ namespace NewHorizons.Builder.Props
public static readonly Dictionary<string, InnerFogWarpVolume> namedNodes = new();
public static readonly Dictionary<BrambleNodeInfo, GameObject> builtBrambleNodes = new();
private static string _brambleSeedPrefabPath = "DB_PioneerDimension_Body/Sector_PioneerDimension/Interactables_PioneerDimension/SeedWarp_ToPioneer (1)";
private static string _brambleNodePrefabPath = "DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster";
private static GameObject _brambleSeedPrefab;
private static GameObject _brambleNodePrefab;
public static void Init(PlanetConfig[] dimensionConfigs)
{
@ -41,6 +41,12 @@ namespace NewHorizons.Builder.Props
PropagateSignals(dimensionConfigs);
}
internal static void InitPrefabs()
{
if (_brambleSeedPrefab == null) _brambleSeedPrefab = SearchUtilities.Find("DB_PioneerDimension_Body/Sector_PioneerDimension/Interactables_PioneerDimension/SeedWarp_ToPioneer (1)").InstantiateInactive().Rename("Prefab_DB_Seed").DontDestroyOnLoad();
if (_brambleNodePrefab == null) _brambleNodePrefab = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster").InstantiateInactive().Rename("Prefab_DB_Node").DontDestroyOnLoad();
}
public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null)
{
Logger.LogVerbose($"Pairing missed for {dimensionName}");
@ -165,7 +171,9 @@ namespace NewHorizons.Builder.Props
public static GameObject Make(GameObject go, Sector sector, BrambleNodeInfo config, IModBehaviour mod)
{
var prefab = SearchUtilities.Find(config.isSeed ? _brambleSeedPrefabPath : _brambleNodePrefabPath);
InitPrefabs();
var prefab = config.isSeed ? _brambleSeedPrefab : _brambleNodePrefab;
// Spawn the bramble node
var brambleNode = prefab.InstantiateInactive();

View File

@ -5,9 +5,18 @@ namespace NewHorizons.Builder.Props
{
public static class GeyserBuilder
{
private static GameObject _geyserPrefab;
internal static void InitPrefab()
{
if (_geyserPrefab == null) _geyserPrefab = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Interactables_TH/Geysers/Geyser_Village").InstantiateInactive().Rename("Prefab_TH_Geyser").DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, Sector sector, PropModule.GeyserInfo info)
{
var geyserGO = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Interactables_TH/Geysers/Geyser_Village").InstantiateInactive();
InitPrefab();
var geyserGO = _geyserPrefab.InstantiateInactive();
geyserGO.transform.parent = sector?.transform ?? planetGO.transform;
geyserGO.name = "Geyser";

View File

@ -45,53 +45,11 @@ namespace NewHorizons.Builder.Props
public static List<GameObject> GetChildArcPrefabs() { return _childArcPrefabs; }
public static List<GameObject> GetGhostArcPrefabs() { return _ghostArcPrefabs; }
private static void InitPrefabs()
{
if (Main.Instance.CurrentStarSystem == "EyeOfTheUniverse")
{
// Just take every wall text and get the first arc
var existingArcs = GameObject.FindObjectsOfType<NomaiWallText>().Select(x => x?.gameObject?.transform?.Find("Arc 1")?.gameObject).Where(x => x != null).ToArray();
_arcPrefabs = new List<GameObject>();
_childArcPrefabs = new List<GameObject>();
_ghostArcPrefabs = new List<GameObject>();
foreach (var existingArc in existingArcs)
{
var arc = existingArc.InstantiateInactive();
arc.name = "Arc";
_arcPrefabs.Add(arc);
}
_scrollPrefab = new GameObject("Prefab_NOM_Scroll");
_scrollPrefab.SetActive(false);
_scrollPrefab.transform.rotation = Quaternion.identity;
_computerPrefab = new GameObject("Prefab_NOM_Computer");
_computerPrefab.SetActive(false);
_computerPrefab.transform.rotation = Quaternion.identity;
_preCrashComputerPrefab = new GameObject("Prefab_NOM_Vessel_Computer");
_preCrashComputerPrefab.SetActive(false);
_preCrashComputerPrefab.transform.rotation = Quaternion.identity;
_cairnPrefab = new GameObject("Prefab_NOM_Cairn");
_cairnPrefab.SetActive(false);
_cairnPrefab.transform.rotation = Quaternion.identity;
_recorderPrefab = new GameObject("Prefab_NOM_Recorder");
_recorderPrefab.SetActive(false);
_recorderPrefab.transform.rotation = Quaternion.identity;
_preCrashRecorderPrefab = SearchUtilities.Find("Vessel_Body/Sector_VesselBridge/Interactibles_VesselBridge/Prefab_NOM_Recorder").InstantiateInactive();
_preCrashRecorderPrefab.name = "Prefab_NOM_Recorder_Vessel";
_preCrashRecorderPrefab.transform.rotation = Quaternion.identity;
_trailmarkerPrefab = new GameObject("Prefab_NOM_Trailmarker");
_trailmarkerPrefab.SetActive(false);
_trailmarkerPrefab.transform.rotation = Quaternion.identity;
}
else
internal static void InitPrefabs()
{
// Just take every scroll and get the first arc
if (_arcPrefabs == null || _childArcPrefabs == null)
{
var existingArcs = GameObject.FindObjectsOfType<ScrollItem>().Select(x => x?._nomaiWallText?.gameObject?.transform?.Find("Arc 1")?.gameObject).Where(x => x != null).ToArray();
_arcPrefabs = new List<GameObject>();
_childArcPrefabs = new List<GameObject>();
@ -99,59 +57,67 @@ namespace NewHorizons.Builder.Props
{
if (existingArc.GetComponent<MeshRenderer>().material.name.Contains("Child"))
{
var arc = existingArc.InstantiateInactive();
arc.name = "Arc (Child)";
_childArcPrefabs.Add(arc);
_childArcPrefabs.Add(existingArc.InstantiateInactive().Rename("Arc (Child)").DontDestroyOnLoad());
}
else
{
var arc = existingArc.InstantiateInactive();
arc.name = "Arc";
_arcPrefabs.Add(arc);
_arcPrefabs.Add(existingArc.InstantiateInactive().Rename("Arc").DontDestroyOnLoad());
}
}
}
if (_ghostArcPrefabs == null)
{
var existingGhostArcs = GameObject.FindObjectsOfType<GhostWallText>().Select(x => x?._textLine?.gameObject).Where(x => x != null).ToArray();
_ghostArcPrefabs = new List<GameObject>();
foreach (var existingArc in existingGhostArcs)
{
var arc = existingArc.InstantiateInactive();
arc.name = "Arc (Ghost)";
_ghostArcPrefabs.Add(arc);
_ghostArcPrefabs.Add(existingArc.InstantiateInactive().Rename("Arc (Ghost)").DontDestroyOnLoad());
}
}
_scrollPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/Prefab_NOM_Scroll").InstantiateInactive();
_scrollPrefab.name = "Prefab_NOM_Scroll";
if (_scrollPrefab == null) _scrollPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/Prefab_NOM_Scroll").InstantiateInactive().Rename("Prefab_NOM_Scroll").DontDestroyOnLoad();
_computerPrefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Interactables_VM/Prefab_NOM_Computer").InstantiateInactive();
_computerPrefab.name = "Prefab_NOM_Computer";
if (_computerPrefab == null)
{
_computerPrefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Interactables_VM/Prefab_NOM_Computer").InstantiateInactive().Rename("Prefab_NOM_Computer").DontDestroyOnLoad();
_computerPrefab.transform.rotation = Quaternion.identity;
}
_preCrashComputerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_EscapePodCrashSite/Sector_CrashFragment/EscapePod_Socket/Interactibles_EscapePod/Prefab_NOM_Vessel_Computer").InstantiateInactive();
_preCrashComputerPrefab.name = "Prefab_NOM_Vessel_Computer";
if (_preCrashComputerPrefab == null)
{
_preCrashComputerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_EscapePodCrashSite/Sector_CrashFragment/EscapePod_Socket/Interactibles_EscapePod/Prefab_NOM_Vessel_Computer").InstantiateInactive().Rename("Prefab_NOM_Vessel_Computer").DontDestroyOnLoad();
_preCrashComputerPrefab.transform.rotation = Quaternion.identity;
}
_cairnPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_Crossroads/Interactables_Crossroads/Trailmarkers/Prefab_NOM_BH_Cairn_Arc (1)").InstantiateInactive();
_cairnPrefab.name = "Prefab_NOM_Cairn";
if (_cairnPrefab == null)
{
_cairnPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_Crossroads/Interactables_Crossroads/Trailmarkers/Prefab_NOM_BH_Cairn_Arc (1)").InstantiateInactive().Rename("Prefab_NOM_Cairn").DontDestroyOnLoad();
_cairnPrefab.transform.rotation = Quaternion.identity;
}
_recorderPrefab = SearchUtilities.Find("Comet_Body/Prefab_NOM_Shuttle/Sector_NomaiShuttleInterior/Interactibles_NomaiShuttleInterior/Prefab_NOM_Recorder").InstantiateInactive();
_recorderPrefab.name = "Prefab_NOM_Recorder";
if (_recorderPrefab == null)
{
_recorderPrefab = SearchUtilities.Find("Comet_Body/Prefab_NOM_Shuttle/Sector_NomaiShuttleInterior/Interactibles_NomaiShuttleInterior/Prefab_NOM_Recorder").InstantiateInactive().Rename("Prefab_NOM_Recorder").DontDestroyOnLoad();
_recorderPrefab.transform.rotation = Quaternion.identity;
}
_preCrashRecorderPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_EscapePodCrashSite/Sector_CrashFragment/Interactables_CrashFragment/Prefab_NOM_Recorder").InstantiateInactive();
_preCrashRecorderPrefab.name = "Prefab_NOM_Recorder_Vessel";
if (_preCrashRecorderPrefab == null)
{
_preCrashRecorderPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_EscapePodCrashSite/Sector_CrashFragment/Interactables_CrashFragment/Prefab_NOM_Recorder").InstantiateInactive().Rename("Prefab_NOM_Recorder_Vessel").DontDestroyOnLoad();
_preCrashRecorderPrefab.transform.rotation = Quaternion.identity;
}
_trailmarkerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/Prefab_NOM_Sign").InstantiateInactive();
_trailmarkerPrefab.name = "Prefab_NOM_Trailmarker";
if (_trailmarkerPrefab == null)
{
_trailmarkerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/Prefab_NOM_Sign").InstantiateInactive().Rename("Prefab_NOM_Trailmarker").DontDestroyOnLoad();
_trailmarkerPrefab.transform.rotation = Quaternion.identity;
}
}
public static GameObject Make(GameObject planetGO, Sector sector, PropModule.NomaiTextInfo info, IModBehaviour mod)
{
if (_scrollPrefab == null) InitPrefabs();
InitPrefabs();
var xmlPath = File.ReadAllText(mod.ModHelper.Manifest.ModFolderPath + info.xmlFile);

View File

@ -13,8 +13,49 @@ namespace NewHorizons.Builder.Props
{
private static GameObject _slideReelPrefab;
private static GameObject _autoPrefab;
private static GameObject _visionTorchDetectorPrefab;
private static GameObject _standingVisionTorchPrefab;
private static readonly int EmissionMap = Shader.PropertyToID("_EmissionMap");
internal static void InitPrefabs()
{
if (_slideReelPrefab == null)
{
_slideReelPrefab = SearchUtilities.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone1/Sector_SlideBurningRoom_Zone1/Interactables_SlideBurningRoom_Zone1/Prefab_IP_SecretAlcove/RotationPivot/SlideReelSocket/Prefab_IP_Reel_1_LibraryPath")?.gameObject?.InstantiateInactive()?.Rename("Prefab_IP_Reel")?.DontDestroyOnLoad();
if (_slideReelPrefab == null)
Logger.LogWarning($"Tried to make slide reel prefab but couldn't. Do you have the DLC installed?");
else
_slideReelPrefab.AddComponent<DestroyOnDLC>()._destroyOnDLCNotOwned = true;
}
if (_autoPrefab == null)
{
_autoPrefab = SearchUtilities.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone4/Sector_BlightedShore/Sector_JammingControlRoom_Zone4/Interactables_JammingControlRoom_Zone4/AutoProjector_SignalJammer/Prefab_IP_AutoProjector_SignalJammer")?.gameObject?.InstantiateInactive()?.Rename("Prefab_IP_AutoProjector")?.DontDestroyOnLoad();
if (_autoPrefab == null)
Logger.LogWarning($"Tried to make auto projector prefab but couldn't. Do you have the DLC installed?");
else
_autoPrefab.AddComponent<DestroyOnDLC>()._destroyOnDLCNotOwned = true;
}
if (_visionTorchDetectorPrefab == null)
{
_visionTorchDetectorPrefab = SearchUtilities.Find("DreamWorld_Body/Sector_DreamWorld/Sector_Underground/Sector_PrisonCell/Ghosts_PrisonCell/GhostDirector_Prisoner/Prefab_IP_GhostBird_Prisoner/Ghostbird_IP_ANIM/Ghostbird_Skin_01:Ghostbird_Rig_V01:Base/Ghostbird_Skin_01:Ghostbird_Rig_V01:Root/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine03/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine04/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Head/PrisonerHeadDetector")?.gameObject?.InstantiateInactive()?.Rename("Prefab_IP_VisionTorchDetector")?.DontDestroyOnLoad();
if (_visionTorchDetectorPrefab == null)
Logger.LogWarning($"Tried to make vision torch detector prefab but couldn't. Do you have the DLC installed?");
else
_visionTorchDetectorPrefab.AddComponent<DestroyOnDLC>()._destroyOnDLCNotOwned = true;
}
if (_standingVisionTorchPrefab == null)
{
_standingVisionTorchPrefab = SearchUtilities.Find("RingWorld_Body/Sector_RingWorld/Sector_SecretEntrance/Interactibles_SecretEntrance/Experiment_1/VisionTorchApparatus/VisionTorchRoot/Prefab_IP_VisionTorchProjector")?.gameObject?.InstantiateInactive()?.Rename("Prefab_IP_VisionTorchProjector")?.DontDestroyOnLoad();
if (_standingVisionTorchPrefab == null)
Logger.LogWarning($"Tried to make standing vision torch prefab but couldn't. Do you have the DLC installed?");
else
_standingVisionTorchPrefab.AddComponent<DestroyOnDLC>()._destroyOnDLCNotOwned = true;
}
}
public static void Make(GameObject go, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod)
{
switch (info.type)
@ -37,18 +78,11 @@ namespace NewHorizons.Builder.Props
}
}
private static void MakeSlideReel(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod)
private static GameObject MakeSlideReel(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod)
{
if (_slideReelPrefab == null)
{
_slideReelPrefab = SearchUtilities.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone1/Sector_SlideBurningRoom_Zone1/Interactables_SlideBurningRoom_Zone1/Prefab_IP_SecretAlcove/RotationPivot/SlideReelSocket/Prefab_IP_Reel_1_LibraryPath")?.gameObject?.InstantiateInactive();
if (_slideReelPrefab == null)
{
Logger.LogWarning($"Tried to make a slide reel but couldn't. Do you have the DLC installed?");
return;
}
_slideReelPrefab.name = "Prefab_IP_Reel";
}
InitPrefabs();
if (_slideReelPrefab == null) return null;
var slideReelObj = _slideReelPrefab.InstantiateInactive();
slideReelObj.name = $"Prefab_IP_Reel_{mod.ModHelper.Manifest.Name}";
@ -146,20 +180,15 @@ namespace NewHorizons.Builder.Props
StreamingHandler.SetUpStreaming(slideReelObj, sector);
slideReelObj.SetActive(true);
return slideReelObj;
}
public static void MakeAutoProjector(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod)
public static GameObject MakeAutoProjector(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod)
{
if (_autoPrefab == null)
{
_autoPrefab = SearchUtilities.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone4/Sector_BlightedShore/Sector_JammingControlRoom_Zone4/Interactables_JammingControlRoom_Zone4/AutoProjector_SignalJammer/Prefab_IP_AutoProjector_SignalJammer")?.gameObject?.InstantiateInactive();
if (_autoPrefab == null)
{
Logger.LogWarning($"Tried to make a auto projector but couldn't. Do you have the DLC installed?");
return;
}
_autoPrefab.name = "Prefab_IP_AutoProjector";
}
InitPrefabs();
if (_autoPrefab == null) return null;
var projectorObj = _autoPrefab.InstantiateInactive();
projectorObj.name = $"Prefab_IP_AutoProjector_{mod.ModHelper.Manifest.Name}";
@ -215,20 +244,24 @@ namespace NewHorizons.Builder.Props
lens.materials[1].SetTexture(EmissionMap, slideCollection.slides[0]._image);
projectorObj.SetActive(true);
return projectorObj;
}
// Makes a target for a vision torch to scan
public static GameObject MakeMindSlidesTarget(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod)
{
InitPrefabs();
if (_visionTorchDetectorPrefab == null) return null;
// spawn a trigger for the vision torch
var path = "DreamWorld_Body/Sector_DreamWorld/Sector_Underground/Sector_PrisonCell/Ghosts_PrisonCell/GhostDirector_Prisoner/Prefab_IP_GhostBird_Prisoner/Ghostbird_IP_ANIM/Ghostbird_Skin_01:Ghostbird_Rig_V01:Base/Ghostbird_Skin_01:Ghostbird_Rig_V01:Root/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine03/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine04/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Head/PrisonerHeadDetector";
var prefab = SearchUtilities.Find(path);
var detailInfo = new PropModule.DetailInfo()
{
position = info.position,
scale = 2
};
var g = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
var g = DetailBuilder.Make(planetGO, sector, _visionTorchDetectorPrefab, detailInfo);
if (!string.IsNullOrEmpty(info.parentPath))
{
@ -286,15 +319,17 @@ namespace NewHorizons.Builder.Props
public static GameObject MakeStandingVisionTorch(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod)
{
InitPrefabs();
if (_standingVisionTorchPrefab == null) return null;
// Spawn the torch itself
var path = "RingWorld_Body/Sector_RingWorld/Sector_SecretEntrance/Interactibles_SecretEntrance/Experiment_1/VisionTorchApparatus/VisionTorchRoot/Prefab_IP_VisionTorchProjector";
var prefab = SearchUtilities.Find(path);
var detailInfo = new PropModule.DetailInfo()
{
position = info.position,
rotation = info.rotation
};
var standingTorch = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
var standingTorch = DetailBuilder.Make(planetGO, sector, _standingVisionTorchPrefab, detailInfo);
if (!string.IsNullOrEmpty(info.parentPath))
{

View File

@ -1,4 +1,4 @@
using NewHorizons.Components;
using NewHorizons.Components;
using NewHorizons.External.Modules;
using NewHorizons.Handlers;
using NewHorizons.Utility;
@ -10,18 +10,26 @@ namespace NewHorizons.Builder.Props
{
private static GameObject _prefab;
public static void Make(GameObject planetGO, Sector sector, PropModule.RaftInfo info, OWRigidbody planetBody)
internal static void InitPrefab()
{
if (_prefab == null)
{
_prefab = GameObject.FindObjectOfType<RaftController>()?.gameObject?.InstantiateInactive();
_prefab = GameObject.FindObjectOfType<RaftController>()?.gameObject?.InstantiateInactive()?.Rename("Raft_Body_Prefab")?.DontDestroyOnLoad();
if (_prefab == null)
{
Logger.LogWarning($"Tried to make a raft but couldn't. Do you have the DLC installed?");
return;
}
_prefab.name = "Raft_Body_Prefab";
else
_prefab.AddComponent<DestroyOnDLC>()._destroyOnDLCNotOwned = true;
}
}
public static void Make(GameObject planetGO, Sector sector, PropModule.RaftInfo info, OWRigidbody planetBody)
{
InitPrefab();
if (_prefab == null) return;
GameObject raftObject = _prefab.InstantiateInactive();
raftObject.name = "Raft_Body";

View File

@ -17,9 +17,11 @@ namespace NewHorizons.Builder.Props
private static GameObject _whiteboardPrefab;
private static GameObject _shareStonePrefab;
private static void InitPrefabs()
internal static void InitPrefabs()
{
_decalMaterial = new Material(Shader.Find("Standard (Decal)"));
if (_decalMaterial == null)
{
_decalMaterial = new Material(Shader.Find("Standard (Decal)")).DontDestroyOnLoad();
_decalMaterial.name = "Decal";
_decalMaterial.SetTexture("_MainTex", Texture2D.whiteTexture);
_decalMaterial.SetTexture("_EmissionMap", Texture2D.whiteTexture);
@ -31,9 +33,11 @@ namespace NewHorizons.Builder.Props
_decalMaterialGold.name = "DecalGold";
_decalMaterialGold.SetColor("_Color", new Color(1, 0.6392157f, 0.3803922f));
_decalMaterialGold.SetColor("_EmissionColor", new Color(1, 0.3662527f, 0.1195384f));
}
_remoteCameraPlatformPrefab = SearchUtilities.Find("OrbitalProbeCannon_Body/Sector_OrbitalProbeCannon/Sector_Module_Broken/Interactables_Module_Broken/Prefab_NOM_RemoteViewer").InstantiateInactive();
_remoteCameraPlatformPrefab.name = "Prefab_NOM_RemoteViewer";
if (_remoteCameraPlatformPrefab == null)
{
_remoteCameraPlatformPrefab = SearchUtilities.Find("OrbitalProbeCannon_Body/Sector_OrbitalProbeCannon/Sector_Module_Broken/Interactables_Module_Broken/Prefab_NOM_RemoteViewer").InstantiateInactive().Rename("Prefab_NOM_RemoteViewer").DontDestroyOnLoad();
var remoteCameraPlatform = _remoteCameraPlatformPrefab.GetComponent<NomaiRemoteCameraPlatform>();
remoteCameraPlatform.enabled = true;
remoteCameraPlatform._id = NomaiRemoteCameraPlatform.ID.None;
@ -50,9 +54,11 @@ namespace NewHorizons.Builder.Props
quad.GetComponent<MeshRenderer>().sharedMaterial = _decalMaterial;
quad.name = "AstroBodySymbolRenderer";
GameObject.DestroyImmediate(AstroBodySymbolRenderer);
}
_whiteboardPrefab = SearchUtilities.Find("OrbitalProbeCannon_Body/Sector_OrbitalProbeCannon/Sector_Module_Broken/Interactables_Module_Broken/Prefab_NOM_Whiteboard_Shared").InstantiateInactive();
_whiteboardPrefab.name = "Prefab_NOM_Whiteboard_Shared";
if (_whiteboardPrefab == null)
{
_whiteboardPrefab = SearchUtilities.Find("OrbitalProbeCannon_Body/Sector_OrbitalProbeCannon/Sector_Module_Broken/Interactables_Module_Broken/Prefab_NOM_Whiteboard_Shared").InstantiateInactive().Rename("Prefab_NOM_Whiteboard_Shared").DontDestroyOnLoad();
var whiteboard = _whiteboardPrefab.GetComponent<NomaiSharedWhiteboard>();
whiteboard.enabled = true;
whiteboard._id = NomaiRemoteCameraPlatform.ID.None;
@ -69,7 +75,10 @@ namespace NewHorizons.Builder.Props
quadW.GetComponent<MeshRenderer>().sharedMaterial = _decalMaterial;
quadW.name = "AstroBodySymbolRenderer";
GameObject.DestroyImmediate(AstroBodySymbolRendererW);
}
if (_shareStonePrefab == null)
{
GameObject stone = new GameObject("ShareStoneFallback");
stone.layer = LayerMask.NameToLayer("Interactible");
stone.SetActive(false);
@ -97,12 +106,13 @@ namespace NewHorizons.Builder.Props
planetDecal.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
planetDecal.AddComponent<OWRenderer>();
planetDecal.GetComponent<MeshRenderer>().sharedMaterial = _decalMaterialGold;
_shareStonePrefab = stone;
_shareStonePrefab = stone.DontDestroyOnLoad();
}
}
public static void Make(GameObject go, Sector sector, PropModule.RemoteInfo info, IModBehaviour mod)
{
if (_shareStonePrefab == null) InitPrefabs();
InitPrefabs();
var id = RemoteHandler.GetPlatformID(info.id);

View File

@ -23,22 +23,13 @@ namespace NewHorizons.Builder.Props
private static readonly int MainTex = Shader.PropertyToID("_MainTex");
private static readonly int FresnelColor = Shader.PropertyToID("_FresnelColor");
public static void Make(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, bool hasClouds)
internal static void InitPrefabs()
{
if (_upPrefab == null)
{
_upPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado").InstantiateInactive();
_upPrefab.name = "Tornado_Up_Prefab";
}
if (_downPrefab == null)
{
_downPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive();
_downPrefab.name = "Tornado_Down_Prefab";
}
if (_upPrefab == null) _upPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado").InstantiateInactive().Rename("Tornado_Up_Prefab").DontDestroyOnLoad();
if (_downPrefab == null) _downPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive().Rename("Tornado_Down_Prefab").DontDestroyOnLoad();
if (_hurricanePrefab == null)
{
_hurricanePrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane").InstantiateInactive();
_hurricanePrefab.name = "Hurricane_Prefab";
_hurricanePrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane").InstantiateInactive().Rename("Hurricane_Prefab").DontDestroyOnLoad();
// For some reason they put the hurricane at the origin and offset all its children (450)
// Increasing by 40 will keep the bottom above the ground
foreach (Transform child in _hurricanePrefab.transform)
@ -50,19 +41,14 @@ namespace NewHorizons.Builder.Props
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
}
if (_soundPrefab == null)
{
_soundPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive();
_soundPrefab.name = "AudioRail_Prefab";
if (_soundPrefab == null) _soundPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive().Rename("AudioRail_Prefab").DontDestroyOnLoad();
if (_mainTexture == null) _mainTexture = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Tornado_BH_Cyclone_02_d.png");
if (_detailTexture == null) _detailTexture = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Tornado_BH_CycloneDetail_d.png");
}
if (_mainTexture == null)
public static void Make(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, bool hasClouds)
{
_mainTexture = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Tornado_BH_Cyclone_02_d.png");
}
if (_detailTexture == null)
{
_detailTexture = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Tornado_BH_CycloneDetail_d.png");
}
InitPrefabs();
Vector3 position;
if (info.position != null)

View File

@ -10,11 +10,18 @@ namespace NewHorizons.Builder.Props
private static readonly int Color1 = Shader.PropertyToID("_Color");
private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");
private static GameObject _meteorLauncherPrefab;
internal static void InitPrefab()
{
if (_meteorLauncherPrefab == null) _meteorLauncherPrefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Effects_VM/VolcanoPivot (2)/MeteorLauncher").InstantiateInactive().Rename("Prefab_VM_MeteorLauncher").DontDestroyOnLoad();
}
public static void Make(GameObject planetGO, Sector sector, PropModule.VolcanoInfo info)
{
var prefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Effects_VM/VolcanoPivot (2)/MeteorLauncher");
InitPrefab();
var launcherGO = prefab.InstantiateInactive();
var launcherGO = _meteorLauncherPrefab.InstantiateInactive();
launcherGO.transform.parent = sector.transform;
launcherGO.transform.position = planetGO.transform.TransformPoint(info.position == null ? Vector3.zero : (Vector3)info.position);
launcherGO.transform.rotation = Quaternion.FromToRotation(launcherGO.transform.TransformDirection(Vector3.up), ((Vector3)info.position).normalized).normalized;

View File

@ -1,6 +1,7 @@
using HarmonyLib;
using NewHorizons.Builder.Atmosphere;
using NewHorizons.Builder.Body;
using NewHorizons.Builder.General;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.Components.Orbital;
@ -55,6 +56,7 @@ namespace NewHorizons
public string CurrentStarSystem => _currentStarSystem;
public bool IsWarpingFromShip { get; private set; } = false;
public bool IsWarpingFromVessel { get; private set; } = false;
public bool IsWarpingBackToEye { get; internal set; } = false;
public bool WearingSuit { get; private set; } = false;
public bool IsChangingStarSystem { get; private set; } = false;
@ -254,7 +256,52 @@ namespace NewHorizons
var isCreditsFinal = scene.name == LoadManager.SceneToName(OWScene.Credits_Final);
var isPostCredits = scene.name == LoadManager.SceneToName(OWScene.PostCreditsScene);
if (isSolarSystem)
{
try
{
AtmosphereBuilder.InitPrefabs();
BrambleDimensionBuilder.InitPrefabs();
BrambleNodeBuilder.InitPrefabs();
CloudsBuilder.InitPrefabs();
CometTailBuilder.InitPrefab();
DetectorBuilder.InitPrefabs();
EffectsBuilder.InitPrefabs();
FogBuilder.InitPrefabs();
FunnelBuilder.InitPrefabs();
GeometryBuilder.InitPrefab();
GeyserBuilder.InitPrefab();
LavaBuilder.InitPrefabs();
NomaiTextBuilder.InitPrefabs();
RemoteBuilder.InitPrefabs();
SandBuilder.InitPrefabs();
SingularityBuilder.InitPrefabs();
StarBuilder.InitPrefabs();
SupernovaEffectBuilder.InitPrefabs();
TornadoBuilder.InitPrefabs();
VolcanoBuilder.InitPrefab();
VolumesBuilder.InitPrefabs();
WaterBuilder.InitPrefabs();
ProjectionBuilder.InitPrefabs();
CloakBuilder.InitPrefab();
RaftBuilder.InitPrefab();
}
catch (Exception e)
{
Logger.LogError($"Couldn't init prefabs:\n{e}");
}
}
if (isEyeOfTheUniverse) _currentStarSystem = "EyeOfTheUniverse";
else if (IsWarpingBackToEye)
{
IsWarpingBackToEye = false;
OWTime.Pause(OWTime.PauseType.Loading);
LoadManager.LoadSceneImmediate(OWScene.EyeOfTheUniverse);
OWTime.Unpause(OWTime.PauseType.Loading);
return;
}
if (!SystemDict.ContainsKey(_currentStarSystem) || !BodyDict.ContainsKey(_currentStarSystem))
{

View File

@ -15,7 +15,7 @@ namespace NewHorizons.Patches
private static void OnLoadScene(OWScene scene)
{
if (scene == OWScene.SolarSystem)
if (scene == OWScene.SolarSystem && !Main.Instance.IsWarpingBackToEye)
{
PlayerData.SaveEyeCompletion();
@ -39,7 +39,12 @@ namespace NewHorizons.Patches
public static void SubmitActionLoadScene_ConfirmSubmit(SubmitActionLoadScene __instance)
{
// Title screen can warp you to eye and cause problems.
if (__instance._sceneToLoad == SubmitActionLoadScene.LoadableScenes.EYE) Main.Instance._currentStarSystem = "EyeOfTheUniverse";
if (__instance._sceneToLoad == SubmitActionLoadScene.LoadableScenes.EYE)
{
Utility.Logger.LogWarning("Warping to solar system and then back to eye");
Main.Instance.IsWarpingBackToEye = true;
__instance._sceneToLoad = SubmitActionLoadScene.LoadableScenes.GAME;
}
}
[HarmonyPrefix]

View File

@ -187,6 +187,29 @@ namespace NewHorizons.Utility
return copy;
}
public static T DontDestroyOnLoad<T>(this T target) where T : UnityEngine.Object
{
UnityEngine.Object.DontDestroyOnLoad(target);
return target;
}
public static Material[] MakePrefabMaterials(this Material[] target)
{
var materials = new List<Material>();
foreach (var material in target)
{
materials.Add(new Material(material).DontDestroyOnLoad());
}
return materials.ToArray();
}
public static T Rename<T>(this T target, string name) where T : UnityEngine.Object
{
target.name = name;
return target;
}
public static Quaternion TransformRotation(this Transform transform, Quaternion localRotation)
{
return transform.rotation * localRotation;