From 74873efc119c8913e47ad84016ee0142aa97d704 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 05:49:41 -0400 Subject: [PATCH 01/72] Manually set attached components --- NewHorizons/Builder/General/DetectorBuilder.cs | 4 +++- NewHorizons/Builder/General/GravityBuilder.cs | 5 +++-- NewHorizons/Builder/General/RFVolumeBuilder.cs | 8 +++++--- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Builder/General/DetectorBuilder.cs b/NewHorizons/Builder/General/DetectorBuilder.cs index d71c30b4..3f47e8bb 100644 --- a/NewHorizons/Builder/General/DetectorBuilder.cs +++ b/NewHorizons/Builder/General/DetectorBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components.Orbital; +using NewHorizons.Components.Orbital; using NewHorizons.External.Configs; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -31,6 +31,8 @@ namespace NewHorizons.Builder.General fluidDetector._collider = sphereCollider; + OWRB.RegisterAttachedFluidDetector(fluidDetector); + // Could copy the splash from the interloper as well some day } diff --git a/NewHorizons/Builder/General/GravityBuilder.cs b/NewHorizons/Builder/General/GravityBuilder.cs index 067a1a75..95f8a886 100644 --- a/NewHorizons/Builder/General/GravityBuilder.cs +++ b/NewHorizons/Builder/General/GravityBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using NewHorizons.External.Modules; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -6,7 +6,7 @@ namespace NewHorizons.Builder.General { public static class GravityBuilder { - public static GravityVolume Make(GameObject planetGO, AstroObject ao, PlanetConfig config) + public static GravityVolume Make(GameObject planetGO, AstroObject ao, OWRigidbody owrb, PlanetConfig config) { var exponent = config.Base.gravityFallOff == GravityFallOff.Linear ? 1f : 2f; var GM = config.Base.surfaceGravity * Mathf.Pow(config.Base.surfaceSize, exponent); @@ -60,6 +60,7 @@ namespace NewHorizons.Builder.General gravityGO.SetActive(true); ao._gravityVolume = gravityVolume; + owrb.RegisterAttachedGravityVolume(gravityVolume); return gravityVolume; } diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index 892aae9a..7b1c08a4 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -1,10 +1,10 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using UnityEngine; namespace NewHorizons.Builder.General { public static class RFVolumeBuilder { - public static void Make(GameObject planetGO, OWRigidbody owRigidBody, float sphereOfInfluence) + public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence) { var rfGO = new GameObject("RFVolume"); rfGO.transform.parent = planetGO.transform; @@ -18,7 +18,7 @@ namespace NewHorizons.Builder.General var RFV = rfGO.AddComponent(); - var RV = new ReferenceFrame(owRigidBody); + var RV = new ReferenceFrame(owrb); RV._minSuitTargetDistance = sphereOfInfluence; RV._maxTargetDistance = 0; RV._autopilotArrivalDistance = 2.0f * sphereOfInfluence; @@ -36,6 +36,8 @@ namespace NewHorizons.Builder.General RFV._isPrimaryVolume = true; RFV._isCloseRangeVolume = false; + owrb.SetAttachedReferenceFrameVolume(RFV); + rfGO.SetActive(true); } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index b7600d4d..b1776627 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -303,7 +303,7 @@ namespace NewHorizons.Handlers if (body.Config.Base.surfaceGravity != 0) { - GravityBuilder.Make(go, ao, body.Config); + GravityBuilder.Make(go, ao, owRigidBody, body.Config); } if (body.Config.Base.hasReferenceFrame) From 76e4ed12d52a0c54d6d9ac46750b1ad0cb665de8 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 05:50:05 -0400 Subject: [PATCH 02/72] Manually enable sector --- NewHorizons/Builder/General/SectorBuilder.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/General/SectorBuilder.cs b/NewHorizons/Builder/General/SectorBuilder.cs index ff10fb97..8093b429 100644 --- a/NewHorizons/Builder/General/SectorBuilder.cs +++ b/NewHorizons/Builder/General/SectorBuilder.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using UnityEngine; namespace NewHorizons.Builder.General { @@ -27,6 +27,7 @@ namespace NewHorizons.Builder.General S._subsectors = new List(); sectorGO.SetActive(true); + S.enabled = true; return S; } From b8b3d7063840ee524f2a58f9d3555504ec456874 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 05:51:11 -0400 Subject: [PATCH 03/72] Create reference frame but disable if not wanted --- NewHorizons/Builder/General/RFVolumeBuilder.cs | 4 ++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index 7b1c08a4..f6831bb7 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -4,7 +4,7 @@ namespace NewHorizons.Builder.General { public static class RFVolumeBuilder { - public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence) + public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, bool hide = false) { var rfGO = new GameObject("RFVolume"); rfGO.transform.parent = planetGO.transform; @@ -38,7 +38,7 @@ namespace NewHorizons.Builder.General owrb.SetAttachedReferenceFrameVolume(RFV); - rfGO.SetActive(true); + rfGO.SetActive(!hide); } } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index b1776627..0234543c 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -306,10 +306,7 @@ namespace NewHorizons.Handlers GravityBuilder.Make(go, ao, owRigidBody, body.Config); } - if (body.Config.Base.hasReferenceFrame) - { - RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence); - } + RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, !body.Config.Base.hasReferenceFrame); if (body.Config.Base.hasMapMarker) { From bb22b03c18e8be7e748374e8ec9f768e0a3e0b82 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 05:54:18 -0400 Subject: [PATCH 04/72] Fix Cloak Invisible Bug --- NewHorizons/Builder/Body/CloakBuilder.cs | 4 +++- .../Components/CloakSectorController.cs | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index 4debb50a..c75fa60c 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Body @@ -32,6 +32,8 @@ namespace NewHorizons.Builder.Body newCloak.SetActive(true); cloakFieldController.enabled = true; + cloakSectorController.EnableCloak(); + // To cloak from the start Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit); } diff --git a/NewHorizons/Components/CloakSectorController.cs b/NewHorizons/Components/CloakSectorController.cs index 844a1a15..f027a7dc 100644 --- a/NewHorizons/Components/CloakSectorController.cs +++ b/NewHorizons/Components/CloakSectorController.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using UnityEngine; namespace NewHorizons.Components @@ -60,5 +60,21 @@ namespace NewHorizons.Components renderer.forceRenderingOff = true; } } + + public void EnableCloak() + { + SunLightController.RegisterSunOverrider(_cloak, 900); + _cloak._cloakSphereRenderer.SetActivation(true); + Shader.EnableKeyword("_CLOAKINGFIELDENABLED"); + _cloak._cloakVisualsEnabled = true; + } + + public void DisableCloak() + { + SunLightController.UnregisterSunOverrider(_cloak); + _cloak._cloakSphereRenderer.SetActivation(false); + Shader.DisableKeyword("_CLOAKINGFIELDENABLED"); + _cloak._cloakVisualsEnabled = false; + } } } From 3ed6834f619a12a6a857aa316da89382e4ba9d74 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 06:00:01 -0400 Subject: [PATCH 05/72] Keep Reference Frame for Cloak --- NewHorizons/Builder/Body/CloakBuilder.cs | 3 ++- NewHorizons/Components/CloakSectorController.cs | 4 ++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index c75fa60c..ffafc769 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -5,7 +5,7 @@ namespace NewHorizons.Builder.Body { public static class CloakBuilder { - public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, float radius) + public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, float radius, bool keepReferenceFrame) { var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP"); @@ -36,6 +36,7 @@ namespace NewHorizons.Builder.Body // To cloak from the start Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit); + Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(keepReferenceFrame ? cloakSectorController.EnableReferenceFrameVolume : cloakSectorController.DisableReferenceFrameVolume); } } } diff --git a/NewHorizons/Components/CloakSectorController.cs b/NewHorizons/Components/CloakSectorController.cs index f027a7dc..9a047ddc 100644 --- a/NewHorizons/Components/CloakSectorController.cs +++ b/NewHorizons/Components/CloakSectorController.cs @@ -76,5 +76,9 @@ namespace NewHorizons.Components Shader.DisableKeyword("_CLOAKINGFIELDENABLED"); _cloak._cloakVisualsEnabled = false; } + + public void SetReferenceFrameVolumeActive(bool active) => _cloak._referenceFrameVolume.gameObject.SetActive(active); + public void EnableReferenceFrameVolume() => SetReferenceFrameVolumeActive(true); + public void DisableReferenceFrameVolume() => SetReferenceFrameVolumeActive(false); } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 0234543c..46cbacf4 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -482,7 +482,7 @@ namespace NewHorizons.Handlers // Has to go last probably if (body.Config.Base.cloakRadius != 0f) { - CloakBuilder.Make(go, sector, rb, body.Config.Base.cloakRadius); + CloakBuilder.Make(go, sector, rb, body.Config.Base.cloakRadius, body.Config.Base.hasReferenceFrame); } return go; From 855a4caa2f40218c3227aa3daaed64352056502b Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 06:04:32 -0400 Subject: [PATCH 06/72] Cloak Module --- NewHorizons/Builder/Body/CloakBuilder.cs | 4 +++- NewHorizons/External/Configs/PlanetConfig.cs | 13 +++++++++++- NewHorizons/External/Modules/BaseModule.cs | 11 ++++------ NewHorizons/External/Modules/CloakModule.cs | 19 ++++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 4 ++-- NewHorizons/Schemas/body_schema.json | 20 ++++++++++++++----- 6 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 NewHorizons/External/Modules/CloakModule.cs diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index ffafc769..b0197bc4 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -1,12 +1,14 @@ using NewHorizons.Components; +using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Body { public static class CloakBuilder { - public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, float radius, bool keepReferenceFrame) + public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame) { + var radius = module.radius; var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP"); var newCloak = GameObject.Instantiate(cloak, sector?.transform ?? planetGO.transform); diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 74c82151..bd748a62 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using NewHorizons.External.Modules; @@ -45,6 +45,11 @@ namespace NewHorizons.External.Configs #endregion Obsolete + /// + /// Add a cloaking field to this planet + /// + public CloakModule Cloak; + /// /// `true` if you want to delete this planet /// @@ -192,6 +197,12 @@ namespace NewHorizons.External.Configs if (childrenToDestroy != null) removeChildren = childrenToDestroy; + if (Base.cloakRadius != 0) + Cloak = new CloakModule + { + radius = Base.cloakRadius + }; + if (Base.hasAmbientLight) Base.ambientLight = 0.5f; if (Atmosphere != null) diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index 28f2f8ba..20645d16 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.Runtime.Serialization; using NewHorizons.Utility; @@ -30,12 +30,6 @@ namespace NewHorizons.External.Modules /// public bool centerOfSolarSystem; - /// - /// Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you - /// don't want a cloak, leave this as 0. - /// - public float cloakRadius; - /// /// If it has a comet tail, it'll be oriented according to these Euler angles. /// @@ -112,6 +106,9 @@ namespace NewHorizons.External.Modules [Obsolete("HasAmbientLight is deprecated, please use AmbientLight instead")] public bool hasAmbientLight; + [Obsolete("CloakRadius is deprecated, please use CloakModule instead")] + public float cloakRadius; + #endregion Obsolete } } \ No newline at end of file diff --git a/NewHorizons/External/Modules/CloakModule.cs b/NewHorizons/External/Modules/CloakModule.cs new file mode 100644 index 00000000..87f6dbf7 --- /dev/null +++ b/NewHorizons/External/Modules/CloakModule.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel; +using System.Runtime.Serialization; +using NewHorizons.Utility; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace NewHorizons.External.Modules +{ + [JsonObject] + public class CloakModule + { + /// + /// Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you + /// don't want a cloak, leave this as 0. + /// + public float radius; + } +} \ No newline at end of file diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 46cbacf4..a6324b55 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -480,9 +480,9 @@ namespace NewHorizons.Handlers } // Has to go last probably - if (body.Config.Base.cloakRadius != 0f) + if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f) { - CloakBuilder.Make(go, sector, rb, body.Config.Base.cloakRadius, body.Config.Base.hasReferenceFrame); + CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame); } return go; diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index b52e6823..5856cea7 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -30,6 +30,10 @@ "type": "boolean", "description": "Should this planet ever be shown on the title screen?" }, + "Cloak": { + "description": "Add a cloaking field to this planet", + "$ref": "#/definitions/CloakModule" + }, "destroy": { "type": "boolean", "description": "`true` if you want to delete this planet" @@ -285,6 +289,17 @@ } } }, + "CloakModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "radius": { + "type": "number", + "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", + "format": "float" + } + } + }, "CloudInfo": { "type": "object", "additionalProperties": false, @@ -384,11 +399,6 @@ "type": "boolean", "description": "Set this to true if you are replacing the sun with a different body. Only one object in a star system should ever\nhave this set to true." }, - "cloakRadius": { - "type": "number", - "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", - "format": "float" - }, "cometTailRotation": { "description": "If it has a comet tail, it'll be oriented according to these Euler angles.", "$ref": "#/definitions/MVector3" From 0fe3ed06ac079f8773f96ef5c3bb12a5e4d4a5cb Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 06:05:12 -0400 Subject: [PATCH 07/72] Cloak Entry Audio --- NewHorizons/Builder/Body/CloakBuilder.cs | 27 ++++++++++++++++++- .../Components/CloakSectorController.cs | 3 +++ NewHorizons/External/Modules/CloakModule.cs | 10 +++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- NewHorizons/Schemas/body_schema.json | 8 ++++++ 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index b0197bc4..ab18f6bf 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -1,14 +1,30 @@ using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Utility; +using OWML.Common; using UnityEngine; namespace NewHorizons.Builder.Body { public static class CloakBuilder { - public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame) + public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame, IModBehaviour mod) { var radius = module.radius; + + AudioClip clip = null; + if (module.audioClip != null) clip = SearchUtilities.FindResourceOfTypeAndName(module.audioClip); + else if (module.audioFilePath != null) + { + try + { + clip = AudioUtilities.LoadAudio(mod.ModHelper.Manifest.ModFolderPath + "/" + module.audioFilePath); + } + catch (System.Exception e) + { + Utility.Logger.LogError($"Couldn't load audio file {module.audioFilePath} : {e.Message}"); + } + } + var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP"); var newCloak = GameObject.Instantiate(cloak, sector?.transform ?? planetGO.transform); @@ -31,6 +47,14 @@ namespace NewHorizons.Builder.Body var cloakSectorController = newCloak.AddComponent(); cloakSectorController.Init(newCloak.GetComponent(), planetGO); + var cloakAudioSource = newCloak.GetComponentInChildren(); + cloakAudioSource._audioSource = cloakAudioSource.GetComponent(); + cloakAudioSource._audioLibraryClip = AudioType.None; + cloakAudioSource._clipArrayIndex = 0; + cloakAudioSource._clipArrayLength = 0; + cloakAudioSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL; + cloakAudioSource.clip = clip; + newCloak.SetActive(true); cloakFieldController.enabled = true; @@ -38,6 +62,7 @@ namespace NewHorizons.Builder.Body // To cloak from the start Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit); + Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(clip != null ? cloakSectorController.TurnOnMusic : cloakSectorController.TurnOffMusic); Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(keepReferenceFrame ? cloakSectorController.EnableReferenceFrameVolume : cloakSectorController.DisableReferenceFrameVolume); } } diff --git a/NewHorizons/Components/CloakSectorController.cs b/NewHorizons/Components/CloakSectorController.cs index 9a047ddc..72a83aea 100644 --- a/NewHorizons/Components/CloakSectorController.cs +++ b/NewHorizons/Components/CloakSectorController.cs @@ -80,5 +80,8 @@ namespace NewHorizons.Components public void SetReferenceFrameVolumeActive(bool active) => _cloak._referenceFrameVolume.gameObject.SetActive(active); public void EnableReferenceFrameVolume() => SetReferenceFrameVolumeActive(true); public void DisableReferenceFrameVolume() => SetReferenceFrameVolumeActive(false); + + public void TurnOnMusic() => _cloak._hasTriggeredMusic = false; + public void TurnOffMusic() => _cloak._hasTriggeredMusic = true; } } diff --git a/NewHorizons/External/Modules/CloakModule.cs b/NewHorizons/External/Modules/CloakModule.cs index 87f6dbf7..55ad844c 100644 --- a/NewHorizons/External/Modules/CloakModule.cs +++ b/NewHorizons/External/Modules/CloakModule.cs @@ -15,5 +15,15 @@ namespace NewHorizons.External.Modules /// don't want a cloak, leave this as 0. /// public float radius; + + /// + /// Name of an existing AudioClip in the game that will play when entering the cloaking field. + /// + public string audioClip; + + /// + /// Relative filepath to the .wav file to use as the audio. Mutually exclusive with audioClip. + /// + public string audioFilePath; } } \ No newline at end of file diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index a6324b55..77ca0ebe 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -482,7 +482,7 @@ namespace NewHorizons.Handlers // Has to go last probably if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f) { - CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame); + CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame, body.Mod); } return go; diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5856cea7..4e929a02 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -297,6 +297,14 @@ "type": "number", "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", "format": "float" + }, + "audioClip": { + "type": "string", + "description": "Name of an existing AudioClip in the game that will play when entering the cloaking field." + }, + "audioFilePath": { + "type": "string", + "description": "Relative filepath to the .wav file to use as the audio. Mutually exclusive with audioClip." } } }, From d5d85cd7bec532931ee1b83995966b54419a310d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 23:31:22 -0400 Subject: [PATCH 08/72] Check for null hit object --- .../Utility/DebugUtilities/DebugRaycaster.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs b/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs index 1c34448b..86858a85 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using UnityEngine.InputSystem; namespace NewHorizons.Utility.DebugUtilities @@ -33,6 +33,7 @@ namespace NewHorizons.Utility.DebugUtilities internal void PrintRaycast() { DebugRaycastData data = Raycast(); + var posText = $"{{\"x\": {data.pos.x}, \"y\": {data.pos.y}, \"z\": {data.pos.z}}}"; var normText = $"{{\"x\": {data.norm.x}, \"y\": {data.norm.y}, \"z\": {data.norm.z}}}"; @@ -40,13 +41,16 @@ namespace NewHorizons.Utility.DebugUtilities if(_normalSphere1 != null) GameObject.Destroy(_normalSphere1); if(_normalSphere2 != null) GameObject.Destroy(_normalSphere2); - _surfaceSphere = AddDebugShape.AddSphere(data.hitObject, 0.1f, Color.green); - _normalSphere1 = AddDebugShape.AddSphere(data.hitObject, 0.01f, Color.red); - _normalSphere2 = AddDebugShape.AddSphere(data.hitObject, 0.01f, Color.red); + if (data.hitObject != null) + { + _surfaceSphere = AddDebugShape.AddSphere(data.hitObject, 0.1f, Color.green); + _normalSphere1 = AddDebugShape.AddSphere(data.hitObject, 0.01f, Color.red); + _normalSphere2 = AddDebugShape.AddSphere(data.hitObject, 0.01f, Color.red); - _surfaceSphere.transform.localPosition = data.pos; - _normalSphere1.transform.localPosition = data.pos + data.norm * 0.5f; - _normalSphere2.transform.localPosition = data.pos + data.norm; + _surfaceSphere.transform.localPosition = data.pos; + _normalSphere1.transform.localPosition = data.pos + data.norm * 0.5f; + _normalSphere2.transform.localPosition = data.pos + data.norm; + } Logger.Log($"Raycast hit \"position\": {posText}, \"normal\": {normText} on [{data.bodyName}] at [{data.bodyPath}]"); } From 5e1ddde7731cce0654a562e8e1193526f8d915a3 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 17:06:10 -0400 Subject: [PATCH 09/72] Add comment to detail --- NewHorizons/Builder/Props/DetailBuilder.cs | 5 +++++ NewHorizons/External/Modules/PropModule.cs | 5 +++++ NewHorizons/Schemas/body_schema.json | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 966be7ff..bfa69d09 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -62,6 +62,11 @@ namespace NewHorizons.Builder.Props detailGO = newDetailGO; } + if (detail.comment != null) + { + detailGO.name = detail.comment; + } + detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO; } diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index ca0c35e3..c1650079 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -113,6 +113,11 @@ namespace NewHorizons.External.Modules [JsonObject] public class DetailInfo { + /// + /// An optional rename of the detail + /// + public string comment; + /// /// Do we override rotation and try to automatically align this object to stand upright on the body's surface? /// diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 4e929a02..5f1f9bdd 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -793,6 +793,10 @@ "type": "object", "additionalProperties": false, "properties": { + "comment": { + "type": "string", + "description": "An optional rename of the detail" + }, "alignToNormal": { "type": "boolean", "description": "Do we override rotation and try to automatically align this object to stand upright on the body's surface?" From 661b084f663b214fc104a68506a524014eb405c8 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 15:19:19 -0400 Subject: [PATCH 10/72] Fix NullReferenceExceptions --- NewHorizons/Builder/Body/StarBuilder.cs | 4 +++- .../Builder/General/SpawnPointBuilder.cs | 7 ++++-- NewHorizons/Builder/Props/DetailBuilder.cs | 1 + .../StarEvolutionController.cs | 4 ++-- NewHorizons/Patches/MapControllerPatches.cs | 9 +++++++- NewHorizons/Patches/PlayerSpawnerPatches.cs | 2 +- NewHorizons/Patches/SunPatches.cs | 23 ++++++++++++++++++- 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index e51341ef..ba5d303a 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -133,11 +133,11 @@ namespace NewHorizons.Builder.Body // It fucking insists on this existing and its really annoying var supernovaVolume = new GameObject("SupernovaVolumePlaceholder"); supernovaVolume.transform.SetParent(starGO.transform); - supernova._supernovaVolume = supernovaVolume.AddComponent(); var sphere = supernovaVolume.AddComponent(); sphere.radius = 0f; sphere.isTrigger = true; supernovaVolume.AddComponent(); + supernova._supernovaVolume = supernovaVolume.AddComponent(); return starController; } @@ -148,6 +148,8 @@ namespace NewHorizons.Builder.Body var supernova = MakeSupernova(starGO, starModule); + supernova._belongsToProxySun = true; + starGO.SetActive(false); var controller = starGO.AddComponent(); if (starModule.curve != null) controller.scaleCurve = starModule.GetAnimationCurve(); diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index 05f6d7a4..f74767bd 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -18,8 +18,9 @@ namespace NewHorizons.Builder.General spawnGO.transform.localPosition = module.playerSpawnPoint; playerSpawn = spawnGO.AddComponent(); - - if(module.playerSpawnRotation != null) + playerSpawn._triggerVolumes = new OWTriggerVolume[0]; + + if (module.playerSpawnRotation != null) { spawnGO.transform.rotation = Quaternion.Euler(module.playerSpawnRotation); } @@ -40,6 +41,7 @@ namespace NewHorizons.Builder.General var spawnPoint = spawnGO.AddComponent(); spawnPoint._isShipSpawn = true; + spawnPoint._triggerVolumes = new OWTriggerVolume[0]; var ship = GameObject.Find("Ship_Body"); ship.transform.position = spawnPoint.transform.position; @@ -67,6 +69,7 @@ namespace NewHorizons.Builder.General playerSpawnGO.transform.localPosition = new Vector3(0, 0, 0); playerSpawn = playerSpawnGO.AddComponent(); + playerSpawn._triggerVolumes = new OWTriggerVolume[0]; playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0); } } diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index bfa69d09..54469e24 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -169,6 +169,7 @@ namespace NewHorizons.Builder.Props { try { + if (component == null) return; if (component is Animator animator) animator.enabled = true; else if (component is Collider collider) collider.enabled = true; else if (component is Renderer renderer) renderer.enabled = true; diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index c862f7fc..d27486fb 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -199,8 +199,8 @@ namespace NewHorizons.Components.SizeControllers supernova.enabled = true; _isSupernova = true; _supernovaStartTime = Time.time; - atmosphere.SetActive(false); - _destructionVolume._deathType = DeathType.Supernova; + if (atmosphere != null) atmosphere.SetActive(false); + if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova; return; } } diff --git a/NewHorizons/Patches/MapControllerPatches.cs b/NewHorizons/Patches/MapControllerPatches.cs index b3c25e29..5c6e626a 100644 --- a/NewHorizons/Patches/MapControllerPatches.cs +++ b/NewHorizons/Patches/MapControllerPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using UnityEngine.SceneManagement; namespace NewHorizons.Patches @@ -43,5 +43,12 @@ namespace NewHorizons.Patches return true; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ReferenceFrameTracker), nameof(ReferenceFrameTracker.UntargetReferenceFrame), new System.Type[] { typeof(bool) })] + public static bool ReferenceFrameTracker_UntargetReferenceFrame(ReferenceFrameTracker __instance, bool playAudio) + { + return __instance._hasTarget && __instance._currentReferenceFrame != null; + } } } diff --git a/NewHorizons/Patches/PlayerSpawnerPatches.cs b/NewHorizons/Patches/PlayerSpawnerPatches.cs index e6dec94d..09e9ff0a 100644 --- a/NewHorizons/Patches/PlayerSpawnerPatches.cs +++ b/NewHorizons/Patches/PlayerSpawnerPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Patches { diff --git a/NewHorizons/Patches/SunPatches.cs b/NewHorizons/Patches/SunPatches.cs index ba57ffee..447028bd 100644 --- a/NewHorizons/Patches/SunPatches.cs +++ b/NewHorizons/Patches/SunPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using UnityEngine; namespace NewHorizons.Patches { @@ -40,5 +40,26 @@ namespace NewHorizons.Patches __instance._audioSource.SetLocalVolume(num * num * __instance._fade); return false; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SunProxyEffectController), nameof(SunProxyEffectController.UpdateScales))] + public static bool SunProxyEffectController_UpdateScales(SunProxyEffectController __instance) + { + return __instance != null && __instance._surface != null && __instance._fog != null && __instance._fogMaterial != null && __instance._solarFlareEmitter != null && __instance._atmosphere != null; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SunProxyEffectController), nameof(SunProxyEffectController.UpdateAtmosphereRadii))] + public static bool SunProxyEffectController_UpdateAtmosphereRadii(SunProxyEffectController __instance) + { + return __instance != null && __instance.transform != null && __instance.transform.parent != null && __instance._atmosphereMaterial != null; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(VanishVolume), nameof(VanishVolume.Shrink))] + public static bool VanishVolume_Shrink(VanishVolume __instance, OWRigidbody bodyToShrink) + { + return __instance != null && __instance.transform != null && __instance._shrinkingBodies != null && __instance._shrinkingBodyLocationData != null && bodyToShrink != null; + } } } From 972059f3f057e00d74215dd1f83ba772c857b3ed Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 19:20:19 -0400 Subject: [PATCH 11/72] Reference Frame Module --- .../Builder/Body/AsteroidBeltBuilder.cs | 8 ++++-- .../Builder/General/RFVolumeBuilder.cs | 9 +++--- .../Builder/Orbital/FocalPointBuilder.cs | 4 +-- NewHorizons/External/Configs/PlanetConfig.cs | 8 ++++++ NewHorizons/External/Modules/BaseModule.cs | 8 ++---- .../External/Modules/ReferenceFrameModule.cs | 28 +++++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 6 ++-- NewHorizons/Schemas/body_schema.json | 25 +++++++++++++---- 8 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 NewHorizons/External/Modules/ReferenceFrameModule.cs diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 64543600..5e71238f 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -34,7 +34,6 @@ namespace NewHorizons.Builder.Body hasMapMarker = false, surfaceGravity = 1, surfaceSize = size, - hasReferenceFrame = false, gravityFallOff = GravityFallOff.InverseSquared }; @@ -49,6 +48,11 @@ namespace NewHorizons.Builder.Body showOrbitLine = false }; + config.ReferenceFrame = new ReferenceFrameModule() + { + hideInMap = true + }; + config.ProcGen = belt.procGen; if (config.ProcGen == null) { diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index f6831bb7..83e76cb5 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -1,10 +1,11 @@ using NewHorizons.External.Configs; +using NewHorizons.External.Modules; using UnityEngine; namespace NewHorizons.Builder.General { public static class RFVolumeBuilder { - public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, bool hide = false) + public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, ReferenceFrameModule module) { var rfGO = new GameObject("RFVolume"); rfGO.transform.parent = planetGO.transform; @@ -19,7 +20,7 @@ namespace NewHorizons.Builder.General var RFV = rfGO.AddComponent(); var RV = new ReferenceFrame(owrb); - RV._minSuitTargetDistance = sphereOfInfluence; + RV._minSuitTargetDistance = module.targetWhenClose ? 0 : sphereOfInfluence; RV._maxTargetDistance = 0; RV._autopilotArrivalDistance = 2.0f * sphereOfInfluence; RV._autoAlignmentDistance = sphereOfInfluence * 1.5f; @@ -28,7 +29,7 @@ namespace NewHorizons.Builder.General RV._matchAngularVelocity = true; RV._minMatchAngularVelocityDistance = 70; RV._maxMatchAngularVelocityDistance = 400; - RV._bracketsRadius = sphereOfInfluence; + RV._bracketsRadius = module.bracketRadius > -1 ? module.bracketRadius : sphereOfInfluence; RFV._referenceFrame = RV; RFV._minColliderRadius = sphereOfInfluence; @@ -38,7 +39,7 @@ namespace NewHorizons.Builder.General owrb.SetAttachedReferenceFrameVolume(RFV); - rfGO.SetActive(!hide); + rfGO.SetActive(!module.hideInMap); } } } diff --git a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs index c217664e..98a51bd9 100644 --- a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs +++ b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components.Orbital; +using NewHorizons.Components.Orbital; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; @@ -59,7 +59,7 @@ namespace NewHorizons.Builder.Orbital fakeMassConfig.name = config.name + "_FakeBarycenterMass"; fakeMassConfig.Base.sphereOfInfluence = 0; fakeMassConfig.Base.hasMapMarker = false; - fakeMassConfig.Base.hasReferenceFrame = false; + fakeMassConfig.ReferenceFrame.hideInMap = true; fakeMassConfig.Orbit = new OrbitModule(); fakeMassConfig.Orbit.CopyPropertiesFrom(config.Orbit); diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index bd748a62..ee652297 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -101,6 +101,11 @@ namespace NewHorizons.External.Configs /// public PropModule Props; + /// + /// Reference frame properties of this body + /// + public ReferenceFrameModule ReferenceFrame; + /// /// A list of paths to child GameObjects to destroy on this planet /// @@ -162,6 +167,7 @@ namespace NewHorizons.External.Configs if (Base == null) Base = new BaseModule(); if (Orbit == null) Orbit = new OrbitModule(); if (ShipLog == null) ShipLog = new ShipLogModule(); + if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule(); } public void MigrateAndValidate() @@ -195,6 +201,8 @@ namespace NewHorizons.External.Configs if (Base.isSatellite) Base.showMinimap = false; + if (!Base.hasReferenceFrame) ReferenceFrame.hideInMap = true; + if (childrenToDestroy != null) removeChildren = childrenToDestroy; if (Base.cloakRadius != 0) diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index 20645d16..b0e81c1a 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -56,11 +56,6 @@ namespace NewHorizons.External.Modules /// public bool hasMapMarker; - /// - /// Allows the object to be targeted on the map. - /// - [DefaultValue(true)] public bool hasReferenceFrame = true; - /// /// Can this planet survive entering a star? /// @@ -106,6 +101,9 @@ namespace NewHorizons.External.Modules [Obsolete("HasAmbientLight is deprecated, please use AmbientLight instead")] public bool hasAmbientLight; + [Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")] + [DefaultValue(true)] public bool hasReferenceFrame = true; + [Obsolete("CloakRadius is deprecated, please use CloakModule instead")] public float cloakRadius; diff --git a/NewHorizons/External/Modules/ReferenceFrameModule.cs b/NewHorizons/External/Modules/ReferenceFrameModule.cs new file mode 100644 index 00000000..e9dc02a4 --- /dev/null +++ b/NewHorizons/External/Modules/ReferenceFrameModule.cs @@ -0,0 +1,28 @@ +using System; +using System.ComponentModel; +using System.Runtime.Serialization; +using NewHorizons.Utility; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace NewHorizons.External.Modules +{ + [JsonObject] + public class ReferenceFrameModule + { + /// + /// Stop the object from being targeted on the map. + /// + public bool hideInMap; + + /// + /// Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence. + /// + [DefaultValue(-1)] public float bracketRadius = -1; + + /// + /// If it should be targetable even when super close. + /// + public bool targetWhenClose; + } +} \ No newline at end of file diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 77ca0ebe..1cb8f3d2 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Atmosphere; +using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Body; using NewHorizons.Builder.General; using NewHorizons.Builder.Orbital; @@ -306,7 +306,7 @@ namespace NewHorizons.Handlers GravityBuilder.Make(go, ao, owRigidBody, body.Config); } - RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, !body.Config.Base.hasReferenceFrame); + RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, body.Config.ReferenceFrame); if (body.Config.Base.hasMapMarker) { @@ -482,7 +482,7 @@ namespace NewHorizons.Handlers // Has to go last probably if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f) { - CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame, body.Mod); + CloakBuilder.Make(go, sector, rb, body.Config.Cloak, !body.Config.ReferenceFrame.hideInMap, body.Mod); } return go; diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5f1f9bdd..3badb0eb 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -428,11 +428,6 @@ "type": "boolean", "description": "If the body should have a marker on the map screen." }, - "hasReferenceFrame": { - "type": "boolean", - "description": "Allows the object to be targeted on the map.", - "default": true - }, "invulnerableToSun": { "type": "boolean", "description": "Can this planet survive entering a star?" @@ -459,6 +454,26 @@ } } }, + "ReferenceFrameModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "hideInMap": { + "type": "boolean", + "description": "Stop the object from being targeted on the map." + }, + "bracketRadius": { + "type": "number", + "description": "Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence.", + "format": "float", + "default": -1 + }, + "targetWhenClose": { + "type": "boolean", + "description": "If it should be targetable even when super close." + } + } + }, "MVector3": { "type": "object", "additionalProperties": false, From 62ecee98e34ac595ff940a1475dfd27c26c08e11 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 19:33:28 -0400 Subject: [PATCH 12/72] Zero Gravity Volume --- .../Builder/Atmosphere/VolumesBuilder.cs | 30 +++++++++++++++++-- NewHorizons/External/Modules/BaseModule.cs | 5 ++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- NewHorizons/Schemas/body_schema.json | 5 ++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index f4e7e17c..12ccc732 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using UnityEngine; namespace NewHorizons.Builder.Atmosphere { @@ -6,7 +6,7 @@ namespace NewHorizons.Builder.Atmosphere { private static readonly int FogColor = Shader.PropertyToID("_FogColor"); - public static void Make(GameObject planetGO, PlanetConfig config, float sphereOfInfluence) + public static void Make(GameObject planetGO, OWRigidbody owrb, PlanetConfig config, float sphereOfInfluence) { var innerRadius = config.Base.surfaceSize; @@ -48,6 +48,32 @@ namespace NewHorizons.Builder.Atmosphere } ER._cloudMaterial = cloudMaterial; + if (config.Base.zeroGravityRadius != 0) + { + var zeroGObject = new GameObject("ZeroGVolume"); + zeroGObject.transform.parent = volumesGO.transform; + zeroGObject.transform.localPosition = Vector3.zero; + zeroGObject.transform.localScale = Vector3.one * config.Base.zeroGravityRadius; + zeroGObject.layer = LayerMask.NameToLayer("BasicEffectVolume"); + + var sphereCollider = zeroGObject.AddComponent(); + sphereCollider.radius = 1; + sphereCollider.isTrigger = true; + + var owCollider = zeroGObject.AddComponent(); + owCollider._parentBody = owrb; + owCollider._collider = sphereCollider; + + var triggerVolume = zeroGObject.AddComponent(); + triggerVolume._owCollider = owCollider; + + var zeroGVolume = zeroGObject.AddComponent(); + zeroGVolume._attachedBody = owrb; + zeroGVolume._triggerVolume = triggerVolume; + zeroGVolume._inheritable = true; + zeroGVolume._priority = 1; + } + volumesGO.transform.position = planetGO.transform.position; rulesetGO.SetActive(true); volumesGO.SetActive(true); diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index b0e81c1a..27858633 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -81,6 +81,11 @@ namespace NewHorizons.External.Modules /// public float surfaceSize; + /// + /// Radius of the zero gravity volume. This will make it so no gravity from any planet will affect you. Useful for satellites. + /// + public float zeroGravityRadius; + #region Obsolete [Obsolete("IsSatellite is deprecated, please use ShowMinimap instead")] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 1cb8f3d2..b79e5116 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -313,7 +313,7 @@ namespace NewHorizons.Handlers MarkerBuilder.Make(go, body.Config.name, body.Config); } - VolumesBuilder.Make(go, body.Config, sphereOfInfluence); + VolumesBuilder.Make(go, owRigidBody, body.Config, sphereOfInfluence); if (body.Config.FocalPoint != null) { diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 3badb0eb..cc33cc0e 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -451,6 +451,11 @@ "type": "number", "description": "A scale height used for a number of things. Should be the approximate radius of the body.", "format": "float" + }, + "zeroGravityRadius": { + "type": "number", + "description": "Radius of the zero gravity sphere. This sphere will make gravity no longer affect you while you are inside it. Useful for satellites.", + "format": "float" } } }, From 9e3fb210c7b33442880c6d2ca11b07261d8957a7 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 23:13:32 -0400 Subject: [PATCH 13/72] Set Proxy Shadow Caster Super Group --- NewHorizons/Builder/Body/HeightMapBuilder.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index cf9e359a..50d7c93a 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Body.Geometry; +using NewHorizons.Builder.Body.Geometry; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -57,7 +57,8 @@ namespace NewHorizons.Builder.Body var cubeSphereMC = cubeSphere.AddComponent(); cubeSphereMC.sharedMesh = mesh; - if (planetGO.GetComponent() != null) cubeSphere.AddComponent(); + var superGroup = planetGO.GetComponent(); + if (superGroup != null) cubeSphere.AddComponent()._superGroup = superGroup; // Fix rotation in the end cubeSphere.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); From 3055d0f2c93a1d06dad11c64022af93398d7dd8c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 23:14:02 -0400 Subject: [PATCH 14/72] Add ProxyShadowCaster when ProxyShadowCasterSuperGroup exists --- NewHorizons/Builder/Body/ProcGenBuilder.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/ProcGenBuilder.cs b/NewHorizons/Builder/Body/ProcGenBuilder.cs index af13da22..13d18b1a 100644 --- a/NewHorizons/Builder/Body/ProcGenBuilder.cs +++ b/NewHorizons/Builder/Body/ProcGenBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Body.Geometry; +using NewHorizons.Builder.Body.Geometry; using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; @@ -16,6 +16,7 @@ namespace NewHorizons.Builder.Body GameObject icosphere = new GameObject("Icosphere"); + icosphere.SetActive(false); icosphere.transform.parent = sector?.transform ?? planetGO.transform; icosphere.transform.rotation = Quaternion.Euler(90, 0, 0); icosphere.transform.position = planetGO.transform.position; @@ -33,7 +34,10 @@ namespace NewHorizons.Builder.Body cubeSphereMC.sharedMesh = mesh; icosphere.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - icosphere.AddComponent(); + var superGroup = planetGO.GetComponent(); + if (superGroup != null) icosphere.AddComponent()._superGroup = superGroup; + + icosphere.SetActive(true); } } } From 33703dc221812798d74cb6cba422dbd10506820c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 23:14:27 -0400 Subject: [PATCH 15/72] More detail for exception --- NewHorizons/Builder/Props/DetailBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 54469e24..98c3927d 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -192,7 +192,7 @@ namespace NewHorizons.Builder.Props } catch (Exception e) { - Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] : {e.Message}, {e.StackTrace}"); + Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab.name}] : {e.GetType().FullName} {e.Message} {e.StackTrace}"); } }); } From 6d4ad5d531e52680ce8284a81465b662592e5b2f Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 15:19:28 -0400 Subject: [PATCH 16/72] Simplify --- NewHorizons/Builder/Body/ProcGenBuilder.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/ProcGenBuilder.cs b/NewHorizons/Builder/Body/ProcGenBuilder.cs index 13d18b1a..156b6ba6 100644 --- a/NewHorizons/Builder/Body/ProcGenBuilder.cs +++ b/NewHorizons/Builder/Body/ProcGenBuilder.cs @@ -23,8 +23,7 @@ namespace NewHorizons.Builder.Body Mesh mesh = Icosphere.Build(4, module.scale, module.scale * 1.2f); - icosphere.AddComponent(); - icosphere.GetComponent().mesh = mesh; + icosphere.AddComponent().mesh = mesh; var cubeSphereMR = icosphere.AddComponent(); cubeSphereMR.material = new Material(Shader.Find("Standard")); From 8a1e77fa8d95b671e65eeb731834732523da0b6c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 00:39:43 -0400 Subject: [PATCH 17/72] Fix not found error --- NewHorizons/Utility/SearchUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs index 6697ebdc..46a5ca16 100644 --- a/NewHorizons/Utility/SearchUtilities.cs +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -162,7 +162,7 @@ namespace NewHorizons.Utility { foreach (Transform c in t.GetComponentsInChildren(true)) { - if (t.name.Equals(names[i])) + if (c.name.Equals(names[i])) { child = c; break; From 18f1b2a605a988e5e78eb954729213727a3ba771 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 00:56:12 -0400 Subject: [PATCH 18/72] Use SearchUtilities.Find instead GameObject.Find --- .../Builder/Atmosphere/AtmosphereBuilder.cs | 5 ++- .../Builder/Atmosphere/CloudsBuilder.cs | 10 ++--- NewHorizons/Builder/Atmosphere/FogBuilder.cs | 6 +-- .../Builder/Atmosphere/VolumesBuilder.cs | 3 +- NewHorizons/Builder/Body/CometTailBuilder.cs | 5 ++- NewHorizons/Builder/Body/FunnelBuilder.cs | 12 +++--- NewHorizons/Builder/Body/GeometryBuilder.cs | 5 ++- NewHorizons/Builder/Body/LavaBuilder.cs | 9 +++-- NewHorizons/Builder/Body/ProxyBuilder.cs | 6 +-- NewHorizons/Builder/Body/SandBuilder.cs | 10 ++--- .../Builder/Body/SingularityBuilder.cs | 24 +++++------ NewHorizons/Builder/Body/StarBuilder.cs | 26 ++++++------ NewHorizons/Builder/Body/WaterBuilder.cs | 8 ++-- .../Builder/General/AmbientLightBuilder.cs | 5 ++- .../Builder/General/RigidBodyBuilder.cs | 5 ++- .../Builder/General/SpawnPointBuilder.cs | 7 ++-- NewHorizons/Builder/Props/DetailBuilder.cs | 2 +- NewHorizons/Builder/Props/GeyserBuilder.cs | 4 +- NewHorizons/Builder/Props/NomaiTextBuilder.cs | 8 ++-- .../Builder/Props/ProjectionBuilder.cs | 6 +-- NewHorizons/Builder/Props/ScatterBuilder.cs | 4 +- NewHorizons/Builder/Props/SignalBuilder.cs | 4 +- NewHorizons/Builder/Props/TornadoBuilder.cs | 8 ++-- NewHorizons/Builder/Props/VolcanoBuilder.cs | 4 +- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 8 ++-- .../Components/ShipLogStarChartMode.cs | 4 +- NewHorizons/Components/ShipWarpController.cs | 9 +++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 16 ++++---- .../Handlers/PlanetDestructionHandler.cs | 16 ++++---- NewHorizons/Handlers/ShipLogHandler.cs | 4 +- NewHorizons/Handlers/StarChartHandler.cs | 8 ++-- NewHorizons/Handlers/SystemCreationHandler.cs | 4 +- NewHorizons/Handlers/TitleSceneHandler.cs | 10 ++--- NewHorizons/Main.cs | 8 ++-- NewHorizons/Patches/ShipLogPatches.cs | 10 ++--- NewHorizons/Patches/WarpDrivePatches.cs | 5 ++- NewHorizons/Utility/AstroObjectLocator.cs | 40 +++++++++---------- .../Utility/DebugUtilities/DebugReload.cs | 4 +- NewHorizons/Utility/SearchUtilities.cs | 8 ++-- 39 files changed, 175 insertions(+), 165 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs index c60ae6a3..5260fbf7 100644 --- a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Atmosphere { @@ -16,7 +17,7 @@ namespace NewHorizons.Builder.Atmosphere if (atmosphereModule.useAtmosphereShader) { - GameObject atmo = GameObject.Instantiate(GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true); + GameObject atmo = GameObject.Instantiate(SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true); atmo.transform.position = planetGO.transform.TransformPoint(Vector3.zero); atmo.transform.localScale = Vector3.one * atmosphereModule.size * 1.2f; foreach (var meshRenderer in atmo.GetComponentsInChildren()) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 8363f36a..82900a6b 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -21,7 +21,7 @@ namespace NewHorizons.Builder.Atmosphere public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) { - if (_lightningPrefab == null) _lightningPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); + if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); GameObject cloudsMainGO = new GameObject("Clouds"); @@ -36,8 +36,8 @@ namespace NewHorizons.Builder.Atmosphere cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); - bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; - var bottomTSRMaterials = GameObject.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; + bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; + var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; // If they set a colour apply it to all the materials else keep the default QM one if (atmo.clouds.tint != null) @@ -165,12 +165,12 @@ namespace NewHorizons.Builder.Atmosphere cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; MeshFilter topMF = cloudsTopGO.AddComponent(); - topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; + topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; MeshRenderer topMR = cloudsTopGO.AddComponent(); if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); - if (_gdCloudMaterials == null) _gdCloudMaterials = GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; + if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; var tempArray = new Material[2]; if (atmo.clouds.useBasicCloudShader) diff --git a/NewHorizons/Builder/Atmosphere/FogBuilder.cs b/NewHorizons/Builder/Atmosphere/FogBuilder.cs index b521ede5..4eae1a82 100644 --- a/NewHorizons/Builder/Atmosphere/FogBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/FogBuilder.cs @@ -17,9 +17,9 @@ namespace NewHorizons.Builder.Atmosphere fogGO.transform.localScale = Vector3.one; // Going to copy from dark bramble - var dbFog = GameObject.Find("DarkBramble_Body/Atmosphere_DB/FogLOD"); - var dbPlanetaryFogController = GameObject.Find("DarkBramble_Body/Atmosphere_DB/FogSphere_DB").GetComponent(); - var brambleLODFog = GameObject.Find("DarkBramble_Body/Sector_DB/Proxy_DB/LOD_DB_VolumeticFog"); + var dbFog = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogLOD"); + var dbPlanetaryFogController = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogSphere_DB").GetComponent(); + var brambleLODFog = SearchUtilities.Find("DarkBramble_Body/Sector_DB/Proxy_DB/LOD_DB_VolumeticFog"); MeshFilter MF = fogGO.AddComponent(); MF.mesh = dbFog.GetComponent().mesh; diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index 12ccc732..cba3845d 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.External.Configs; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Atmosphere { @@ -37,7 +38,7 @@ namespace NewHorizons.Builder.Atmosphere EffectRuleset ER = rulesetGO.AddComponent(); ER._type = EffectRuleset.BubbleType.Underwater; - var gdRuleset = GameObject.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent(); + var gdRuleset = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent(); ER._material = gdRuleset._material; diff --git a/NewHorizons/Builder/Body/CometTailBuilder.cs b/NewHorizons/Builder/Body/CometTailBuilder.cs index be13a836..5980b2d1 100644 --- a/NewHorizons/Builder/Body/CometTailBuilder.cs +++ b/NewHorizons/Builder/Body/CometTailBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Body { @@ -6,7 +7,7 @@ namespace NewHorizons.Builder.Body { public static void Make(GameObject planetGO, Sector sector, PlanetConfig config) { - var cometTail = GameObject.Instantiate(GameObject.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes"), sector?.transform ?? planetGO.transform); + var cometTail = GameObject.Instantiate(SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes"), sector?.transform ?? planetGO.transform); cometTail.transform.position = planetGO.transform.position; cometTail.name = "CometTail"; cometTail.transform.localScale = Vector3.one * config.Base.surfaceSize / 110; diff --git a/NewHorizons/Builder/Body/FunnelBuilder.cs b/NewHorizons/Builder/Body/FunnelBuilder.cs index 9c54486f..eea69694 100644 --- a/NewHorizons/Builder/Body/FunnelBuilder.cs +++ b/NewHorizons/Builder/Body/FunnelBuilder.cs @@ -1,4 +1,4 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization; using NewHorizons.Components; using NewHorizons.Utility; using UnityEngine; @@ -43,13 +43,13 @@ namespace NewHorizons.Builder.Body scaleRoot.transform.localPosition = Vector3.zero; scaleRoot.transform.localScale = new Vector3(1, 1, 1); - var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform); + var proxyGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform); proxyGO.name = "Proxy_Funnel"; - var geoGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel"), scaleRoot.transform); + var geoGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel"), scaleRoot.transform); geoGO.name = "Geo_Funnel"; - var volumesGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform); + var volumesGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform); volumesGO.name = "Volumes_Funnel"; var sfv = volumesGO.GetComponentInChildren(); var fluidVolume = sfv.gameObject; @@ -63,7 +63,7 @@ namespace NewHorizons.Builder.Body GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject); - var waterMaterials = GameObject.Find("TimberHearth_Body/Sector_TH/Geometry_TH/Terrain_TH_Water_v3/Village_Upper_Water/Village_Upper_Water_Geo").GetComponent().materials; + var waterMaterials = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Geometry_TH/Terrain_TH_Water_v3/Village_Upper_Water/Village_Upper_Water_Geo").GetComponent().materials; var materials = new Material[waterMaterials.Length]; for (int i = 0; i < waterMaterials.Length; i++) { @@ -111,7 +111,7 @@ namespace NewHorizons.Builder.Body GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject); - var lavaMaterial = new Material(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent().material); + var lavaMaterial = new Material(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent().material); lavaMaterial.mainTextureOffset = new Vector2(0.1f, 0.2f); lavaMaterial.mainTextureScale = new Vector2(1f, 3f); diff --git a/NewHorizons/Builder/Body/GeometryBuilder.cs b/NewHorizons/Builder/Body/GeometryBuilder.cs index dc422e71..fb0fc698 100644 --- a/NewHorizons/Builder/Body/GeometryBuilder.cs +++ b/NewHorizons/Builder/Body/GeometryBuilder.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using UnityEngine; +using NewHorizons.Utility; namespace NewHorizons.Builder.Body { public static class GeometryBuilder @@ -9,7 +10,7 @@ namespace NewHorizons.Builder.Body groundGO.transform.parent = sector?.transform ?? planetGO.transform; groundGO.transform.localScale = new Vector3(groundScale, groundScale, groundScale); groundGO.transform.position = planetGO.transform.position; - groundGO.GetComponent().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; + groundGO.GetComponent().mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; groundGO.GetComponent().radius = 1f; groundGO.SetActive(true); } diff --git a/NewHorizons/Builder/Body/LavaBuilder.cs b/NewHorizons/Builder/Body/LavaBuilder.cs index ea831506..dc1d4d47 100644 --- a/NewHorizons/Builder/Body/LavaBuilder.cs +++ b/NewHorizons/Builder/Body/LavaBuilder.cs @@ -1,5 +1,6 @@ -using System.Collections.Generic; +using System.Collections.Generic; using UnityEngine; +using NewHorizons.Utility; using NewHorizons.External.Modules.VariableSize; namespace NewHorizons.Builder.Body @@ -28,7 +29,7 @@ namespace NewHorizons.Builder.Body moltenCore.transform.position = planetGO.transform.position; moltenCore.transform.localScale = Vector3.one * module.size; - var lavaSphere = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform); + var lavaSphere = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform); lavaSphere.transform.localScale = Vector3.one; lavaSphere.transform.name = "LavaSphere"; lavaSphere.GetComponent().material.SetFloat(HeightScale, heightScale); @@ -37,7 +38,7 @@ namespace NewHorizons.Builder.Body var sectorCullGroup = lavaSphere.GetComponent(); sectorCullGroup.SetSector(sector); - var moltenCoreProxy = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/MoltenCore_Proxy"), moltenCore.transform); ; + var moltenCoreProxy = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/MoltenCore_Proxy"), moltenCore.transform); ; moltenCoreProxy.name = "MoltenCore_Proxy"; var proxyLavaSphere = moltenCoreProxy.transform.Find("LavaSphere (1)"); @@ -50,7 +51,7 @@ namespace NewHorizons.Builder.Body sectorProxy._renderers = new List { proxyLavaSphere.GetComponent() }; sectorProxy.SetSector(sector); - var destructionVolume = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/DestructionVolume"), moltenCore.transform); + var destructionVolume = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/DestructionVolume"), moltenCore.transform); destructionVolume.GetComponent().radius = 1; destructionVolume.SetActive(true); diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index fb950a47..aea9a019 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Atmosphere; +using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Props; using NewHorizons.Components; using NewHorizons.Components.SizeControllers; @@ -176,7 +176,7 @@ namespace NewHorizons.Builder.Body private static void MakeBlackHole(GameObject rootObject, float size) { - if (_blackHolePrefab == null) _blackHolePrefab = GameObject.Find(_blackHolePath); + if (_blackHolePrefab == null) _blackHolePrefab = SearchUtilities.Find(_blackHolePath); var blackHoleShader = _blackHolePrefab.GetComponent().material.shader; if (blackHoleShader == null) blackHoleShader = _blackHolePrefab.GetComponent().sharedMaterial.shader; @@ -201,7 +201,7 @@ namespace NewHorizons.Builder.Body private static void MakeWhiteHole(GameObject rootObject, float size) { - if (_whiteHolePrefab == null) _whiteHolePrefab = GameObject.Find(_whiteHolePath); + if (_whiteHolePrefab == null) _whiteHolePrefab = SearchUtilities.Find(_whiteHolePath); var whiteHoleShader = _whiteHolePrefab.GetComponent().material.shader; if (whiteHoleShader == null) whiteHoleShader = _whiteHolePrefab.GetComponent().sharedMaterial.shader; diff --git a/NewHorizons/Builder/Body/SandBuilder.cs b/NewHorizons/Builder/Body/SandBuilder.cs index 35de7c8b..43b86ac5 100644 --- a/NewHorizons/Builder/Body/SandBuilder.cs +++ b/NewHorizons/Builder/Body/SandBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Utility; +using NewHorizons.Utility; using UnityEngine; using NewHorizons.External.Modules.VariableSize; @@ -11,7 +11,7 @@ namespace NewHorizons.Builder.Body var sandGO = new GameObject("Sand"); sandGO.SetActive(false); - var sandSphere = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/SandSphere"), sandGO.transform); + var sandSphere = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/SandSphere"), sandGO.transform); if (module.tint != null) { var oldMR = sandSphere.GetComponent(); @@ -28,13 +28,13 @@ namespace NewHorizons.Builder.Body sandMR.sharedMaterials[1].color = module.tint.ToColor(); } - var collider = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/Collider"), sandGO.transform); + var collider = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/Collider"), sandGO.transform); var sphereCollider = collider.GetComponent(); collider.SetActive(true); - var occlusionSphere = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/OcclusionSphere"), sandGO.transform); + var occlusionSphere = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/OcclusionSphere"), sandGO.transform); - var proxyShadowCasterGO = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/ProxyShadowCaster"), sandGO.transform); + var proxyShadowCasterGO = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/ProxyShadowCaster"), sandGO.transform); var proxyShadowCaster = proxyShadowCasterGO.GetComponent(); proxyShadowCaster.SetSuperGroup(sandGO.GetComponent()); diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index 949041f0..b9a031f6 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.External.Configs; using NewHorizons.Utility; using System; @@ -88,10 +88,10 @@ namespace NewHorizons.Builder.Body blackHoleRender.transform.localScale = Vector3.one * size; var meshFilter = blackHoleRender.AddComponent(); - meshFilter.mesh = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().mesh; + meshFilter.mesh = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().mesh; var meshRenderer = blackHoleRender.AddComponent(); - if (blackHoleShader == null) blackHoleShader = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().sharedMaterial.shader; + if (blackHoleShader == null) blackHoleShader = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().sharedMaterial.shader; meshRenderer.material = new Material(blackHoleShader); meshRenderer.material.SetFloat(Radius, size * 0.4f); meshRenderer.material.SetFloat(MaxDistortRadius, size * 0.95f); @@ -100,7 +100,7 @@ namespace NewHorizons.Builder.Body if (makeAudio) { - var blackHoleAmbience = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleAmbience"), blackHole.transform); + var blackHoleAmbience = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleAmbience"), blackHole.transform); blackHoleAmbience.name = "BlackHoleAmbience"; blackHoleAmbience.GetComponent().SetSector(sector); @@ -109,7 +109,7 @@ namespace NewHorizons.Builder.Body blackHoleAudioSource.minDistance = size * 0.4f; blackHoleAmbience.transform.localPosition = Vector3.zero; - var blackHoleOneShot = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleEmissionOneShot"), blackHole.transform); + var blackHoleOneShot = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleEmissionOneShot"), blackHole.transform); var oneShotAudioSource = blackHoleOneShot.GetComponent(); oneShotAudioSource.maxDistance = size * 3f; oneShotAudioSource.minDistance = size * 0.4f; @@ -137,7 +137,7 @@ namespace NewHorizons.Builder.Body } else { - var blackHoleVolume = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume"), blackHole.transform); + var blackHoleVolume = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume"), blackHole.transform); blackHoleVolume.name = "BlackHoleVolume"; blackHoleVolume.GetComponent().radius = size * 0.4f; } @@ -159,10 +159,10 @@ namespace NewHorizons.Builder.Body whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f; var meshFilter = whiteHoleRenderer.AddComponent(); - meshFilter.mesh = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().mesh; + meshFilter.mesh = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().mesh; var meshRenderer = whiteHoleRenderer.AddComponent(); - if (whiteHoleShader == null) whiteHoleShader = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().sharedMaterial.shader; + if (whiteHoleShader == null) whiteHoleShader = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().sharedMaterial.shader; meshRenderer.material = new Material(whiteHoleShader); meshRenderer.sharedMaterial.SetFloat(Radius, size * 0.4f); meshRenderer.sharedMaterial.SetFloat(DistortFadeDist, size); @@ -170,14 +170,14 @@ namespace NewHorizons.Builder.Body meshRenderer.sharedMaterial.SetFloat(MassScale, -1); meshRenderer.sharedMaterial.SetColor(Color1, new Color(1.88f, 1.88f, 1.88f, 1f)); - var ambientLight = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH")); + var ambientLight = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH")); ambientLight.transform.parent = whiteHole.transform; ambientLight.transform.localScale = Vector3.one; ambientLight.transform.localPosition = Vector3.zero; ambientLight.name = "AmbientLight"; ambientLight.GetComponent().range = size * 7f; - GameObject whiteHoleVolumeGO = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVolume")); + GameObject whiteHoleVolumeGO = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/WhiteHoleVolume")); whiteHoleVolumeGO.transform.parent = whiteHole.transform; whiteHoleVolumeGO.transform.localPosition = Vector3.zero; whiteHoleVolumeGO.transform.localScale = Vector3.one; @@ -205,13 +205,13 @@ namespace NewHorizons.Builder.Body if (makeZeroGVolume) { - var zeroGVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/ZeroGVolume"), whiteHole.transform); + var zeroGVolume = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/ZeroGVolume"), whiteHole.transform); zeroGVolume.name = "ZeroGVolume"; zeroGVolume.transform.localPosition = Vector3.zero; zeroGVolume.GetComponent().radius = size * 10f; zeroGVolume.GetComponent()._attachedBody = OWRB; - var rulesetVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole"), planetGO.transform); + var rulesetVolume = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole"), planetGO.transform); rulesetVolume.name = "RulesetVolume"; rulesetVolume.transform.localPosition = Vector3.zero; rulesetVolume.transform.localScale = Vector3.one * size / 100f; diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index ba5d303a..aa0cc253 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -23,7 +23,7 @@ namespace NewHorizons.Builder.Body { var starGO = MakeStarGraphics(planetGO, sector, starModule); - var sunAudio = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); + var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); sunAudio.transform.localPosition = Vector3.zero; sunAudio.transform.localScale = Vector3.one; sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent().maxDistance = starModule.size * 2f; @@ -36,7 +36,7 @@ namespace NewHorizons.Builder.Body GameObject sunAtmosphere = null; if (starModule.hasAtmosphere) { - sunAtmosphere = Object.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); + sunAtmosphere = Object.Instantiate(SearchUtilities.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); sunAtmosphere.transform.position = planetGO.transform.position; sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio; sunAtmosphere.name = "Atmosphere_Star"; @@ -59,17 +59,17 @@ namespace NewHorizons.Builder.Body fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f); } - var ambientLightGO = Object.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); + var ambientLightGO = Object.Instantiate(SearchUtilities.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); ambientLightGO.transform.localPosition = Vector3.zero; ambientLightGO.name = "AmbientLight_Star"; - var heatVolume = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), starGO.transform); + var heatVolume = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), starGO.transform); heatVolume.transform.localPosition = Vector3.zero; heatVolume.transform.localScale = Vector3.one; heatVolume.GetComponent().radius = 1f; heatVolume.name = "HeatVolume"; - var deathVolume = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), starGO.transform); + var deathVolume = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), starGO.transform); deathVolume.transform.localPosition = Vector3.zero; deathVolume.transform.localScale = Vector3.one; deathVolume.GetComponent().radius = 1f; @@ -85,7 +85,7 @@ namespace NewHorizons.Builder.Body sunLight.transform.localScale = Vector3.one; var light = sunLight.AddComponent(); - light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.solarLuminosity; light.range *= Mathf.Sqrt(starModule.solarLuminosity); @@ -96,12 +96,12 @@ namespace NewHorizons.Builder.Body ambientLight.color = lightColour; var faceActiveCamera = sunLight.AddComponent(); - faceActiveCamera.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + faceActiveCamera.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); var csmTextureCacher = sunLight.AddComponent(); - csmTextureCacher.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + csmTextureCacher.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); csmTextureCacher._light = light; var proxyShadowLight = sunLight.AddComponent(); - proxyShadowLight.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + proxyShadowLight.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); proxyShadowLight._light = light; StarController starController = null; @@ -172,12 +172,12 @@ namespace NewHorizons.Builder.Body var starGO = new GameObject("Star"); starGO.transform.parent = sector?.transform ?? rootObject.transform; - var sunSurface = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform); + var sunSurface = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform); sunSurface.transform.position = rootObject.transform.position; sunSurface.transform.localScale = Vector3.one; sunSurface.name = "Surface"; - var solarFlareEmitter = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform); + var solarFlareEmitter = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform); solarFlareEmitter.transform.localPosition = Vector3.zero; solarFlareEmitter.transform.localScale = Vector3.one; solarFlareEmitter.name = "SolarFlareEmitter"; @@ -204,7 +204,7 @@ namespace NewHorizons.Builder.Body var colour = starModule.tint.ToColor(); - var sun = GameObject.Find("Sun_Body"); + var sun = SearchUtilities.Find("Sun_Body"); var mainSequenceMaterial = sun.GetComponent()._startSurfaceMaterial; var giantMaterial = sun.GetComponent()._endSurfaceMaterial; @@ -230,7 +230,7 @@ namespace NewHorizons.Builder.Body private static SupernovaEffectController MakeSupernova(GameObject starGO, StarModule starModule) { - var supernovaGO = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); + var supernovaGO = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); supernovaGO.transform.SetParent(starGO.transform); supernovaGO.transform.localPosition = Vector3.zero; diff --git a/NewHorizons/Builder/Body/WaterBuilder.cs b/NewHorizons/Builder/Body/WaterBuilder.cs index 5780e638..fdb85ec8 100644 --- a/NewHorizons/Builder/Body/WaterBuilder.cs +++ b/NewHorizons/Builder/Body/WaterBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.Components.SizeControllers; using NewHorizons.Utility; using UnityEngine; @@ -19,7 +19,7 @@ namespace NewHorizons.Builder.Body waterGO.transform.parent = sector?.transform ?? planetGO.transform; waterGO.transform.localScale = new Vector3(waterSize, waterSize, waterSize); - var GDTSR = GameObject.Find("Ocean_GD").GetComponent(); + var GDTSR = SearchUtilities.Find("Ocean_GD").GetComponent(); TessellatedSphereRenderer TSR = waterGO.AddComponent(); TSR.tessellationMeshGroup = ScriptableObject.CreateInstance(); @@ -30,7 +30,7 @@ namespace NewHorizons.Builder.Body TSR.tessellationMeshGroup.variants[i] = mesh; } - var GDSharedMaterials = GameObject.Find("Ocean_GD").GetComponent()._lowAltitudeMaterials; + var GDSharedMaterials = SearchUtilities.Find("Ocean_GD").GetComponent()._lowAltitudeMaterials; var tempArray = new Material[GDSharedMaterials.Length]; for (int i = 0; i < GDSharedMaterials.Length; i++) { @@ -87,7 +87,7 @@ namespace NewHorizons.Builder.Body fluidVolume._radius = waterSize; fluidVolume._layer = LayerMask.NameToLayer("BasicEffectVolume"); - var fogGO = GameObject.Instantiate(GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/OceanFog"), waterGO.transform); + var fogGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/OceanFog"), waterGO.transform); fogGO.name = "OceanFog"; fogGO.transform.localPosition = Vector3.zero; fogGO.transform.localScale = Vector3.one; diff --git a/NewHorizons/Builder/General/AmbientLightBuilder.cs b/NewHorizons/Builder/General/AmbientLightBuilder.cs index 6ad20aaf..c51f90c0 100644 --- a/NewHorizons/Builder/General/AmbientLightBuilder.cs +++ b/NewHorizons/Builder/General/AmbientLightBuilder.cs @@ -1,11 +1,12 @@ -using UnityEngine; +using UnityEngine; +using NewHorizons.Utility; namespace NewHorizons.Builder.General { public static class AmbientLightBuilder { public static void Make(GameObject planetGO, Sector sector, float scale, float intensity) { - GameObject lightGO = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/AmbientLight_BH_Surface"), sector?.transform ?? planetGO.transform); + GameObject lightGO = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/AmbientLight_BH_Surface"), sector?.transform ?? planetGO.transform); lightGO.transform.position = planetGO.transform.position; lightGO.name = "Light"; diff --git a/NewHorizons/Builder/General/RigidBodyBuilder.cs b/NewHorizons/Builder/General/RigidBodyBuilder.cs index f6672314..a827cc2e 100644 --- a/NewHorizons/Builder/General/RigidBodyBuilder.cs +++ b/NewHorizons/Builder/General/RigidBodyBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.General { @@ -27,7 +28,7 @@ namespace NewHorizons.Builder.General owRigidBody._maintainOriginalCenterOfMass = true; owRigidBody._rigidbody = rigidBody; owRigidBody._kinematicRigidbody = kinematicRigidBody; - owRigidBody._origParent = GameObject.Find("SolarSystemRoot").transform; + owRigidBody._origParent = SearchUtilities.Find("SolarSystemRoot").transform; owRigidBody.EnableKinematicSimulation(); owRigidBody.MakeKinematic(); diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index f74767bd..8c26fd9c 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; +using NewHorizons.Utility; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.General @@ -43,7 +44,7 @@ namespace NewHorizons.Builder.General spawnPoint._isShipSpawn = true; spawnPoint._triggerVolumes = new OWTriggerVolume[0]; - var ship = GameObject.Find("Ship_Body"); + var ship = SearchUtilities.Find("Ship_Body"); ship.transform.position = spawnPoint.transform.position; if(module.shipSpawnRotation != null) @@ -92,7 +93,7 @@ namespace NewHorizons.Builder.General Locator.GetPlayerTransform().GetComponent().SuitUp(false, true, true); // Make the ship act as if the player took the suit - var spv = GameObject.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear")?.GetComponent(); + var spv = SearchUtilities.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear")?.GetComponent(); if (spv == null) return; diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 98c3927d..61287cb4 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -150,7 +150,7 @@ namespace NewHorizons.Builder.Props { torchItem.enabled = true; torchItem.mindProjectorTrigger.enabled = true; - torchItem.mindSlideProjector._mindProjectorImageEffect = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); + torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); } } else diff --git a/NewHorizons/Builder/Props/GeyserBuilder.cs b/NewHorizons/Builder/Props/GeyserBuilder.cs index bd177925..6cb77acb 100644 --- a/NewHorizons/Builder/Props/GeyserBuilder.cs +++ b/NewHorizons/Builder/Props/GeyserBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Props @@ -7,7 +7,7 @@ namespace NewHorizons.Builder.Props { public static void Make(GameObject planetGO, Sector sector, PropModule.GeyserInfo info) { - var original = GameObject.Find("TimberHearth_Body/Sector_TH/Interactables_TH/Geysers/Geyser_Village"); + var original = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Interactables_TH/Geysers/Geyser_Village"); GameObject geyserGO = original.InstantiateInactive(); geyserGO.transform.parent = sector?.transform ?? planetGO.transform; geyserGO.name = "Geyser"; diff --git a/NewHorizons/Builder/Props/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiTextBuilder.cs index b2cc2c44..d304a9b8 100644 --- a/NewHorizons/Builder/Props/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiTextBuilder.cs @@ -51,18 +51,18 @@ namespace NewHorizons.Builder.Props _ghostArcPrefabs.Add(arc); } - _scrollPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/Prefab_NOM_Scroll").InstantiateInactive(); + _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"; - _computerPrefab = GameObject.Find("VolcanicMoon_Body/Sector_VM/Interactables_VM/Prefab_NOM_Computer").InstantiateInactive(); + _computerPrefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Interactables_VM/Prefab_NOM_Computer").InstantiateInactive(); _computerPrefab.name = "Prefab_NOM_Computer"; _computerPrefab.transform.rotation = Quaternion.identity; - _cairnPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_Crossroads/Interactables_Crossroads/Trailmarkers/Prefab_NOM_BH_Cairn_Arc (1)").InstantiateInactive(); + _cairnPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_Crossroads/Interactables_Crossroads/Trailmarkers/Prefab_NOM_BH_Cairn_Arc (1)").InstantiateInactive(); _cairnPrefab.name = "Prefab_NOM_Cairn"; _cairnPrefab.transform.rotation = Quaternion.identity; - _recorderPrefab = GameObject.Find("Comet_Body/Prefab_NOM_Shuttle/Sector_NomaiShuttleInterior/Interactibles_NomaiShuttleInterior/Prefab_NOM_Recorder").InstantiateInactive(); + _recorderPrefab = SearchUtilities.Find("Comet_Body/Prefab_NOM_Shuttle/Sector_NomaiShuttleInterior/Interactibles_NomaiShuttleInterior/Prefab_NOM_Recorder").InstantiateInactive(); _recorderPrefab.name = "Prefab_NOM_Recorder"; _recorderPrefab.transform.rotation = Quaternion.identity; } diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index da0ab34f..d6bc9b7a 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -41,7 +41,7 @@ namespace NewHorizons.Builder.Props { if (_slideReelPrefab == null) { - _slideReelPrefab = GameObject.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(); + _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?"); @@ -139,7 +139,7 @@ namespace NewHorizons.Builder.Props { if (_autoPrefab == null) { - _autoPrefab = GameObject.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone4/Sector_BlightedShore/Sector_JammingControlRoom_Zone4/Interactables_JammingControlRoom_Zone4/AutoProjector_SignalJammer/Prefab_IP_AutoProjector_SignalJammer")?.gameObject?.InstantiateInactive(); + _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?"); @@ -261,7 +261,7 @@ namespace NewHorizons.Builder.Props // var mindSlideProjector = standingTorch.GetComponent(); - mindSlideProjector._mindProjectorImageEffect = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); + mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); // setup for visually supporting async texture loading mindSlideProjector.enabled = false; diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index f3293eaa..89307795 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Props GameObject prefab; if (propInfo.assetBundle != null) prefab = AssetBundleUtilities.LoadPrefab(propInfo.assetBundle, propInfo.path, mod); - else prefab = GameObject.Find(propInfo.path); + else prefab = SearchUtilities.Find(propInfo.path); for (int i = 0; i < propInfo.count; i++) { var randomInd = (int)Random.Range(0, points.Count - 1); diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs index 7f38857e..097ea6cb 100644 --- a/NewHorizons/Builder/Props/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -192,7 +192,7 @@ namespace NewHorizons.Builder.Props source.rolloffMode = AudioRolloffMode.Custom; if (_customCurve == null) - _customCurve = GameObject.Find("Moon_Body/Sector_THM/Characters_THM/Villager_HEA_Esker/Signal_Whistling").GetComponent().GetCustomCurve(AudioSourceCurveType.CustomRolloff); + _customCurve = SearchUtilities.Find("Moon_Body/Sector_THM/Characters_THM/Villager_HEA_Esker/Signal_Whistling").GetComponent().GetCustomCurve(AudioSourceCurveType.CustomRolloff); source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, _customCurve); // If it can be heard regularly then we play it immediately diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 730790b5..34c21494 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -26,17 +26,17 @@ namespace NewHorizons.Builder.Props { if (_upPrefab == null) { - _upPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado").InstantiateInactive(); + _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 = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive(); + _downPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive(); _downPrefab.name = "Tornado_Down_Prefab"; } if (_hurricanePrefab == null) { - _hurricanePrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane/").InstantiateInactive(); + _hurricanePrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane/").InstantiateInactive(); // 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,7 +50,7 @@ namespace NewHorizons.Builder.Props } if (_soundPrefab == null) { - _soundPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive(); + _soundPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive(); _soundPrefab.name = "AudioRail_Prefab"; } if (_mainTexture == null) diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs index a9e04b51..48f5fa99 100644 --- a/NewHorizons/Builder/Props/VolcanoBuilder.cs +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Props @@ -12,7 +12,7 @@ namespace NewHorizons.Builder.Props public static void Make(GameObject planetGO, Sector sector, PropModule.VolcanoInfo info) { - var prefab = GameObject.Find("VolcanicMoon_Body/Sector_VM/Effects_VM/VolcanoPivot (2)/MeteorLauncher"); + var prefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Effects_VM/VolcanoPivot (2)/MeteorLauncher"); var launcherGO = prefab.InstantiateInactive(); launcherGO.transform.parent = sector.transform; diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 8b007aa3..dcca9126 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -16,7 +16,7 @@ namespace NewHorizons.Builder.ShipLog #region General public static ShipLogAstroObject[][] ConstructMapMode(string systemName, GameObject transformParent, ShipLogAstroObject[][] currentNav, int layer) { - Material greyScaleMaterial = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/Sprite").GetComponent().material; + Material greyScaleMaterial = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/Sprite").GetComponent().material; List bodies = Main.BodyDict[systemName].Where( b => !(b.Config.ShipLog?.mapMode?.remove ?? false) && !b.Config.isQuantumState ).ToList(); @@ -251,12 +251,12 @@ namespace NewHorizons.Builder.ShipLog navMatrix[navIndex[0]][navIndex[1]] = null; if (astroObject.GetID() == "CAVE_TWIN" || astroObject.GetID() == "TOWER_TWIN") { - GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); + SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); } } else if (name == "SandFunnel") { - GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); + SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); } gameObject.SetActive(false); } diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLogStarChartMode.cs index 251ce350..78cd5200 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLogStarChartMode.cs @@ -1,4 +1,4 @@ -using NewHorizons.Handlers; +using NewHorizons.Handlers; using NewHorizons.Utility; using System; using System.Collections.Generic; @@ -136,7 +136,7 @@ namespace NewHorizons.Components { if (_cardTemplate == null) { - var panRoot = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot"); + var panRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot"); _cardTemplate = GameObject.Instantiate(panRoot.GetComponentInChildren().gameObject); _cardTemplate.SetActive(false); } diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index 470dc432..9f4a8cc3 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -1,4 +1,5 @@ -using NewHorizons.Builder.General; +using NewHorizons.Builder.General; +using NewHorizons.Utility; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Components @@ -26,8 +27,8 @@ namespace NewHorizons.Components public void Init() { - _blackHolePrefab = GameObject.Find(_blackHolePath); - _whiteHolePrefab = GameObject.Find(_whiteHolePath); + _blackHolePrefab = SearchUtilities.Find(_blackHolePath); + _whiteHolePrefab = SearchUtilities.Find(_whiteHolePath); } public void Start() @@ -183,7 +184,7 @@ namespace NewHorizons.Components // For some reason warping into the ship makes you suffocate while in the ship if (_wearingSuit) resources.OnSuitUp(); var o2Volume = Locator.GetShipBody().GetComponent(); - var atmoVolume = GameObject.Find("Ship_Body/Volumes/ShipAtmosphereVolume").GetComponent(); + var atmoVolume = SearchUtilities.Find("Ship_Body/Volumes/ShipAtmosphereVolume").GetComponent(); resources._cameraFluidDetector.AddVolume(atmoVolume); resources._cameraFluidDetector.OnVolumeAdded(atmoVolume); diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index b79e5116..1470b5f6 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -33,13 +33,13 @@ namespace NewHorizons.Handlers // Set up stars // Need to manage this when there are multiple stars - var sun = GameObject.Find("Sun_Body"); + var sun = SearchUtilities.Find("Sun_Body"); var starController = sun.AddComponent(); - starController.Light = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); - starController.AmbientLight = GameObject.Find("Sun_Body/AmbientLight_SUN").GetComponent(); - starController.FaceActiveCamera = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); - starController.CSMTextureCacher = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); - starController.ProxyShadowLight = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.Light = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.AmbientLight = SearchUtilities.Find("Sun_Body/AmbientLight_SUN").GetComponent(); + starController.FaceActiveCamera = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.CSMTextureCacher = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.ProxyShadowLight = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); starController.Intensity = 0.9859f; starController.SunColor = new Color(1f, 0.8845f, 0.6677f, 1f); @@ -137,7 +137,7 @@ namespace NewHorizons.Handlers catch (Exception) { if (body?.Config?.name == null) Logger.LogError($"How is there no name for {body}"); - else existingPlanet = GameObject.Find(body.Config.name.Replace(" ", "") + "_Body"); + else existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false); } if (existingPlanet != null) @@ -252,7 +252,7 @@ namespace NewHorizons.Handlers { foreach (var child in body.Config.removeChildren) { - Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.Find(go.name + "/" + child)?.SetActive(false), 2); + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => SearchUtilities.Find(go.name + "/" + child)?.SetActive(false), 2); } } diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 6dead21b..82c0454a 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.Utility; using OWML.Utils; using System; @@ -33,7 +33,7 @@ namespace NewHorizons.Handlers public static void RemoveSolarSystem() { // Stop the sun from killing the player - var sunVolumes = GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN"); + var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); sunVolumes.SetActive(false); foreach (var name in _solarSystemBodies) @@ -82,11 +82,11 @@ namespace NewHorizons.Handlers break; case AstroObject.Name.CaveTwin: case AstroObject.Name.TowerTwin: - DisableBody(GameObject.Find("FocalBody"), delete); - DisableBody(GameObject.Find("SandFunnel_Body"), delete); + DisableBody(SearchUtilities.Find("FocalBody"), delete); + DisableBody(SearchUtilities.Find("SandFunnel_Body"), delete); break; case AstroObject.Name.MapSatellite: - DisableBody(GameObject.Find("MapSatellite_Body"), delete); + DisableBody(SearchUtilities.Find("MapSatellite_Body"), delete); break; case AstroObject.Name.GiantsDeep: // Might prevent leftover jellyfish from existing @@ -100,7 +100,7 @@ namespace NewHorizons.Handlers break; case AstroObject.Name.TimberHearth: // Always just fucking kill this one to stop THE WARP BUG!!! - DisableBody(GameObject.Find("StreamingGroup_TH"), true); + DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true); foreach (var obj in GameObject.FindObjectsOfType()) { @@ -229,8 +229,8 @@ namespace NewHorizons.Handlers { if (name.Equals("TowerTwin")) name = "AshTwin"; if (name.Equals("CaveTwin")) name = "EmberTwin"; - var distantProxy = GameObject.Find(name + "_DistantProxy"); - var distantProxyClone = GameObject.Find(name + "_DistantProxy(Clone)"); + var distantProxy = SearchUtilities.Find(name + "_DistantProxy", false); + var distantProxyClone = SearchUtilities.Find(name + "_DistantProxy(Clone)", false); if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject); if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject); diff --git a/NewHorizons/Handlers/ShipLogHandler.cs b/NewHorizons/Handlers/ShipLogHandler.cs index 2ef80633..0d5faaf5 100644 --- a/NewHorizons/Handlers/ShipLogHandler.cs +++ b/NewHorizons/Handlers/ShipLogHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Utility; +using NewHorizons.Utility; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -26,7 +26,7 @@ namespace NewHorizons.Handlers _entryIDsToNHBody = new Dictionary(); _nhBodyToAstroIDs = new Dictionary(); - List gameObjects = SearchUtilities.GetAllChildren(GameObject.Find(PAN_ROOT_PATH)); + List gameObjects = SearchUtilities.GetAllChildren(SearchUtilities.Find(PAN_ROOT_PATH)); _vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray(); _vanillaBodyIDs = gameObjects.ConvertAll(g => g.GetComponent()?.GetID()).ToArray(); } diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index e22406d3..4b1844e6 100644 --- a/NewHorizons/Handlers/StarChartHandler.cs +++ b/NewHorizons/Handlers/StarChartHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; @@ -18,7 +18,7 @@ namespace NewHorizons.Handlers { _systems = systems; - var shipLogRoot = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas"); + var shipLogRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas"); var starChartLog = new GameObject("StarChartMode"); starChartLog.SetActive(false); @@ -29,7 +29,7 @@ namespace NewHorizons.Handlers ShipLogStarChartMode = starChartLog.AddComponent(); - var reticleImage = GameObject.Instantiate(GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform); + var reticleImage = GameObject.Instantiate(SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform); var scaleRoot = new GameObject("ScaleRoot"); scaleRoot.transform.parent = starChartLog.transform; @@ -45,7 +45,7 @@ namespace NewHorizons.Handlers var centerPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_Center")?.GetComponent(); var upperRightPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_UpperRight")?.GetComponent(); - var oneShotSource = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent(); + var oneShotSource = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent(); _starSystemToFactID = new Dictionary(); _factIDToStarSystem = new Dictionary(); diff --git a/NewHorizons/Handlers/SystemCreationHandler.cs b/NewHorizons/Handlers/SystemCreationHandler.cs index fa020c5d..473cb372 100644 --- a/NewHorizons/Handlers/SystemCreationHandler.cs +++ b/NewHorizons/Handlers/SystemCreationHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.StarSystem; +using NewHorizons.Builder.StarSystem; using NewHorizons.Components; using NewHorizons.Utility; using UnityEngine; @@ -9,7 +9,7 @@ namespace NewHorizons.Handlers { public static void LoadSystem(NewHorizonsSystem system) { - var skybox = GameObject.Find("Skybox/Starfield"); + var skybox = SearchUtilities.Find("Skybox/Starfield"); if (system.Config.skybox?.destroyStarField ?? false) { diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index 6baf33ea..ebbb4043 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -13,7 +13,7 @@ namespace NewHorizons.Handlers { public static void InitSubtitles() { - GameObject subtitleContainer = GameObject.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye"); + GameObject subtitleContainer = SearchUtilities.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye"); if (subtitleContainer == null) { @@ -60,11 +60,11 @@ namespace NewHorizons.Handlers body3.transform.localRotation = Quaternion.Euler(10f, 0f, 0f); } - GameObject.Find("Scene/Background/PlanetPivot/Prefab_HEA_Campfire").SetActive(false); - GameObject.Find("Scene/Background/PlanetPivot/PlanetRoot").SetActive(false); + SearchUtilities.Find("Scene/Background/PlanetPivot/Prefab_HEA_Campfire").SetActive(false); + SearchUtilities.Find("Scene/Background/PlanetPivot/PlanetRoot").SetActive(false); var lightGO = new GameObject("Light"); - lightGO.transform.parent = GameObject.Find("Scene/Background").transform; + lightGO.transform.parent = SearchUtilities.Find("Scene/Background").transform; lightGO.transform.localPosition = new Vector3(-47.9203f, 145.7596f, 43.1802f); var light = lightGO.AddComponent(); light.color = new Color(1f, 1f, 1f, 1f); @@ -98,7 +98,7 @@ namespace NewHorizons.Handlers HeightMapBuilder.Make(titleScreenGO, null, heightMap, body.Mod); - GameObject pivot = GameObject.Instantiate(GameObject.Find("Scene/Background/PlanetPivot"), GameObject.Find("Scene/Background").transform); + GameObject pivot = GameObject.Instantiate(SearchUtilities.Find("Scene/Background/PlanetPivot"), SearchUtilities.Find("Scene/Background").transform); pivot.GetComponent()._degreesPerSecond = 10f; foreach (Transform child in pivot.transform) { diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 0a965afc..d4bcc7fc 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -189,7 +189,7 @@ namespace NewHorizons } launchController.enabled = false; } - var nomaiProbe = GameObject.Find("NomaiProbe_Body"); + var nomaiProbe = SearchUtilities.Find("NomaiProbe_Body"); if (nomaiProbe != null) nomaiProbe.gameObject.SetActive(false); } @@ -220,7 +220,7 @@ namespace NewHorizons if (_ship != null) { - _ship = GameObject.Find("Ship_Body").InstantiateInactive(); + _ship = SearchUtilities.Find("Ship_Body").InstantiateInactive(); DontDestroyOnLoad(_ship); } @@ -237,7 +237,7 @@ namespace NewHorizons // Warp drive StarChartHandler.Init(SystemDict.Values.ToArray()); HasWarpDrive = StarChartHandler.CanWarp(); - _shipWarpController = GameObject.Find("Ship_Body").AddComponent(); + _shipWarpController = SearchUtilities.Find("Ship_Body").AddComponent(); _shipWarpController.Init(); if (HasWarpDrive == true) EnableWarpDrive(); @@ -250,7 +250,7 @@ namespace NewHorizons if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; // Fix the map satellite - GameObject.Find("HearthianMapSatellite_Body").AddComponent(); + SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent(); } else { diff --git a/NewHorizons/Patches/ShipLogPatches.cs b/NewHorizons/Patches/ShipLogPatches.cs index acc1c021..672660c8 100644 --- a/NewHorizons/Patches/ShipLogPatches.cs +++ b/NewHorizons/Patches/ShipLogPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using NewHorizons.Builder.ShipLog; using NewHorizons.Components; using NewHorizons.Handlers; @@ -135,8 +135,8 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(ShipLogMapMode), nameof(ShipLogMapMode.Initialize))] public static void ShipLogMapMode_Initialize(ShipLogMapMode __instance) { - GameObject panRoot = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH); - GameObject sunObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); + GameObject panRoot = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH); + GameObject sunObject = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); ShipLogAstroObject[][] navMatrix = MapModeBuilder.ConstructMapMode(Main.Instance.CurrentStarSystem, panRoot, __instance._astroObjects, sunObject.layer); if (navMatrix == null || navMatrix.Length <= 1) { @@ -151,9 +151,9 @@ namespace NewHorizons.Patches List delete = SearchUtilities.GetAllChildren(panRoot).Where(g => g.name.Contains("_ShipLog") == false).ToList(); foreach (GameObject gameObject in delete) { - Object.Destroy(GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name)); + Object.Destroy(SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name)); } - if (GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel") == null) + if (SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel") == null) { __instance._sandFunnel = __instance.gameObject.AddComponent(); } diff --git a/NewHorizons/Patches/WarpDrivePatches.cs b/NewHorizons/Patches/WarpDrivePatches.cs index ff5aec3a..3995e002 100644 --- a/NewHorizons/Patches/WarpDrivePatches.cs +++ b/NewHorizons/Patches/WarpDrivePatches.cs @@ -1,5 +1,6 @@ -using HarmonyLib; +using HarmonyLib; using NewHorizons.Handlers; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Patches { @@ -14,7 +15,7 @@ namespace NewHorizons.Patches var newPrompt = TranslationHandler.GetTranslation("INTERSTELLAR_MODE", TranslationHandler.TextType.UI); __instance._detectiveModePrompt.SetText(newPrompt); - var text = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); + var text = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); text.text = newPrompt; } diff --git a/NewHorizons/Utility/AstroObjectLocator.cs b/NewHorizons/Utility/AstroObjectLocator.cs index 428e0f4b..40cb3ddc 100644 --- a/NewHorizons/Utility/AstroObjectLocator.cs +++ b/NewHorizons/Utility/AstroObjectLocator.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using UnityEngine; namespace NewHorizons.Utility @@ -97,35 +97,35 @@ namespace NewHorizons.Utility switch (primary._name) { case AstroObject.Name.TowerTwin: - otherChildren.Add(GameObject.Find("TimeLoopRing_Body")); + otherChildren.Add(SearchUtilities.Find("TimeLoopRing_Body")); break; case AstroObject.Name.ProbeCannon: - otherChildren.Add(GameObject.Find("NomaiProbe_Body")); - otherChildren.Add(GameObject.Find("CannonMuzzle_Body")); - otherChildren.Add(GameObject.Find("FakeCannonMuzzle_Body (1)")); - otherChildren.Add(GameObject.Find("CannonBarrel_Body")); - otherChildren.Add(GameObject.Find("FakeCannonBarrel_Body (1)")); - otherChildren.Add(GameObject.Find("Debris_Body (1)")); + otherChildren.Add(SearchUtilities.Find("NomaiProbe_Body")); + otherChildren.Add(SearchUtilities.Find("CannonMuzzle_Body")); + otherChildren.Add(SearchUtilities.Find("FakeCannonMuzzle_Body (1)")); + otherChildren.Add(SearchUtilities.Find("CannonBarrel_Body")); + otherChildren.Add(SearchUtilities.Find("FakeCannonBarrel_Body (1)")); + otherChildren.Add(SearchUtilities.Find("Debris_Body (1)")); break; case AstroObject.Name.GiantsDeep: - otherChildren.Add(GameObject.Find("BrambleIsland_Body")); - otherChildren.Add(GameObject.Find("GabbroIsland_Body")); - otherChildren.Add(GameObject.Find("QuantumIsland_Body")); - otherChildren.Add(GameObject.Find("StatueIsland_Body")); - otherChildren.Add(GameObject.Find("ConstructionYardIsland_Body")); - otherChildren.Add(GameObject.Find("GabbroShip_Body")); + otherChildren.Add(SearchUtilities.Find("BrambleIsland_Body")); + otherChildren.Add(SearchUtilities.Find("GabbroIsland_Body")); + otherChildren.Add(SearchUtilities.Find("QuantumIsland_Body")); + otherChildren.Add(SearchUtilities.Find("StatueIsland_Body")); + otherChildren.Add(SearchUtilities.Find("ConstructionYardIsland_Body")); + otherChildren.Add(SearchUtilities.Find("GabbroShip_Body")); break; case AstroObject.Name.WhiteHole: - otherChildren.Add(GameObject.Find("WhiteholeStation_Body")); - otherChildren.Add(GameObject.Find("WhiteholeStationSuperstructure_Body")); + otherChildren.Add(SearchUtilities.Find("WhiteholeStation_Body")); + otherChildren.Add(SearchUtilities.Find("WhiteholeStationSuperstructure_Body")); break; case AstroObject.Name.TimberHearth: - otherChildren.Add(GameObject.Find("MiningRig_Body")); - otherChildren.Add(GameObject.Find("Ship_Body")); + otherChildren.Add(SearchUtilities.Find("MiningRig_Body")); + otherChildren.Add(SearchUtilities.Find("Ship_Body")); break; case AstroObject.Name.DreamWorld: - otherChildren.Add(GameObject.Find("BackRaft_Body")); - otherChildren.Add(GameObject.Find("SealRaft_Body")); + otherChildren.Add(SearchUtilities.Find("BackRaft_Body")); + otherChildren.Add(SearchUtilities.Find("SealRaft_Body")); break; // For some dumb reason the sun station doesn't use AstroObject.Name.SunStation case AstroObject.Name.CustomString: diff --git a/NewHorizons/Utility/DebugUtilities/DebugReload.cs b/NewHorizons/Utility/DebugUtilities/DebugReload.cs index 8e763eab..ac48c7ad 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugReload.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugReload.cs @@ -1,4 +1,4 @@ -using NewHorizons.Handlers; +using NewHorizons.Handlers; using OWML.Common; using OWML.Common.Menus; using System; @@ -45,7 +45,7 @@ namespace NewHorizons.Utility.DebugUtilities Logger.LogWarning("Error While Reloading"); } - GameObject.Find("/PauseMenu/PauseMenuManagers").GetComponent().OnSkipToNextTimeLoop(); + SearchUtilities.Find("/PauseMenu/PauseMenuManagers").GetComponent().OnSkipToNextTimeLoop(); Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem); diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs index 46a5ca16..af140b5d 100644 --- a/NewHorizons/Utility/SearchUtilities.cs +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -129,7 +129,7 @@ namespace NewHorizons.Utility return null; } - public static GameObject Find(string path) + public static GameObject Find(string path, bool warn = true) { if (CachedGameObjects.ContainsKey(path)) { @@ -150,7 +150,7 @@ namespace NewHorizons.Utility var t = root?.transform; if (t == null) { - Logger.LogWarning($"Couldn't find root object in path ({names[0]})"); + if (warn) Logger.LogWarning($"Couldn't find root object in path ({names[0]})"); } else { @@ -172,7 +172,7 @@ namespace NewHorizons.Utility if (child == null) { - Logger.LogWarning($"Couldn't find object in path ({names[i]})"); + if (warn) Logger.LogWarning($"Couldn't find object in path ({names[i]})"); t = null; break; } @@ -187,7 +187,7 @@ namespace NewHorizons.Utility if (go == null) { var name = names.Last(); - Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}"); + if (warn) Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}"); go = FindObjectOfTypeAndName(name); } From 63cf1355503bf4742f56dec6b11fcf7f72bbea13 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 03:33:28 -0400 Subject: [PATCH 19/72] Try Catch --- NewHorizons/Main.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index d4bcc7fc..f4c9ad09 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -158,7 +158,14 @@ namespace NewHorizons private static void OnWakeUp() { IsSystemReady = true; - Instance.OnStarSystemLoaded?.Invoke(Instance.CurrentStarSystem); + try + { + Instance.OnStarSystemLoaded?.Invoke(Instance.CurrentStarSystem); + } + catch (Exception e) + { + Logger.LogError($"Exception thrown when invoking star system loaded event with parameter [{Instance.CurrentStarSystem}] : {e.GetType().FullName} {e.Message} {e.StackTrace}"); + } } private void OnSceneUnloaded(Scene scene) From 937e389719e0d71d6962e45c3fc82452ec437c76 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 03:33:57 -0400 Subject: [PATCH 20/72] Star Light Radius --- NewHorizons/Builder/Body/StarBuilder.cs | 1 + NewHorizons/External/Modules/VariableSize/StarModule.cs | 8 +++++++- NewHorizons/Schemas/body_schema.json | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index aa0cc253..a2c81ed1 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -87,6 +87,7 @@ namespace NewHorizons.Builder.Body var light = sunLight.AddComponent(); light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.solarLuminosity; + light.range = starModule.lightRadius; light.range *= Mathf.Sqrt(starModule.solarLuminosity); Color lightColour = light.color; diff --git a/NewHorizons/External/Modules/VariableSize/StarModule.cs b/NewHorizons/External/Modules/VariableSize/StarModule.cs index d722be68..201571e3 100644 --- a/NewHorizons/External/Modules/VariableSize/StarModule.cs +++ b/NewHorizons/External/Modules/VariableSize/StarModule.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using NewHorizons.Utility; using Newtonsoft.Json; @@ -55,5 +55,11 @@ namespace NewHorizons.External.Modules.VariableSize /// Colour of the star. /// public MColor tint; + + /// + /// How far the light from the star can reach. + /// + [DefaultValue(50000f)] [Range(0f, double.MaxValue)] + public float lightRadius = 50000f; } } diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index cc33cc0e..662f19a4 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1772,6 +1772,13 @@ "tint": { "description": "Colour of the star.", "$ref": "#/definitions/MColor" + }, + "lightRadius": { + "type": "number", + "description": "How far the light from the star can reach.", + "format": "float", + "default": 50000.0, + "minimum": 0.0 } } }, From 3634a58bdf7630761e18ecbcde30db032dbe791b Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 22:12:12 -0400 Subject: [PATCH 21/72] rename --- NewHorizons/Builder/Props/DetailBuilder.cs | 4 ++-- NewHorizons/External/Modules/PropModule.cs | 2 +- NewHorizons/Schemas/body_schema.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 61287cb4..c070b6a4 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -62,9 +62,9 @@ namespace NewHorizons.Builder.Props detailGO = newDetailGO; } - if (detail.comment != null) + if (detail.rename != null) { - detailGO.name = detail.comment; + detailGO.name = detail.rename; } detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO; diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index c1650079..c378c7af 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -116,7 +116,7 @@ namespace NewHorizons.External.Modules /// /// An optional rename of the detail /// - public string comment; + public string rename; /// /// Do we override rotation and try to automatically align this object to stand upright on the body's surface? diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 662f19a4..f5943fe5 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -813,7 +813,7 @@ "type": "object", "additionalProperties": false, "properties": { - "comment": { + "rename": { "type": "string", "description": "An optional rename of the detail" }, From 853fd3111a0cc6b3edd2cb0563b6f5da6af93d63 Mon Sep 17 00:00:00 2001 From: Ben C Date: Tue, 31 May 2022 10:16:13 -0400 Subject: [PATCH 22/72] Fixed IgnoreMoreToExploreCondition in docs --- NewHorizons/Schemas/shiplog_schema.xsd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Schemas/shiplog_schema.xsd b/NewHorizons/Schemas/shiplog_schema.xsd index 4655788f..71f503ef 100644 --- a/NewHorizons/Schemas/shiplog_schema.xsd +++ b/NewHorizons/Schemas/shiplog_schema.xsd @@ -67,7 +67,7 @@ - Ignore more to explore if a fact is known + Ignore more to explore if a persistent condition is `true` @@ -202,4 +202,4 @@ - \ No newline at end of file + From f66829e240e8c3f527619c93e35edfa500603596 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 1 Jun 2022 06:37:24 -0400 Subject: [PATCH 23/72] Customizable Travel Audio (#31) --- .../External/Configs/StarSystemConfig.cs | 10 ++++++++ NewHorizons/Handlers/SystemCreationHandler.cs | 24 +++++++++++++++++++ NewHorizons/Schemas/star_system_schema.json | 8 +++++++ 3 files changed, 42 insertions(+) diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index a939a456..86cc9c2b 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -51,6 +51,16 @@ namespace NewHorizons.External.Configs /// public bool startHere; + /// + /// Name of an existing AudioClip in the game that will play when travelling in space. + /// + public string travelAudioClip; + + /// + /// Relative filepath to the .wav file to use as the audio. Mutually exclusive with travelAudioClip. + /// + public string travelAudioFilePath; + public class NomaiCoordinates { public int[] x; diff --git a/NewHorizons/Handlers/SystemCreationHandler.cs b/NewHorizons/Handlers/SystemCreationHandler.cs index 473cb372..f4c0ca99 100644 --- a/NewHorizons/Handlers/SystemCreationHandler.cs +++ b/NewHorizons/Handlers/SystemCreationHandler.cs @@ -26,6 +26,30 @@ namespace NewHorizons.Handlers var timeLoopController = new GameObject("TimeLoopController"); timeLoopController.AddComponent(); } + + AudioClip clip = null; + if (system.Config.travelAudioClip != null) clip = SearchUtilities.FindResourceOfTypeAndName(system.Config.travelAudioClip); + else if (system.Config.travelAudioFilePath != null) + { + try + { + clip = AudioUtilities.LoadAudio(system.Mod.ModHelper.Manifest.ModFolderPath + "/" + system.Config.travelAudioFilePath); + } + catch (System.Exception e) + { + Utility.Logger.LogError($"Couldn't load audio file {system.Config.travelAudioFilePath} : {e.Message}"); + } + } + + if (clip != null) + { + var travelSource = Locator.GetGlobalMusicController()._travelSource; + travelSource._audioLibraryClip = AudioType.None; + travelSource._clipArrayIndex = 0; + travelSource._clipArrayLength = 0; + travelSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL; + travelSource.clip = clip; + } } } } diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index 13ae6ecc..1a4076a5 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -38,6 +38,14 @@ "type": "boolean", "description": "Set to `true` if you want to spawn here after dying, not Timber Hearth. You can still warp back to the main star\nsystem." }, + "travelAudioClip": { + "type": "string", + "description": "Name of an existing AudioClip in the game that will play when travelling in space." + }, + "travelAudioFilePath": { + "type": "string", + "description": "Relative filepath to the .wav file to use as the audio. Mutually exclusive with travelAudioClip." + }, "$schema": { "type": "string", "description": "The schema to validate with" From daa4fff4c1b3a813872110e1fd3474e63c92dd3d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 01:27:23 -0400 Subject: [PATCH 24/72] Target When Close For Ship --- NewHorizons/Builder/General/RFVolumeBuilder.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index 83e76cb5..e34b29a0 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -19,8 +19,10 @@ namespace NewHorizons.Builder.General var RFV = rfGO.AddComponent(); + var minTargetDistance = module.targetWhenClose ? 0 : sphereOfInfluence; + var RV = new ReferenceFrame(owrb); - RV._minSuitTargetDistance = module.targetWhenClose ? 0 : sphereOfInfluence; + RV._minSuitTargetDistance = minTargetDistance; RV._maxTargetDistance = 0; RV._autopilotArrivalDistance = 2.0f * sphereOfInfluence; RV._autoAlignmentDistance = sphereOfInfluence * 1.5f; @@ -32,7 +34,7 @@ namespace NewHorizons.Builder.General RV._bracketsRadius = module.bracketRadius > -1 ? module.bracketRadius : sphereOfInfluence; RFV._referenceFrame = RV; - RFV._minColliderRadius = sphereOfInfluence; + RFV._minColliderRadius = minTargetDistance; RFV._maxColliderRadius = sphereOfInfluence * 2f; RFV._isPrimaryVolume = true; RFV._isCloseRangeVolume = false; From c6529098bdaaaeda678968790513da055c0450af Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 01:44:56 -0400 Subject: [PATCH 25/72] Max Target Distance --- NewHorizons/Builder/General/RFVolumeBuilder.cs | 2 +- NewHorizons/External/Modules/ReferenceFrameModule.cs | 5 +++++ NewHorizons/Schemas/body_schema.json | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index e34b29a0..178234e4 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -35,7 +35,7 @@ namespace NewHorizons.Builder.General RFV._referenceFrame = RV; RFV._minColliderRadius = minTargetDistance; - RFV._maxColliderRadius = sphereOfInfluence * 2f; + RFV._maxColliderRadius = module.maxTargetDistance > -1 ? module.maxTargetDistance : sphereOfInfluence * 2f; RFV._isPrimaryVolume = true; RFV._isCloseRangeVolume = false; diff --git a/NewHorizons/External/Modules/ReferenceFrameModule.cs b/NewHorizons/External/Modules/ReferenceFrameModule.cs index e9dc02a4..793bb5f0 100644 --- a/NewHorizons/External/Modules/ReferenceFrameModule.cs +++ b/NewHorizons/External/Modules/ReferenceFrameModule.cs @@ -24,5 +24,10 @@ namespace NewHorizons.External.Modules /// If it should be targetable even when super close. /// public bool targetWhenClose; + + /// + /// The maximum distance that the reference frame can be targeted from. Defaults to double the sphereOfInfluence. + /// + [DefaultValue(-1)] public float maxTargetDistance = -1; } } \ No newline at end of file diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index f5943fe5..3dfefb56 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -476,6 +476,12 @@ "targetWhenClose": { "type": "boolean", "description": "If it should be targetable even when super close." + }, + "maxTargetDistance": { + "type": "number", + "description": "The maximum distance that the reference frame can be targeted from. Defaults to double the sphereOfInfluence.", + "format": "float", + "default": -1 } } }, From 1c72525246d40b182abd254fa43b355aa9b192be Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 01:45:54 -0400 Subject: [PATCH 26/72] Log --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index dcca9126..a3059dc8 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -99,6 +99,8 @@ namespace NewHorizons.Builder.ShipLog { const float unviewedIconOffset = 15; + Logger.Log($"Adding ship log astro object for {body.Config.name}"); + GameObject unviewedReference = SearchUtilities.CachedFind(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/UnviewedIcon"); ShipLogAstroObject astroObject = gameObject.AddComponent(); From d5a156644cb162c380324f1dcae7fb32682d7617 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 02:39:45 -0400 Subject: [PATCH 27/72] Stop setting centerOfMass for kinematic rigidbody Setting it does nothing except spam the log. --- NewHorizons/Builder/General/RigidBodyBuilder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/Builder/General/RigidBodyBuilder.cs b/NewHorizons/Builder/General/RigidBodyBuilder.cs index a827cc2e..d016f469 100644 --- a/NewHorizons/Builder/General/RigidBodyBuilder.cs +++ b/NewHorizons/Builder/General/RigidBodyBuilder.cs @@ -19,7 +19,6 @@ namespace NewHorizons.Builder.General rigidBody.collisionDetectionMode = CollisionDetectionMode.Discrete; KinematicRigidbody kinematicRigidBody = body.AddComponent(); - kinematicRigidBody.centerOfMass = Vector3.zero; OWRigidbody owRigidBody = body.AddComponent(); owRigidBody._kinematicSimulation = true; From 0164fbf23c280a211ec5bda6a003de812253f6aa Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 02:46:21 -0400 Subject: [PATCH 28/72] Map Mode Focal Point --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index a3059dc8..16ca369b 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -237,6 +237,12 @@ namespace NewHorizons.Builder.ShipLog { GameObject newMapModeGO = CreateMapModeGameObject(body, transformParent, layer, body.Config.ShipLog?.mapMode?.manualPosition); ShipLogAstroObject newAstroObject = AddShipLogAstroObject(newMapModeGO, body, greyScaleMaterial, layer); + if (body.Config.FocalPoint != null) + { + newAstroObject._imageObj.GetComponent().enabled = false; + newAstroObject._outlineObj.GetComponent().enabled = false; + newAstroObject._unviewedObj.GetComponent().enabled = false; + } MakeDetails(body, newMapModeGO.transform, greyScaleMaterial); Vector2 navigationPosition = body.Config.ShipLog?.mapMode?.manualNavigationPosition; navMatrix[(int)navigationPosition.y][(int)navigationPosition.x] = newAstroObject; @@ -483,7 +489,7 @@ namespace NewHorizons.Builder.ShipLog GameObject newNodeGO = CreateMapModeGameObject(node.mainBody, parent, layer, position); ShipLogAstroObject astroObject = AddShipLogAstroObject(newNodeGO, node.mainBody, greyScaleMaterial, layer); if (node.mainBody.Config.FocalPoint != null) - { + { astroObject._imageObj.GetComponent().enabled = false; astroObject._outlineObj.GetComponent().enabled = false; astroObject._unviewedObj.GetComponent().enabled = false; From 0e0766e87014cc23a7a075d01a6694cf2b8db197 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 15:19:19 -0400 Subject: [PATCH 29/72] Fix NullReferenceExceptions --- NewHorizons/Builder/Body/StarBuilder.cs | 4 +++- .../Builder/General/SpawnPointBuilder.cs | 7 ++++-- NewHorizons/Builder/Props/DetailBuilder.cs | 1 + .../StarEvolutionController.cs | 4 ++-- NewHorizons/Patches/MapControllerPatches.cs | 9 +++++++- NewHorizons/Patches/PlayerSpawnerPatches.cs | 2 +- NewHorizons/Patches/SunPatches.cs | 23 ++++++++++++++++++- 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index e51341ef..ba5d303a 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -133,11 +133,11 @@ namespace NewHorizons.Builder.Body // It fucking insists on this existing and its really annoying var supernovaVolume = new GameObject("SupernovaVolumePlaceholder"); supernovaVolume.transform.SetParent(starGO.transform); - supernova._supernovaVolume = supernovaVolume.AddComponent(); var sphere = supernovaVolume.AddComponent(); sphere.radius = 0f; sphere.isTrigger = true; supernovaVolume.AddComponent(); + supernova._supernovaVolume = supernovaVolume.AddComponent(); return starController; } @@ -148,6 +148,8 @@ namespace NewHorizons.Builder.Body var supernova = MakeSupernova(starGO, starModule); + supernova._belongsToProxySun = true; + starGO.SetActive(false); var controller = starGO.AddComponent(); if (starModule.curve != null) controller.scaleCurve = starModule.GetAnimationCurve(); diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index 05f6d7a4..f74767bd 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -18,8 +18,9 @@ namespace NewHorizons.Builder.General spawnGO.transform.localPosition = module.playerSpawnPoint; playerSpawn = spawnGO.AddComponent(); - - if(module.playerSpawnRotation != null) + playerSpawn._triggerVolumes = new OWTriggerVolume[0]; + + if (module.playerSpawnRotation != null) { spawnGO.transform.rotation = Quaternion.Euler(module.playerSpawnRotation); } @@ -40,6 +41,7 @@ namespace NewHorizons.Builder.General var spawnPoint = spawnGO.AddComponent(); spawnPoint._isShipSpawn = true; + spawnPoint._triggerVolumes = new OWTriggerVolume[0]; var ship = GameObject.Find("Ship_Body"); ship.transform.position = spawnPoint.transform.position; @@ -67,6 +69,7 @@ namespace NewHorizons.Builder.General playerSpawnGO.transform.localPosition = new Vector3(0, 0, 0); playerSpawn = playerSpawnGO.AddComponent(); + playerSpawn._triggerVolumes = new OWTriggerVolume[0]; playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0); } } diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index bfa69d09..54469e24 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -169,6 +169,7 @@ namespace NewHorizons.Builder.Props { try { + if (component == null) return; if (component is Animator animator) animator.enabled = true; else if (component is Collider collider) collider.enabled = true; else if (component is Renderer renderer) renderer.enabled = true; diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index c862f7fc..d27486fb 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -199,8 +199,8 @@ namespace NewHorizons.Components.SizeControllers supernova.enabled = true; _isSupernova = true; _supernovaStartTime = Time.time; - atmosphere.SetActive(false); - _destructionVolume._deathType = DeathType.Supernova; + if (atmosphere != null) atmosphere.SetActive(false); + if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova; return; } } diff --git a/NewHorizons/Patches/MapControllerPatches.cs b/NewHorizons/Patches/MapControllerPatches.cs index b3c25e29..903868fb 100644 --- a/NewHorizons/Patches/MapControllerPatches.cs +++ b/NewHorizons/Patches/MapControllerPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using UnityEngine.SceneManagement; namespace NewHorizons.Patches @@ -43,5 +43,12 @@ namespace NewHorizons.Patches return true; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ReferenceFrameTracker), nameof(ReferenceFrameTracker.UntargetReferenceFrame), new System.Type[] { typeof(bool) })] + public static bool ReferenceFrameTracker_UntargetReferenceFrame(ReferenceFrameTracker __instance, bool playAudio) + { + return __instance != null && __instance._hasTarget && __instance._currentReferenceFrame != null; + } } } diff --git a/NewHorizons/Patches/PlayerSpawnerPatches.cs b/NewHorizons/Patches/PlayerSpawnerPatches.cs index e6dec94d..09e9ff0a 100644 --- a/NewHorizons/Patches/PlayerSpawnerPatches.cs +++ b/NewHorizons/Patches/PlayerSpawnerPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Patches { diff --git a/NewHorizons/Patches/SunPatches.cs b/NewHorizons/Patches/SunPatches.cs index ba57ffee..447028bd 100644 --- a/NewHorizons/Patches/SunPatches.cs +++ b/NewHorizons/Patches/SunPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using UnityEngine; namespace NewHorizons.Patches { @@ -40,5 +40,26 @@ namespace NewHorizons.Patches __instance._audioSource.SetLocalVolume(num * num * __instance._fade); return false; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SunProxyEffectController), nameof(SunProxyEffectController.UpdateScales))] + public static bool SunProxyEffectController_UpdateScales(SunProxyEffectController __instance) + { + return __instance != null && __instance._surface != null && __instance._fog != null && __instance._fogMaterial != null && __instance._solarFlareEmitter != null && __instance._atmosphere != null; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SunProxyEffectController), nameof(SunProxyEffectController.UpdateAtmosphereRadii))] + public static bool SunProxyEffectController_UpdateAtmosphereRadii(SunProxyEffectController __instance) + { + return __instance != null && __instance.transform != null && __instance.transform.parent != null && __instance._atmosphereMaterial != null; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(VanishVolume), nameof(VanishVolume.Shrink))] + public static bool VanishVolume_Shrink(VanishVolume __instance, OWRigidbody bodyToShrink) + { + return __instance != null && __instance.transform != null && __instance._shrinkingBodies != null && __instance._shrinkingBodyLocationData != null && bodyToShrink != null; + } } } From 75ce7349cfb6ad96d2c3d4091d1e4f10ec909e82 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 19:20:19 -0400 Subject: [PATCH 30/72] Reference Frame Module --- .../Builder/Body/AsteroidBeltBuilder.cs | 8 ++++-- .../Builder/General/RFVolumeBuilder.cs | 9 +++--- .../Builder/Orbital/FocalPointBuilder.cs | 4 +-- NewHorizons/External/Configs/PlanetConfig.cs | 8 ++++++ NewHorizons/External/Modules/BaseModule.cs | 8 ++---- .../External/Modules/ReferenceFrameModule.cs | 28 +++++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 6 ++-- NewHorizons/Schemas/body_schema.json | 25 +++++++++++++---- 8 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 NewHorizons/External/Modules/ReferenceFrameModule.cs diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 64543600..5e71238f 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -34,7 +34,6 @@ namespace NewHorizons.Builder.Body hasMapMarker = false, surfaceGravity = 1, surfaceSize = size, - hasReferenceFrame = false, gravityFallOff = GravityFallOff.InverseSquared }; @@ -49,6 +48,11 @@ namespace NewHorizons.Builder.Body showOrbitLine = false }; + config.ReferenceFrame = new ReferenceFrameModule() + { + hideInMap = true + }; + config.ProcGen = belt.procGen; if (config.ProcGen == null) { diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index f6831bb7..83e76cb5 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -1,10 +1,11 @@ using NewHorizons.External.Configs; +using NewHorizons.External.Modules; using UnityEngine; namespace NewHorizons.Builder.General { public static class RFVolumeBuilder { - public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, bool hide = false) + public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, ReferenceFrameModule module) { var rfGO = new GameObject("RFVolume"); rfGO.transform.parent = planetGO.transform; @@ -19,7 +20,7 @@ namespace NewHorizons.Builder.General var RFV = rfGO.AddComponent(); var RV = new ReferenceFrame(owrb); - RV._minSuitTargetDistance = sphereOfInfluence; + RV._minSuitTargetDistance = module.targetWhenClose ? 0 : sphereOfInfluence; RV._maxTargetDistance = 0; RV._autopilotArrivalDistance = 2.0f * sphereOfInfluence; RV._autoAlignmentDistance = sphereOfInfluence * 1.5f; @@ -28,7 +29,7 @@ namespace NewHorizons.Builder.General RV._matchAngularVelocity = true; RV._minMatchAngularVelocityDistance = 70; RV._maxMatchAngularVelocityDistance = 400; - RV._bracketsRadius = sphereOfInfluence; + RV._bracketsRadius = module.bracketRadius > -1 ? module.bracketRadius : sphereOfInfluence; RFV._referenceFrame = RV; RFV._minColliderRadius = sphereOfInfluence; @@ -38,7 +39,7 @@ namespace NewHorizons.Builder.General owrb.SetAttachedReferenceFrameVolume(RFV); - rfGO.SetActive(!hide); + rfGO.SetActive(!module.hideInMap); } } } diff --git a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs index c217664e..98a51bd9 100644 --- a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs +++ b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components.Orbital; +using NewHorizons.Components.Orbital; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; @@ -59,7 +59,7 @@ namespace NewHorizons.Builder.Orbital fakeMassConfig.name = config.name + "_FakeBarycenterMass"; fakeMassConfig.Base.sphereOfInfluence = 0; fakeMassConfig.Base.hasMapMarker = false; - fakeMassConfig.Base.hasReferenceFrame = false; + fakeMassConfig.ReferenceFrame.hideInMap = true; fakeMassConfig.Orbit = new OrbitModule(); fakeMassConfig.Orbit.CopyPropertiesFrom(config.Orbit); diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index bd748a62..ee652297 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -101,6 +101,11 @@ namespace NewHorizons.External.Configs /// public PropModule Props; + /// + /// Reference frame properties of this body + /// + public ReferenceFrameModule ReferenceFrame; + /// /// A list of paths to child GameObjects to destroy on this planet /// @@ -162,6 +167,7 @@ namespace NewHorizons.External.Configs if (Base == null) Base = new BaseModule(); if (Orbit == null) Orbit = new OrbitModule(); if (ShipLog == null) ShipLog = new ShipLogModule(); + if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule(); } public void MigrateAndValidate() @@ -195,6 +201,8 @@ namespace NewHorizons.External.Configs if (Base.isSatellite) Base.showMinimap = false; + if (!Base.hasReferenceFrame) ReferenceFrame.hideInMap = true; + if (childrenToDestroy != null) removeChildren = childrenToDestroy; if (Base.cloakRadius != 0) diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index 20645d16..b0e81c1a 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -56,11 +56,6 @@ namespace NewHorizons.External.Modules /// public bool hasMapMarker; - /// - /// Allows the object to be targeted on the map. - /// - [DefaultValue(true)] public bool hasReferenceFrame = true; - /// /// Can this planet survive entering a star? /// @@ -106,6 +101,9 @@ namespace NewHorizons.External.Modules [Obsolete("HasAmbientLight is deprecated, please use AmbientLight instead")] public bool hasAmbientLight; + [Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")] + [DefaultValue(true)] public bool hasReferenceFrame = true; + [Obsolete("CloakRadius is deprecated, please use CloakModule instead")] public float cloakRadius; diff --git a/NewHorizons/External/Modules/ReferenceFrameModule.cs b/NewHorizons/External/Modules/ReferenceFrameModule.cs new file mode 100644 index 00000000..e9dc02a4 --- /dev/null +++ b/NewHorizons/External/Modules/ReferenceFrameModule.cs @@ -0,0 +1,28 @@ +using System; +using System.ComponentModel; +using System.Runtime.Serialization; +using NewHorizons.Utility; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace NewHorizons.External.Modules +{ + [JsonObject] + public class ReferenceFrameModule + { + /// + /// Stop the object from being targeted on the map. + /// + public bool hideInMap; + + /// + /// Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence. + /// + [DefaultValue(-1)] public float bracketRadius = -1; + + /// + /// If it should be targetable even when super close. + /// + public bool targetWhenClose; + } +} \ No newline at end of file diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 77ca0ebe..1cb8f3d2 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Atmosphere; +using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Body; using NewHorizons.Builder.General; using NewHorizons.Builder.Orbital; @@ -306,7 +306,7 @@ namespace NewHorizons.Handlers GravityBuilder.Make(go, ao, owRigidBody, body.Config); } - RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, !body.Config.Base.hasReferenceFrame); + RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, body.Config.ReferenceFrame); if (body.Config.Base.hasMapMarker) { @@ -482,7 +482,7 @@ namespace NewHorizons.Handlers // Has to go last probably if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f) { - CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame, body.Mod); + CloakBuilder.Make(go, sector, rb, body.Config.Cloak, !body.Config.ReferenceFrame.hideInMap, body.Mod); } return go; diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5f1f9bdd..3badb0eb 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -428,11 +428,6 @@ "type": "boolean", "description": "If the body should have a marker on the map screen." }, - "hasReferenceFrame": { - "type": "boolean", - "description": "Allows the object to be targeted on the map.", - "default": true - }, "invulnerableToSun": { "type": "boolean", "description": "Can this planet survive entering a star?" @@ -459,6 +454,26 @@ } } }, + "ReferenceFrameModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "hideInMap": { + "type": "boolean", + "description": "Stop the object from being targeted on the map." + }, + "bracketRadius": { + "type": "number", + "description": "Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence.", + "format": "float", + "default": -1 + }, + "targetWhenClose": { + "type": "boolean", + "description": "If it should be targetable even when super close." + } + } + }, "MVector3": { "type": "object", "additionalProperties": false, From fa414929e3c22b1891b3b9515644a745ed8a6592 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 19:33:28 -0400 Subject: [PATCH 31/72] Zero Gravity Volume --- .../Builder/Atmosphere/VolumesBuilder.cs | 30 +++++++++++++++++-- NewHorizons/External/Modules/BaseModule.cs | 5 ++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- NewHorizons/Schemas/body_schema.json | 5 ++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index f4e7e17c..12ccc732 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using UnityEngine; namespace NewHorizons.Builder.Atmosphere { @@ -6,7 +6,7 @@ namespace NewHorizons.Builder.Atmosphere { private static readonly int FogColor = Shader.PropertyToID("_FogColor"); - public static void Make(GameObject planetGO, PlanetConfig config, float sphereOfInfluence) + public static void Make(GameObject planetGO, OWRigidbody owrb, PlanetConfig config, float sphereOfInfluence) { var innerRadius = config.Base.surfaceSize; @@ -48,6 +48,32 @@ namespace NewHorizons.Builder.Atmosphere } ER._cloudMaterial = cloudMaterial; + if (config.Base.zeroGravityRadius != 0) + { + var zeroGObject = new GameObject("ZeroGVolume"); + zeroGObject.transform.parent = volumesGO.transform; + zeroGObject.transform.localPosition = Vector3.zero; + zeroGObject.transform.localScale = Vector3.one * config.Base.zeroGravityRadius; + zeroGObject.layer = LayerMask.NameToLayer("BasicEffectVolume"); + + var sphereCollider = zeroGObject.AddComponent(); + sphereCollider.radius = 1; + sphereCollider.isTrigger = true; + + var owCollider = zeroGObject.AddComponent(); + owCollider._parentBody = owrb; + owCollider._collider = sphereCollider; + + var triggerVolume = zeroGObject.AddComponent(); + triggerVolume._owCollider = owCollider; + + var zeroGVolume = zeroGObject.AddComponent(); + zeroGVolume._attachedBody = owrb; + zeroGVolume._triggerVolume = triggerVolume; + zeroGVolume._inheritable = true; + zeroGVolume._priority = 1; + } + volumesGO.transform.position = planetGO.transform.position; rulesetGO.SetActive(true); volumesGO.SetActive(true); diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index b0e81c1a..27858633 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -81,6 +81,11 @@ namespace NewHorizons.External.Modules /// public float surfaceSize; + /// + /// Radius of the zero gravity volume. This will make it so no gravity from any planet will affect you. Useful for satellites. + /// + public float zeroGravityRadius; + #region Obsolete [Obsolete("IsSatellite is deprecated, please use ShowMinimap instead")] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 1cb8f3d2..b79e5116 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -313,7 +313,7 @@ namespace NewHorizons.Handlers MarkerBuilder.Make(go, body.Config.name, body.Config); } - VolumesBuilder.Make(go, body.Config, sphereOfInfluence); + VolumesBuilder.Make(go, owRigidBody, body.Config, sphereOfInfluence); if (body.Config.FocalPoint != null) { diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 3badb0eb..cc33cc0e 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -451,6 +451,11 @@ "type": "number", "description": "A scale height used for a number of things. Should be the approximate radius of the body.", "format": "float" + }, + "zeroGravityRadius": { + "type": "number", + "description": "Radius of the zero gravity sphere. This sphere will make gravity no longer affect you while you are inside it. Useful for satellites.", + "format": "float" } } }, From f28e4030e2472cbaf3008b5c4de13b181311fafd Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 23:13:32 -0400 Subject: [PATCH 32/72] Set Proxy Shadow Caster Super Group --- NewHorizons/Builder/Body/HeightMapBuilder.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index cf9e359a..50d7c93a 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Body.Geometry; +using NewHorizons.Builder.Body.Geometry; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -57,7 +57,8 @@ namespace NewHorizons.Builder.Body var cubeSphereMC = cubeSphere.AddComponent(); cubeSphereMC.sharedMesh = mesh; - if (planetGO.GetComponent() != null) cubeSphere.AddComponent(); + var superGroup = planetGO.GetComponent(); + if (superGroup != null) cubeSphere.AddComponent()._superGroup = superGroup; // Fix rotation in the end cubeSphere.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); From 368b494f2ce403cc317bc7aa83bbea1b74c74419 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 23:14:02 -0400 Subject: [PATCH 33/72] Add ProxyShadowCaster when ProxyShadowCasterSuperGroup exists --- NewHorizons/Builder/Body/ProcGenBuilder.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/ProcGenBuilder.cs b/NewHorizons/Builder/Body/ProcGenBuilder.cs index af13da22..13d18b1a 100644 --- a/NewHorizons/Builder/Body/ProcGenBuilder.cs +++ b/NewHorizons/Builder/Body/ProcGenBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Body.Geometry; +using NewHorizons.Builder.Body.Geometry; using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; @@ -16,6 +16,7 @@ namespace NewHorizons.Builder.Body GameObject icosphere = new GameObject("Icosphere"); + icosphere.SetActive(false); icosphere.transform.parent = sector?.transform ?? planetGO.transform; icosphere.transform.rotation = Quaternion.Euler(90, 0, 0); icosphere.transform.position = planetGO.transform.position; @@ -33,7 +34,10 @@ namespace NewHorizons.Builder.Body cubeSphereMC.sharedMesh = mesh; icosphere.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - icosphere.AddComponent(); + var superGroup = planetGO.GetComponent(); + if (superGroup != null) icosphere.AddComponent()._superGroup = superGroup; + + icosphere.SetActive(true); } } } From d6c8f0a6dafde009e193a393694e5e3846e8bc40 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 23:14:27 -0400 Subject: [PATCH 34/72] More detail for exception --- NewHorizons/Builder/Props/DetailBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 54469e24..98c3927d 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -192,7 +192,7 @@ namespace NewHorizons.Builder.Props } catch (Exception e) { - Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] : {e.Message}, {e.StackTrace}"); + Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab.name}] : {e.GetType().FullName} {e.Message} {e.StackTrace}"); } }); } From 712873b58a90b7cb2d1971e5ed3eb3231d392aac Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 15:19:28 -0400 Subject: [PATCH 35/72] Simplify --- NewHorizons/Builder/Body/ProcGenBuilder.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/ProcGenBuilder.cs b/NewHorizons/Builder/Body/ProcGenBuilder.cs index 13d18b1a..156b6ba6 100644 --- a/NewHorizons/Builder/Body/ProcGenBuilder.cs +++ b/NewHorizons/Builder/Body/ProcGenBuilder.cs @@ -23,8 +23,7 @@ namespace NewHorizons.Builder.Body Mesh mesh = Icosphere.Build(4, module.scale, module.scale * 1.2f); - icosphere.AddComponent(); - icosphere.GetComponent().mesh = mesh; + icosphere.AddComponent().mesh = mesh; var cubeSphereMR = icosphere.AddComponent(); cubeSphereMR.material = new Material(Shader.Find("Standard")); From 4bcaef968d6128cf3ca88ade0040c273f71a15be Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 00:39:43 -0400 Subject: [PATCH 36/72] Fix not found error --- NewHorizons/Utility/SearchUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs index 6697ebdc..46a5ca16 100644 --- a/NewHorizons/Utility/SearchUtilities.cs +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -162,7 +162,7 @@ namespace NewHorizons.Utility { foreach (Transform c in t.GetComponentsInChildren(true)) { - if (t.name.Equals(names[i])) + if (c.name.Equals(names[i])) { child = c; break; From 977c790ef5989c36cadb052459edd78ae6d48c0d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 00:56:12 -0400 Subject: [PATCH 37/72] Use SearchUtilities.Find instead GameObject.Find --- .../Builder/Atmosphere/AtmosphereBuilder.cs | 5 ++- .../Builder/Atmosphere/CloudsBuilder.cs | 10 ++--- NewHorizons/Builder/Atmosphere/FogBuilder.cs | 6 +-- .../Builder/Atmosphere/VolumesBuilder.cs | 3 +- NewHorizons/Builder/Body/CometTailBuilder.cs | 5 ++- NewHorizons/Builder/Body/FunnelBuilder.cs | 12 +++--- NewHorizons/Builder/Body/GeometryBuilder.cs | 5 ++- NewHorizons/Builder/Body/LavaBuilder.cs | 9 +++-- NewHorizons/Builder/Body/ProxyBuilder.cs | 6 +-- NewHorizons/Builder/Body/SandBuilder.cs | 10 ++--- .../Builder/Body/SingularityBuilder.cs | 24 +++++------ NewHorizons/Builder/Body/StarBuilder.cs | 26 ++++++------ NewHorizons/Builder/Body/WaterBuilder.cs | 8 ++-- .../Builder/General/AmbientLightBuilder.cs | 5 ++- .../Builder/General/RigidBodyBuilder.cs | 5 ++- .../Builder/General/SpawnPointBuilder.cs | 7 ++-- NewHorizons/Builder/Props/DetailBuilder.cs | 2 +- NewHorizons/Builder/Props/GeyserBuilder.cs | 4 +- NewHorizons/Builder/Props/NomaiTextBuilder.cs | 8 ++-- .../Builder/Props/ProjectionBuilder.cs | 6 +-- NewHorizons/Builder/Props/ScatterBuilder.cs | 4 +- NewHorizons/Builder/Props/SignalBuilder.cs | 4 +- NewHorizons/Builder/Props/TornadoBuilder.cs | 8 ++-- NewHorizons/Builder/Props/VolcanoBuilder.cs | 4 +- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 8 ++-- .../Components/ShipLogStarChartMode.cs | 4 +- NewHorizons/Components/ShipWarpController.cs | 9 +++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 16 ++++---- .../Handlers/PlanetDestructionHandler.cs | 16 ++++---- NewHorizons/Handlers/ShipLogHandler.cs | 4 +- NewHorizons/Handlers/StarChartHandler.cs | 8 ++-- NewHorizons/Handlers/SystemCreationHandler.cs | 4 +- NewHorizons/Handlers/TitleSceneHandler.cs | 10 ++--- NewHorizons/Main.cs | 8 ++-- NewHorizons/Patches/ShipLogPatches.cs | 10 ++--- NewHorizons/Patches/WarpDrivePatches.cs | 5 ++- NewHorizons/Utility/AstroObjectLocator.cs | 40 +++++++++---------- .../Utility/DebugUtilities/DebugReload.cs | 4 +- NewHorizons/Utility/SearchUtilities.cs | 8 ++-- 39 files changed, 175 insertions(+), 165 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs index c60ae6a3..5260fbf7 100644 --- a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Atmosphere { @@ -16,7 +17,7 @@ namespace NewHorizons.Builder.Atmosphere if (atmosphereModule.useAtmosphereShader) { - GameObject atmo = GameObject.Instantiate(GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true); + GameObject atmo = GameObject.Instantiate(SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true); atmo.transform.position = planetGO.transform.TransformPoint(Vector3.zero); atmo.transform.localScale = Vector3.one * atmosphereModule.size * 1.2f; foreach (var meshRenderer in atmo.GetComponentsInChildren()) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 8363f36a..82900a6b 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -21,7 +21,7 @@ namespace NewHorizons.Builder.Atmosphere public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) { - if (_lightningPrefab == null) _lightningPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); + if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); GameObject cloudsMainGO = new GameObject("Clouds"); @@ -36,8 +36,8 @@ namespace NewHorizons.Builder.Atmosphere cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); - bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; - var bottomTSRMaterials = GameObject.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; + bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; + var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; // If they set a colour apply it to all the materials else keep the default QM one if (atmo.clouds.tint != null) @@ -165,12 +165,12 @@ namespace NewHorizons.Builder.Atmosphere cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; MeshFilter topMF = cloudsTopGO.AddComponent(); - topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; + topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; MeshRenderer topMR = cloudsTopGO.AddComponent(); if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); - if (_gdCloudMaterials == null) _gdCloudMaterials = GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; + if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; var tempArray = new Material[2]; if (atmo.clouds.useBasicCloudShader) diff --git a/NewHorizons/Builder/Atmosphere/FogBuilder.cs b/NewHorizons/Builder/Atmosphere/FogBuilder.cs index b521ede5..4eae1a82 100644 --- a/NewHorizons/Builder/Atmosphere/FogBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/FogBuilder.cs @@ -17,9 +17,9 @@ namespace NewHorizons.Builder.Atmosphere fogGO.transform.localScale = Vector3.one; // Going to copy from dark bramble - var dbFog = GameObject.Find("DarkBramble_Body/Atmosphere_DB/FogLOD"); - var dbPlanetaryFogController = GameObject.Find("DarkBramble_Body/Atmosphere_DB/FogSphere_DB").GetComponent(); - var brambleLODFog = GameObject.Find("DarkBramble_Body/Sector_DB/Proxy_DB/LOD_DB_VolumeticFog"); + var dbFog = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogLOD"); + var dbPlanetaryFogController = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogSphere_DB").GetComponent(); + var brambleLODFog = SearchUtilities.Find("DarkBramble_Body/Sector_DB/Proxy_DB/LOD_DB_VolumeticFog"); MeshFilter MF = fogGO.AddComponent(); MF.mesh = dbFog.GetComponent().mesh; diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index 12ccc732..cba3845d 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.External.Configs; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Atmosphere { @@ -37,7 +38,7 @@ namespace NewHorizons.Builder.Atmosphere EffectRuleset ER = rulesetGO.AddComponent(); ER._type = EffectRuleset.BubbleType.Underwater; - var gdRuleset = GameObject.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent(); + var gdRuleset = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent(); ER._material = gdRuleset._material; diff --git a/NewHorizons/Builder/Body/CometTailBuilder.cs b/NewHorizons/Builder/Body/CometTailBuilder.cs index be13a836..5980b2d1 100644 --- a/NewHorizons/Builder/Body/CometTailBuilder.cs +++ b/NewHorizons/Builder/Body/CometTailBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Body { @@ -6,7 +7,7 @@ namespace NewHorizons.Builder.Body { public static void Make(GameObject planetGO, Sector sector, PlanetConfig config) { - var cometTail = GameObject.Instantiate(GameObject.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes"), sector?.transform ?? planetGO.transform); + var cometTail = GameObject.Instantiate(SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes"), sector?.transform ?? planetGO.transform); cometTail.transform.position = planetGO.transform.position; cometTail.name = "CometTail"; cometTail.transform.localScale = Vector3.one * config.Base.surfaceSize / 110; diff --git a/NewHorizons/Builder/Body/FunnelBuilder.cs b/NewHorizons/Builder/Body/FunnelBuilder.cs index 9c54486f..eea69694 100644 --- a/NewHorizons/Builder/Body/FunnelBuilder.cs +++ b/NewHorizons/Builder/Body/FunnelBuilder.cs @@ -1,4 +1,4 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization; using NewHorizons.Components; using NewHorizons.Utility; using UnityEngine; @@ -43,13 +43,13 @@ namespace NewHorizons.Builder.Body scaleRoot.transform.localPosition = Vector3.zero; scaleRoot.transform.localScale = new Vector3(1, 1, 1); - var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform); + var proxyGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform); proxyGO.name = "Proxy_Funnel"; - var geoGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel"), scaleRoot.transform); + var geoGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel"), scaleRoot.transform); geoGO.name = "Geo_Funnel"; - var volumesGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform); + var volumesGO = GameObject.Instantiate(SearchUtilities.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform); volumesGO.name = "Volumes_Funnel"; var sfv = volumesGO.GetComponentInChildren(); var fluidVolume = sfv.gameObject; @@ -63,7 +63,7 @@ namespace NewHorizons.Builder.Body GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject); - var waterMaterials = GameObject.Find("TimberHearth_Body/Sector_TH/Geometry_TH/Terrain_TH_Water_v3/Village_Upper_Water/Village_Upper_Water_Geo").GetComponent().materials; + var waterMaterials = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Geometry_TH/Terrain_TH_Water_v3/Village_Upper_Water/Village_Upper_Water_Geo").GetComponent().materials; var materials = new Material[waterMaterials.Length]; for (int i = 0; i < waterMaterials.Length; i++) { @@ -111,7 +111,7 @@ namespace NewHorizons.Builder.Body GameObject.Destroy(geoGO.transform.Find("Effects_HT_SandColumn/SandColumn_Interior").gameObject); - var lavaMaterial = new Material(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent().material); + var lavaMaterial = new Material(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere").GetComponent().material); lavaMaterial.mainTextureOffset = new Vector2(0.1f, 0.2f); lavaMaterial.mainTextureScale = new Vector2(1f, 3f); diff --git a/NewHorizons/Builder/Body/GeometryBuilder.cs b/NewHorizons/Builder/Body/GeometryBuilder.cs index dc422e71..fb0fc698 100644 --- a/NewHorizons/Builder/Body/GeometryBuilder.cs +++ b/NewHorizons/Builder/Body/GeometryBuilder.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using UnityEngine; +using NewHorizons.Utility; namespace NewHorizons.Builder.Body { public static class GeometryBuilder @@ -9,7 +10,7 @@ namespace NewHorizons.Builder.Body groundGO.transform.parent = sector?.transform ?? planetGO.transform; groundGO.transform.localScale = new Vector3(groundScale, groundScale, groundScale); groundGO.transform.position = planetGO.transform.position; - groundGO.GetComponent().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; + groundGO.GetComponent().mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; groundGO.GetComponent().radius = 1f; groundGO.SetActive(true); } diff --git a/NewHorizons/Builder/Body/LavaBuilder.cs b/NewHorizons/Builder/Body/LavaBuilder.cs index ea831506..dc1d4d47 100644 --- a/NewHorizons/Builder/Body/LavaBuilder.cs +++ b/NewHorizons/Builder/Body/LavaBuilder.cs @@ -1,5 +1,6 @@ -using System.Collections.Generic; +using System.Collections.Generic; using UnityEngine; +using NewHorizons.Utility; using NewHorizons.External.Modules.VariableSize; namespace NewHorizons.Builder.Body @@ -28,7 +29,7 @@ namespace NewHorizons.Builder.Body moltenCore.transform.position = planetGO.transform.position; moltenCore.transform.localScale = Vector3.one * module.size; - var lavaSphere = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform); + var lavaSphere = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform); lavaSphere.transform.localScale = Vector3.one; lavaSphere.transform.name = "LavaSphere"; lavaSphere.GetComponent().material.SetFloat(HeightScale, heightScale); @@ -37,7 +38,7 @@ namespace NewHorizons.Builder.Body var sectorCullGroup = lavaSphere.GetComponent(); sectorCullGroup.SetSector(sector); - var moltenCoreProxy = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/MoltenCore_Proxy"), moltenCore.transform); ; + var moltenCoreProxy = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/MoltenCore_Proxy"), moltenCore.transform); ; moltenCoreProxy.name = "MoltenCore_Proxy"; var proxyLavaSphere = moltenCoreProxy.transform.Find("LavaSphere (1)"); @@ -50,7 +51,7 @@ namespace NewHorizons.Builder.Body sectorProxy._renderers = new List { proxyLavaSphere.GetComponent() }; sectorProxy.SetSector(sector); - var destructionVolume = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/DestructionVolume"), moltenCore.transform); + var destructionVolume = GameObject.Instantiate(SearchUtilities.Find("VolcanicMoon_Body/MoltenCore_VM/DestructionVolume"), moltenCore.transform); destructionVolume.GetComponent().radius = 1; destructionVolume.SetActive(true); diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index fb950a47..aea9a019 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Atmosphere; +using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Props; using NewHorizons.Components; using NewHorizons.Components.SizeControllers; @@ -176,7 +176,7 @@ namespace NewHorizons.Builder.Body private static void MakeBlackHole(GameObject rootObject, float size) { - if (_blackHolePrefab == null) _blackHolePrefab = GameObject.Find(_blackHolePath); + if (_blackHolePrefab == null) _blackHolePrefab = SearchUtilities.Find(_blackHolePath); var blackHoleShader = _blackHolePrefab.GetComponent().material.shader; if (blackHoleShader == null) blackHoleShader = _blackHolePrefab.GetComponent().sharedMaterial.shader; @@ -201,7 +201,7 @@ namespace NewHorizons.Builder.Body private static void MakeWhiteHole(GameObject rootObject, float size) { - if (_whiteHolePrefab == null) _whiteHolePrefab = GameObject.Find(_whiteHolePath); + if (_whiteHolePrefab == null) _whiteHolePrefab = SearchUtilities.Find(_whiteHolePath); var whiteHoleShader = _whiteHolePrefab.GetComponent().material.shader; if (whiteHoleShader == null) whiteHoleShader = _whiteHolePrefab.GetComponent().sharedMaterial.shader; diff --git a/NewHorizons/Builder/Body/SandBuilder.cs b/NewHorizons/Builder/Body/SandBuilder.cs index 35de7c8b..43b86ac5 100644 --- a/NewHorizons/Builder/Body/SandBuilder.cs +++ b/NewHorizons/Builder/Body/SandBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Utility; +using NewHorizons.Utility; using UnityEngine; using NewHorizons.External.Modules.VariableSize; @@ -11,7 +11,7 @@ namespace NewHorizons.Builder.Body var sandGO = new GameObject("Sand"); sandGO.SetActive(false); - var sandSphere = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/SandSphere"), sandGO.transform); + var sandSphere = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/SandSphere"), sandGO.transform); if (module.tint != null) { var oldMR = sandSphere.GetComponent(); @@ -28,13 +28,13 @@ namespace NewHorizons.Builder.Body sandMR.sharedMaterials[1].color = module.tint.ToColor(); } - var collider = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/Collider"), sandGO.transform); + var collider = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/Collider"), sandGO.transform); var sphereCollider = collider.GetComponent(); collider.SetActive(true); - var occlusionSphere = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/OcclusionSphere"), sandGO.transform); + var occlusionSphere = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/OcclusionSphere"), sandGO.transform); - var proxyShadowCasterGO = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/ProxyShadowCaster"), sandGO.transform); + var proxyShadowCasterGO = GameObject.Instantiate(SearchUtilities.Find("TowerTwin_Body/SandSphere_Draining/ProxyShadowCaster"), sandGO.transform); var proxyShadowCaster = proxyShadowCasterGO.GetComponent(); proxyShadowCaster.SetSuperGroup(sandGO.GetComponent()); diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index 949041f0..b9a031f6 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.External.Configs; using NewHorizons.Utility; using System; @@ -88,10 +88,10 @@ namespace NewHorizons.Builder.Body blackHoleRender.transform.localScale = Vector3.one * size; var meshFilter = blackHoleRender.AddComponent(); - meshFilter.mesh = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().mesh; + meshFilter.mesh = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().mesh; var meshRenderer = blackHoleRender.AddComponent(); - if (blackHoleShader == null) blackHoleShader = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().sharedMaterial.shader; + if (blackHoleShader == null) blackHoleShader = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().sharedMaterial.shader; meshRenderer.material = new Material(blackHoleShader); meshRenderer.material.SetFloat(Radius, size * 0.4f); meshRenderer.material.SetFloat(MaxDistortRadius, size * 0.95f); @@ -100,7 +100,7 @@ namespace NewHorizons.Builder.Body if (makeAudio) { - var blackHoleAmbience = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleAmbience"), blackHole.transform); + var blackHoleAmbience = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleAmbience"), blackHole.transform); blackHoleAmbience.name = "BlackHoleAmbience"; blackHoleAmbience.GetComponent().SetSector(sector); @@ -109,7 +109,7 @@ namespace NewHorizons.Builder.Body blackHoleAudioSource.minDistance = size * 0.4f; blackHoleAmbience.transform.localPosition = Vector3.zero; - var blackHoleOneShot = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleEmissionOneShot"), blackHole.transform); + var blackHoleOneShot = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleEmissionOneShot"), blackHole.transform); var oneShotAudioSource = blackHoleOneShot.GetComponent(); oneShotAudioSource.maxDistance = size * 3f; oneShotAudioSource.minDistance = size * 0.4f; @@ -137,7 +137,7 @@ namespace NewHorizons.Builder.Body } else { - var blackHoleVolume = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume"), blackHole.transform); + var blackHoleVolume = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume"), blackHole.transform); blackHoleVolume.name = "BlackHoleVolume"; blackHoleVolume.GetComponent().radius = size * 0.4f; } @@ -159,10 +159,10 @@ namespace NewHorizons.Builder.Body whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f; var meshFilter = whiteHoleRenderer.AddComponent(); - meshFilter.mesh = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().mesh; + meshFilter.mesh = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().mesh; var meshRenderer = whiteHoleRenderer.AddComponent(); - if (whiteHoleShader == null) whiteHoleShader = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().sharedMaterial.shader; + if (whiteHoleShader == null) whiteHoleShader = SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().sharedMaterial.shader; meshRenderer.material = new Material(whiteHoleShader); meshRenderer.sharedMaterial.SetFloat(Radius, size * 0.4f); meshRenderer.sharedMaterial.SetFloat(DistortFadeDist, size); @@ -170,14 +170,14 @@ namespace NewHorizons.Builder.Body meshRenderer.sharedMaterial.SetFloat(MassScale, -1); meshRenderer.sharedMaterial.SetColor(Color1, new Color(1.88f, 1.88f, 1.88f, 1f)); - var ambientLight = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH")); + var ambientLight = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH")); ambientLight.transform.parent = whiteHole.transform; ambientLight.transform.localScale = Vector3.one; ambientLight.transform.localPosition = Vector3.zero; ambientLight.name = "AmbientLight"; ambientLight.GetComponent().range = size * 7f; - GameObject whiteHoleVolumeGO = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVolume")); + GameObject whiteHoleVolumeGO = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/WhiteHoleVolume")); whiteHoleVolumeGO.transform.parent = whiteHole.transform; whiteHoleVolumeGO.transform.localPosition = Vector3.zero; whiteHoleVolumeGO.transform.localScale = Vector3.one; @@ -205,13 +205,13 @@ namespace NewHorizons.Builder.Body if (makeZeroGVolume) { - var zeroGVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/ZeroGVolume"), whiteHole.transform); + var zeroGVolume = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/ZeroGVolume"), whiteHole.transform); zeroGVolume.name = "ZeroGVolume"; zeroGVolume.transform.localPosition = Vector3.zero; zeroGVolume.GetComponent().radius = size * 10f; zeroGVolume.GetComponent()._attachedBody = OWRB; - var rulesetVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole"), planetGO.transform); + var rulesetVolume = GameObject.Instantiate(SearchUtilities.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole"), planetGO.transform); rulesetVolume.name = "RulesetVolume"; rulesetVolume.transform.localPosition = Vector3.zero; rulesetVolume.transform.localScale = Vector3.one * size / 100f; diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index ba5d303a..aa0cc253 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -23,7 +23,7 @@ namespace NewHorizons.Builder.Body { var starGO = MakeStarGraphics(planetGO, sector, starModule); - var sunAudio = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); + var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); sunAudio.transform.localPosition = Vector3.zero; sunAudio.transform.localScale = Vector3.one; sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent().maxDistance = starModule.size * 2f; @@ -36,7 +36,7 @@ namespace NewHorizons.Builder.Body GameObject sunAtmosphere = null; if (starModule.hasAtmosphere) { - sunAtmosphere = Object.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); + sunAtmosphere = Object.Instantiate(SearchUtilities.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); sunAtmosphere.transform.position = planetGO.transform.position; sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio; sunAtmosphere.name = "Atmosphere_Star"; @@ -59,17 +59,17 @@ namespace NewHorizons.Builder.Body fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f); } - var ambientLightGO = Object.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); + var ambientLightGO = Object.Instantiate(SearchUtilities.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); ambientLightGO.transform.localPosition = Vector3.zero; ambientLightGO.name = "AmbientLight_Star"; - var heatVolume = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), starGO.transform); + var heatVolume = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), starGO.transform); heatVolume.transform.localPosition = Vector3.zero; heatVolume.transform.localScale = Vector3.one; heatVolume.GetComponent().radius = 1f; heatVolume.name = "HeatVolume"; - var deathVolume = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), starGO.transform); + var deathVolume = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), starGO.transform); deathVolume.transform.localPosition = Vector3.zero; deathVolume.transform.localScale = Vector3.one; deathVolume.GetComponent().radius = 1f; @@ -85,7 +85,7 @@ namespace NewHorizons.Builder.Body sunLight.transform.localScale = Vector3.one; var light = sunLight.AddComponent(); - light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.solarLuminosity; light.range *= Mathf.Sqrt(starModule.solarLuminosity); @@ -96,12 +96,12 @@ namespace NewHorizons.Builder.Body ambientLight.color = lightColour; var faceActiveCamera = sunLight.AddComponent(); - faceActiveCamera.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + faceActiveCamera.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); var csmTextureCacher = sunLight.AddComponent(); - csmTextureCacher.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + csmTextureCacher.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); csmTextureCacher._light = light; var proxyShadowLight = sunLight.AddComponent(); - proxyShadowLight.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + proxyShadowLight.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); proxyShadowLight._light = light; StarController starController = null; @@ -172,12 +172,12 @@ namespace NewHorizons.Builder.Body var starGO = new GameObject("Star"); starGO.transform.parent = sector?.transform ?? rootObject.transform; - var sunSurface = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform); + var sunSurface = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform); sunSurface.transform.position = rootObject.transform.position; sunSurface.transform.localScale = Vector3.one; sunSurface.name = "Surface"; - var solarFlareEmitter = Object.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform); + var solarFlareEmitter = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform); solarFlareEmitter.transform.localPosition = Vector3.zero; solarFlareEmitter.transform.localScale = Vector3.one; solarFlareEmitter.name = "SolarFlareEmitter"; @@ -204,7 +204,7 @@ namespace NewHorizons.Builder.Body var colour = starModule.tint.ToColor(); - var sun = GameObject.Find("Sun_Body"); + var sun = SearchUtilities.Find("Sun_Body"); var mainSequenceMaterial = sun.GetComponent()._startSurfaceMaterial; var giantMaterial = sun.GetComponent()._endSurfaceMaterial; @@ -230,7 +230,7 @@ namespace NewHorizons.Builder.Body private static SupernovaEffectController MakeSupernova(GameObject starGO, StarModule starModule) { - var supernovaGO = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); + var supernovaGO = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); supernovaGO.transform.SetParent(starGO.transform); supernovaGO.transform.localPosition = Vector3.zero; diff --git a/NewHorizons/Builder/Body/WaterBuilder.cs b/NewHorizons/Builder/Body/WaterBuilder.cs index 5780e638..fdb85ec8 100644 --- a/NewHorizons/Builder/Body/WaterBuilder.cs +++ b/NewHorizons/Builder/Body/WaterBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.Components.SizeControllers; using NewHorizons.Utility; using UnityEngine; @@ -19,7 +19,7 @@ namespace NewHorizons.Builder.Body waterGO.transform.parent = sector?.transform ?? planetGO.transform; waterGO.transform.localScale = new Vector3(waterSize, waterSize, waterSize); - var GDTSR = GameObject.Find("Ocean_GD").GetComponent(); + var GDTSR = SearchUtilities.Find("Ocean_GD").GetComponent(); TessellatedSphereRenderer TSR = waterGO.AddComponent(); TSR.tessellationMeshGroup = ScriptableObject.CreateInstance(); @@ -30,7 +30,7 @@ namespace NewHorizons.Builder.Body TSR.tessellationMeshGroup.variants[i] = mesh; } - var GDSharedMaterials = GameObject.Find("Ocean_GD").GetComponent()._lowAltitudeMaterials; + var GDSharedMaterials = SearchUtilities.Find("Ocean_GD").GetComponent()._lowAltitudeMaterials; var tempArray = new Material[GDSharedMaterials.Length]; for (int i = 0; i < GDSharedMaterials.Length; i++) { @@ -87,7 +87,7 @@ namespace NewHorizons.Builder.Body fluidVolume._radius = waterSize; fluidVolume._layer = LayerMask.NameToLayer("BasicEffectVolume"); - var fogGO = GameObject.Instantiate(GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/OceanFog"), waterGO.transform); + var fogGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/OceanFog"), waterGO.transform); fogGO.name = "OceanFog"; fogGO.transform.localPosition = Vector3.zero; fogGO.transform.localScale = Vector3.one; diff --git a/NewHorizons/Builder/General/AmbientLightBuilder.cs b/NewHorizons/Builder/General/AmbientLightBuilder.cs index 6ad20aaf..c51f90c0 100644 --- a/NewHorizons/Builder/General/AmbientLightBuilder.cs +++ b/NewHorizons/Builder/General/AmbientLightBuilder.cs @@ -1,11 +1,12 @@ -using UnityEngine; +using UnityEngine; +using NewHorizons.Utility; namespace NewHorizons.Builder.General { public static class AmbientLightBuilder { public static void Make(GameObject planetGO, Sector sector, float scale, float intensity) { - GameObject lightGO = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/AmbientLight_BH_Surface"), sector?.transform ?? planetGO.transform); + GameObject lightGO = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/AmbientLight_BH_Surface"), sector?.transform ?? planetGO.transform); lightGO.transform.position = planetGO.transform.position; lightGO.name = "Light"; diff --git a/NewHorizons/Builder/General/RigidBodyBuilder.cs b/NewHorizons/Builder/General/RigidBodyBuilder.cs index f6672314..a827cc2e 100644 --- a/NewHorizons/Builder/General/RigidBodyBuilder.cs +++ b/NewHorizons/Builder/General/RigidBodyBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.General { @@ -27,7 +28,7 @@ namespace NewHorizons.Builder.General owRigidBody._maintainOriginalCenterOfMass = true; owRigidBody._rigidbody = rigidBody; owRigidBody._kinematicRigidbody = kinematicRigidBody; - owRigidBody._origParent = GameObject.Find("SolarSystemRoot").transform; + owRigidBody._origParent = SearchUtilities.Find("SolarSystemRoot").transform; owRigidBody.EnableKinematicSimulation(); owRigidBody.MakeKinematic(); diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index f74767bd..8c26fd9c 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; +using NewHorizons.Utility; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.General @@ -43,7 +44,7 @@ namespace NewHorizons.Builder.General spawnPoint._isShipSpawn = true; spawnPoint._triggerVolumes = new OWTriggerVolume[0]; - var ship = GameObject.Find("Ship_Body"); + var ship = SearchUtilities.Find("Ship_Body"); ship.transform.position = spawnPoint.transform.position; if(module.shipSpawnRotation != null) @@ -92,7 +93,7 @@ namespace NewHorizons.Builder.General Locator.GetPlayerTransform().GetComponent().SuitUp(false, true, true); // Make the ship act as if the player took the suit - var spv = GameObject.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear")?.GetComponent(); + var spv = SearchUtilities.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear")?.GetComponent(); if (spv == null) return; diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 98c3927d..61287cb4 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -150,7 +150,7 @@ namespace NewHorizons.Builder.Props { torchItem.enabled = true; torchItem.mindProjectorTrigger.enabled = true; - torchItem.mindSlideProjector._mindProjectorImageEffect = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); + torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); } } else diff --git a/NewHorizons/Builder/Props/GeyserBuilder.cs b/NewHorizons/Builder/Props/GeyserBuilder.cs index bd177925..6cb77acb 100644 --- a/NewHorizons/Builder/Props/GeyserBuilder.cs +++ b/NewHorizons/Builder/Props/GeyserBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Props @@ -7,7 +7,7 @@ namespace NewHorizons.Builder.Props { public static void Make(GameObject planetGO, Sector sector, PropModule.GeyserInfo info) { - var original = GameObject.Find("TimberHearth_Body/Sector_TH/Interactables_TH/Geysers/Geyser_Village"); + var original = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Interactables_TH/Geysers/Geyser_Village"); GameObject geyserGO = original.InstantiateInactive(); geyserGO.transform.parent = sector?.transform ?? planetGO.transform; geyserGO.name = "Geyser"; diff --git a/NewHorizons/Builder/Props/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiTextBuilder.cs index b2cc2c44..d304a9b8 100644 --- a/NewHorizons/Builder/Props/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiTextBuilder.cs @@ -51,18 +51,18 @@ namespace NewHorizons.Builder.Props _ghostArcPrefabs.Add(arc); } - _scrollPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/Prefab_NOM_Scroll").InstantiateInactive(); + _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"; - _computerPrefab = GameObject.Find("VolcanicMoon_Body/Sector_VM/Interactables_VM/Prefab_NOM_Computer").InstantiateInactive(); + _computerPrefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Interactables_VM/Prefab_NOM_Computer").InstantiateInactive(); _computerPrefab.name = "Prefab_NOM_Computer"; _computerPrefab.transform.rotation = Quaternion.identity; - _cairnPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_Crossroads/Interactables_Crossroads/Trailmarkers/Prefab_NOM_BH_Cairn_Arc (1)").InstantiateInactive(); + _cairnPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_Crossroads/Interactables_Crossroads/Trailmarkers/Prefab_NOM_BH_Cairn_Arc (1)").InstantiateInactive(); _cairnPrefab.name = "Prefab_NOM_Cairn"; _cairnPrefab.transform.rotation = Quaternion.identity; - _recorderPrefab = GameObject.Find("Comet_Body/Prefab_NOM_Shuttle/Sector_NomaiShuttleInterior/Interactibles_NomaiShuttleInterior/Prefab_NOM_Recorder").InstantiateInactive(); + _recorderPrefab = SearchUtilities.Find("Comet_Body/Prefab_NOM_Shuttle/Sector_NomaiShuttleInterior/Interactibles_NomaiShuttleInterior/Prefab_NOM_Recorder").InstantiateInactive(); _recorderPrefab.name = "Prefab_NOM_Recorder"; _recorderPrefab.transform.rotation = Quaternion.identity; } diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index da0ab34f..d6bc9b7a 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -41,7 +41,7 @@ namespace NewHorizons.Builder.Props { if (_slideReelPrefab == null) { - _slideReelPrefab = GameObject.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(); + _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?"); @@ -139,7 +139,7 @@ namespace NewHorizons.Builder.Props { if (_autoPrefab == null) { - _autoPrefab = GameObject.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone4/Sector_BlightedShore/Sector_JammingControlRoom_Zone4/Interactables_JammingControlRoom_Zone4/AutoProjector_SignalJammer/Prefab_IP_AutoProjector_SignalJammer")?.gameObject?.InstantiateInactive(); + _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?"); @@ -261,7 +261,7 @@ namespace NewHorizons.Builder.Props // var mindSlideProjector = standingTorch.GetComponent(); - mindSlideProjector._mindProjectorImageEffect = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); + mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); // setup for visually supporting async texture loading mindSlideProjector.enabled = false; diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index f3293eaa..89307795 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Props GameObject prefab; if (propInfo.assetBundle != null) prefab = AssetBundleUtilities.LoadPrefab(propInfo.assetBundle, propInfo.path, mod); - else prefab = GameObject.Find(propInfo.path); + else prefab = SearchUtilities.Find(propInfo.path); for (int i = 0; i < propInfo.count; i++) { var randomInd = (int)Random.Range(0, points.Count - 1); diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs index 7f38857e..097ea6cb 100644 --- a/NewHorizons/Builder/Props/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -192,7 +192,7 @@ namespace NewHorizons.Builder.Props source.rolloffMode = AudioRolloffMode.Custom; if (_customCurve == null) - _customCurve = GameObject.Find("Moon_Body/Sector_THM/Characters_THM/Villager_HEA_Esker/Signal_Whistling").GetComponent().GetCustomCurve(AudioSourceCurveType.CustomRolloff); + _customCurve = SearchUtilities.Find("Moon_Body/Sector_THM/Characters_THM/Villager_HEA_Esker/Signal_Whistling").GetComponent().GetCustomCurve(AudioSourceCurveType.CustomRolloff); source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, _customCurve); // If it can be heard regularly then we play it immediately diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 730790b5..34c21494 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -26,17 +26,17 @@ namespace NewHorizons.Builder.Props { if (_upPrefab == null) { - _upPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado").InstantiateInactive(); + _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 = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive(); + _downPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive(); _downPrefab.name = "Tornado_Down_Prefab"; } if (_hurricanePrefab == null) { - _hurricanePrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane/").InstantiateInactive(); + _hurricanePrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane/").InstantiateInactive(); // 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,7 +50,7 @@ namespace NewHorizons.Builder.Props } if (_soundPrefab == null) { - _soundPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive(); + _soundPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive(); _soundPrefab.name = "AudioRail_Prefab"; } if (_mainTexture == null) diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs index a9e04b51..48f5fa99 100644 --- a/NewHorizons/Builder/Props/VolcanoBuilder.cs +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Props @@ -12,7 +12,7 @@ namespace NewHorizons.Builder.Props public static void Make(GameObject planetGO, Sector sector, PropModule.VolcanoInfo info) { - var prefab = GameObject.Find("VolcanicMoon_Body/Sector_VM/Effects_VM/VolcanoPivot (2)/MeteorLauncher"); + var prefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Effects_VM/VolcanoPivot (2)/MeteorLauncher"); var launcherGO = prefab.InstantiateInactive(); launcherGO.transform.parent = sector.transform; diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 8b007aa3..dcca9126 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -16,7 +16,7 @@ namespace NewHorizons.Builder.ShipLog #region General public static ShipLogAstroObject[][] ConstructMapMode(string systemName, GameObject transformParent, ShipLogAstroObject[][] currentNav, int layer) { - Material greyScaleMaterial = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/Sprite").GetComponent().material; + Material greyScaleMaterial = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/Sprite").GetComponent().material; List bodies = Main.BodyDict[systemName].Where( b => !(b.Config.ShipLog?.mapMode?.remove ?? false) && !b.Config.isQuantumState ).ToList(); @@ -251,12 +251,12 @@ namespace NewHorizons.Builder.ShipLog navMatrix[navIndex[0]][navIndex[1]] = null; if (astroObject.GetID() == "CAVE_TWIN" || astroObject.GetID() == "TOWER_TWIN") { - GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); + SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); } } else if (name == "SandFunnel") { - GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); + SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); } gameObject.SetActive(false); } diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLogStarChartMode.cs index 251ce350..78cd5200 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLogStarChartMode.cs @@ -1,4 +1,4 @@ -using NewHorizons.Handlers; +using NewHorizons.Handlers; using NewHorizons.Utility; using System; using System.Collections.Generic; @@ -136,7 +136,7 @@ namespace NewHorizons.Components { if (_cardTemplate == null) { - var panRoot = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot"); + var panRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot"); _cardTemplate = GameObject.Instantiate(panRoot.GetComponentInChildren().gameObject); _cardTemplate.SetActive(false); } diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index 470dc432..9f4a8cc3 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -1,4 +1,5 @@ -using NewHorizons.Builder.General; +using NewHorizons.Builder.General; +using NewHorizons.Utility; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Components @@ -26,8 +27,8 @@ namespace NewHorizons.Components public void Init() { - _blackHolePrefab = GameObject.Find(_blackHolePath); - _whiteHolePrefab = GameObject.Find(_whiteHolePath); + _blackHolePrefab = SearchUtilities.Find(_blackHolePath); + _whiteHolePrefab = SearchUtilities.Find(_whiteHolePath); } public void Start() @@ -183,7 +184,7 @@ namespace NewHorizons.Components // For some reason warping into the ship makes you suffocate while in the ship if (_wearingSuit) resources.OnSuitUp(); var o2Volume = Locator.GetShipBody().GetComponent(); - var atmoVolume = GameObject.Find("Ship_Body/Volumes/ShipAtmosphereVolume").GetComponent(); + var atmoVolume = SearchUtilities.Find("Ship_Body/Volumes/ShipAtmosphereVolume").GetComponent(); resources._cameraFluidDetector.AddVolume(atmoVolume); resources._cameraFluidDetector.OnVolumeAdded(atmoVolume); diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index b79e5116..1470b5f6 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -33,13 +33,13 @@ namespace NewHorizons.Handlers // Set up stars // Need to manage this when there are multiple stars - var sun = GameObject.Find("Sun_Body"); + var sun = SearchUtilities.Find("Sun_Body"); var starController = sun.AddComponent(); - starController.Light = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); - starController.AmbientLight = GameObject.Find("Sun_Body/AmbientLight_SUN").GetComponent(); - starController.FaceActiveCamera = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); - starController.CSMTextureCacher = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); - starController.ProxyShadowLight = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.Light = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.AmbientLight = SearchUtilities.Find("Sun_Body/AmbientLight_SUN").GetComponent(); + starController.FaceActiveCamera = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.CSMTextureCacher = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.ProxyShadowLight = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); starController.Intensity = 0.9859f; starController.SunColor = new Color(1f, 0.8845f, 0.6677f, 1f); @@ -137,7 +137,7 @@ namespace NewHorizons.Handlers catch (Exception) { if (body?.Config?.name == null) Logger.LogError($"How is there no name for {body}"); - else existingPlanet = GameObject.Find(body.Config.name.Replace(" ", "") + "_Body"); + else existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false); } if (existingPlanet != null) @@ -252,7 +252,7 @@ namespace NewHorizons.Handlers { foreach (var child in body.Config.removeChildren) { - Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.Find(go.name + "/" + child)?.SetActive(false), 2); + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => SearchUtilities.Find(go.name + "/" + child)?.SetActive(false), 2); } } diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 6dead21b..82c0454a 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.Utility; using OWML.Utils; using System; @@ -33,7 +33,7 @@ namespace NewHorizons.Handlers public static void RemoveSolarSystem() { // Stop the sun from killing the player - var sunVolumes = GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN"); + var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); sunVolumes.SetActive(false); foreach (var name in _solarSystemBodies) @@ -82,11 +82,11 @@ namespace NewHorizons.Handlers break; case AstroObject.Name.CaveTwin: case AstroObject.Name.TowerTwin: - DisableBody(GameObject.Find("FocalBody"), delete); - DisableBody(GameObject.Find("SandFunnel_Body"), delete); + DisableBody(SearchUtilities.Find("FocalBody"), delete); + DisableBody(SearchUtilities.Find("SandFunnel_Body"), delete); break; case AstroObject.Name.MapSatellite: - DisableBody(GameObject.Find("MapSatellite_Body"), delete); + DisableBody(SearchUtilities.Find("MapSatellite_Body"), delete); break; case AstroObject.Name.GiantsDeep: // Might prevent leftover jellyfish from existing @@ -100,7 +100,7 @@ namespace NewHorizons.Handlers break; case AstroObject.Name.TimberHearth: // Always just fucking kill this one to stop THE WARP BUG!!! - DisableBody(GameObject.Find("StreamingGroup_TH"), true); + DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true); foreach (var obj in GameObject.FindObjectsOfType()) { @@ -229,8 +229,8 @@ namespace NewHorizons.Handlers { if (name.Equals("TowerTwin")) name = "AshTwin"; if (name.Equals("CaveTwin")) name = "EmberTwin"; - var distantProxy = GameObject.Find(name + "_DistantProxy"); - var distantProxyClone = GameObject.Find(name + "_DistantProxy(Clone)"); + var distantProxy = SearchUtilities.Find(name + "_DistantProxy", false); + var distantProxyClone = SearchUtilities.Find(name + "_DistantProxy(Clone)", false); if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject); if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject); diff --git a/NewHorizons/Handlers/ShipLogHandler.cs b/NewHorizons/Handlers/ShipLogHandler.cs index 2ef80633..0d5faaf5 100644 --- a/NewHorizons/Handlers/ShipLogHandler.cs +++ b/NewHorizons/Handlers/ShipLogHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Utility; +using NewHorizons.Utility; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -26,7 +26,7 @@ namespace NewHorizons.Handlers _entryIDsToNHBody = new Dictionary(); _nhBodyToAstroIDs = new Dictionary(); - List gameObjects = SearchUtilities.GetAllChildren(GameObject.Find(PAN_ROOT_PATH)); + List gameObjects = SearchUtilities.GetAllChildren(SearchUtilities.Find(PAN_ROOT_PATH)); _vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray(); _vanillaBodyIDs = gameObjects.ConvertAll(g => g.GetComponent()?.GetID()).ToArray(); } diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index e22406d3..4b1844e6 100644 --- a/NewHorizons/Handlers/StarChartHandler.cs +++ b/NewHorizons/Handlers/StarChartHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components; using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; @@ -18,7 +18,7 @@ namespace NewHorizons.Handlers { _systems = systems; - var shipLogRoot = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas"); + var shipLogRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas"); var starChartLog = new GameObject("StarChartMode"); starChartLog.SetActive(false); @@ -29,7 +29,7 @@ namespace NewHorizons.Handlers ShipLogStarChartMode = starChartLog.AddComponent(); - var reticleImage = GameObject.Instantiate(GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform); + var reticleImage = GameObject.Instantiate(SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform); var scaleRoot = new GameObject("ScaleRoot"); scaleRoot.transform.parent = starChartLog.transform; @@ -45,7 +45,7 @@ namespace NewHorizons.Handlers var centerPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_Center")?.GetComponent(); var upperRightPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_UpperRight")?.GetComponent(); - var oneShotSource = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent(); + var oneShotSource = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent(); _starSystemToFactID = new Dictionary(); _factIDToStarSystem = new Dictionary(); diff --git a/NewHorizons/Handlers/SystemCreationHandler.cs b/NewHorizons/Handlers/SystemCreationHandler.cs index fa020c5d..473cb372 100644 --- a/NewHorizons/Handlers/SystemCreationHandler.cs +++ b/NewHorizons/Handlers/SystemCreationHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.StarSystem; +using NewHorizons.Builder.StarSystem; using NewHorizons.Components; using NewHorizons.Utility; using UnityEngine; @@ -9,7 +9,7 @@ namespace NewHorizons.Handlers { public static void LoadSystem(NewHorizonsSystem system) { - var skybox = GameObject.Find("Skybox/Starfield"); + var skybox = SearchUtilities.Find("Skybox/Starfield"); if (system.Config.skybox?.destroyStarField ?? false) { diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index 6baf33ea..ebbb4043 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -13,7 +13,7 @@ namespace NewHorizons.Handlers { public static void InitSubtitles() { - GameObject subtitleContainer = GameObject.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye"); + GameObject subtitleContainer = SearchUtilities.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye"); if (subtitleContainer == null) { @@ -60,11 +60,11 @@ namespace NewHorizons.Handlers body3.transform.localRotation = Quaternion.Euler(10f, 0f, 0f); } - GameObject.Find("Scene/Background/PlanetPivot/Prefab_HEA_Campfire").SetActive(false); - GameObject.Find("Scene/Background/PlanetPivot/PlanetRoot").SetActive(false); + SearchUtilities.Find("Scene/Background/PlanetPivot/Prefab_HEA_Campfire").SetActive(false); + SearchUtilities.Find("Scene/Background/PlanetPivot/PlanetRoot").SetActive(false); var lightGO = new GameObject("Light"); - lightGO.transform.parent = GameObject.Find("Scene/Background").transform; + lightGO.transform.parent = SearchUtilities.Find("Scene/Background").transform; lightGO.transform.localPosition = new Vector3(-47.9203f, 145.7596f, 43.1802f); var light = lightGO.AddComponent(); light.color = new Color(1f, 1f, 1f, 1f); @@ -98,7 +98,7 @@ namespace NewHorizons.Handlers HeightMapBuilder.Make(titleScreenGO, null, heightMap, body.Mod); - GameObject pivot = GameObject.Instantiate(GameObject.Find("Scene/Background/PlanetPivot"), GameObject.Find("Scene/Background").transform); + GameObject pivot = GameObject.Instantiate(SearchUtilities.Find("Scene/Background/PlanetPivot"), SearchUtilities.Find("Scene/Background").transform); pivot.GetComponent()._degreesPerSecond = 10f; foreach (Transform child in pivot.transform) { diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 0a965afc..d4bcc7fc 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -189,7 +189,7 @@ namespace NewHorizons } launchController.enabled = false; } - var nomaiProbe = GameObject.Find("NomaiProbe_Body"); + var nomaiProbe = SearchUtilities.Find("NomaiProbe_Body"); if (nomaiProbe != null) nomaiProbe.gameObject.SetActive(false); } @@ -220,7 +220,7 @@ namespace NewHorizons if (_ship != null) { - _ship = GameObject.Find("Ship_Body").InstantiateInactive(); + _ship = SearchUtilities.Find("Ship_Body").InstantiateInactive(); DontDestroyOnLoad(_ship); } @@ -237,7 +237,7 @@ namespace NewHorizons // Warp drive StarChartHandler.Init(SystemDict.Values.ToArray()); HasWarpDrive = StarChartHandler.CanWarp(); - _shipWarpController = GameObject.Find("Ship_Body").AddComponent(); + _shipWarpController = SearchUtilities.Find("Ship_Body").AddComponent(); _shipWarpController.Init(); if (HasWarpDrive == true) EnableWarpDrive(); @@ -250,7 +250,7 @@ namespace NewHorizons if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; // Fix the map satellite - GameObject.Find("HearthianMapSatellite_Body").AddComponent(); + SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent(); } else { diff --git a/NewHorizons/Patches/ShipLogPatches.cs b/NewHorizons/Patches/ShipLogPatches.cs index acc1c021..672660c8 100644 --- a/NewHorizons/Patches/ShipLogPatches.cs +++ b/NewHorizons/Patches/ShipLogPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using NewHorizons.Builder.ShipLog; using NewHorizons.Components; using NewHorizons.Handlers; @@ -135,8 +135,8 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(ShipLogMapMode), nameof(ShipLogMapMode.Initialize))] public static void ShipLogMapMode_Initialize(ShipLogMapMode __instance) { - GameObject panRoot = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH); - GameObject sunObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); + GameObject panRoot = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH); + GameObject sunObject = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); ShipLogAstroObject[][] navMatrix = MapModeBuilder.ConstructMapMode(Main.Instance.CurrentStarSystem, panRoot, __instance._astroObjects, sunObject.layer); if (navMatrix == null || navMatrix.Length <= 1) { @@ -151,9 +151,9 @@ namespace NewHorizons.Patches List delete = SearchUtilities.GetAllChildren(panRoot).Where(g => g.name.Contains("_ShipLog") == false).ToList(); foreach (GameObject gameObject in delete) { - Object.Destroy(GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name)); + Object.Destroy(SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name)); } - if (GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel") == null) + if (SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel") == null) { __instance._sandFunnel = __instance.gameObject.AddComponent(); } diff --git a/NewHorizons/Patches/WarpDrivePatches.cs b/NewHorizons/Patches/WarpDrivePatches.cs index ff5aec3a..3995e002 100644 --- a/NewHorizons/Patches/WarpDrivePatches.cs +++ b/NewHorizons/Patches/WarpDrivePatches.cs @@ -1,5 +1,6 @@ -using HarmonyLib; +using HarmonyLib; using NewHorizons.Handlers; +using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Patches { @@ -14,7 +15,7 @@ namespace NewHorizons.Patches var newPrompt = TranslationHandler.GetTranslation("INTERSTELLAR_MODE", TranslationHandler.TextType.UI); __instance._detectiveModePrompt.SetText(newPrompt); - var text = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); + var text = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); text.text = newPrompt; } diff --git a/NewHorizons/Utility/AstroObjectLocator.cs b/NewHorizons/Utility/AstroObjectLocator.cs index 428e0f4b..40cb3ddc 100644 --- a/NewHorizons/Utility/AstroObjectLocator.cs +++ b/NewHorizons/Utility/AstroObjectLocator.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using UnityEngine; namespace NewHorizons.Utility @@ -97,35 +97,35 @@ namespace NewHorizons.Utility switch (primary._name) { case AstroObject.Name.TowerTwin: - otherChildren.Add(GameObject.Find("TimeLoopRing_Body")); + otherChildren.Add(SearchUtilities.Find("TimeLoopRing_Body")); break; case AstroObject.Name.ProbeCannon: - otherChildren.Add(GameObject.Find("NomaiProbe_Body")); - otherChildren.Add(GameObject.Find("CannonMuzzle_Body")); - otherChildren.Add(GameObject.Find("FakeCannonMuzzle_Body (1)")); - otherChildren.Add(GameObject.Find("CannonBarrel_Body")); - otherChildren.Add(GameObject.Find("FakeCannonBarrel_Body (1)")); - otherChildren.Add(GameObject.Find("Debris_Body (1)")); + otherChildren.Add(SearchUtilities.Find("NomaiProbe_Body")); + otherChildren.Add(SearchUtilities.Find("CannonMuzzle_Body")); + otherChildren.Add(SearchUtilities.Find("FakeCannonMuzzle_Body (1)")); + otherChildren.Add(SearchUtilities.Find("CannonBarrel_Body")); + otherChildren.Add(SearchUtilities.Find("FakeCannonBarrel_Body (1)")); + otherChildren.Add(SearchUtilities.Find("Debris_Body (1)")); break; case AstroObject.Name.GiantsDeep: - otherChildren.Add(GameObject.Find("BrambleIsland_Body")); - otherChildren.Add(GameObject.Find("GabbroIsland_Body")); - otherChildren.Add(GameObject.Find("QuantumIsland_Body")); - otherChildren.Add(GameObject.Find("StatueIsland_Body")); - otherChildren.Add(GameObject.Find("ConstructionYardIsland_Body")); - otherChildren.Add(GameObject.Find("GabbroShip_Body")); + otherChildren.Add(SearchUtilities.Find("BrambleIsland_Body")); + otherChildren.Add(SearchUtilities.Find("GabbroIsland_Body")); + otherChildren.Add(SearchUtilities.Find("QuantumIsland_Body")); + otherChildren.Add(SearchUtilities.Find("StatueIsland_Body")); + otherChildren.Add(SearchUtilities.Find("ConstructionYardIsland_Body")); + otherChildren.Add(SearchUtilities.Find("GabbroShip_Body")); break; case AstroObject.Name.WhiteHole: - otherChildren.Add(GameObject.Find("WhiteholeStation_Body")); - otherChildren.Add(GameObject.Find("WhiteholeStationSuperstructure_Body")); + otherChildren.Add(SearchUtilities.Find("WhiteholeStation_Body")); + otherChildren.Add(SearchUtilities.Find("WhiteholeStationSuperstructure_Body")); break; case AstroObject.Name.TimberHearth: - otherChildren.Add(GameObject.Find("MiningRig_Body")); - otherChildren.Add(GameObject.Find("Ship_Body")); + otherChildren.Add(SearchUtilities.Find("MiningRig_Body")); + otherChildren.Add(SearchUtilities.Find("Ship_Body")); break; case AstroObject.Name.DreamWorld: - otherChildren.Add(GameObject.Find("BackRaft_Body")); - otherChildren.Add(GameObject.Find("SealRaft_Body")); + otherChildren.Add(SearchUtilities.Find("BackRaft_Body")); + otherChildren.Add(SearchUtilities.Find("SealRaft_Body")); break; // For some dumb reason the sun station doesn't use AstroObject.Name.SunStation case AstroObject.Name.CustomString: diff --git a/NewHorizons/Utility/DebugUtilities/DebugReload.cs b/NewHorizons/Utility/DebugUtilities/DebugReload.cs index 8e763eab..ac48c7ad 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugReload.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugReload.cs @@ -1,4 +1,4 @@ -using NewHorizons.Handlers; +using NewHorizons.Handlers; using OWML.Common; using OWML.Common.Menus; using System; @@ -45,7 +45,7 @@ namespace NewHorizons.Utility.DebugUtilities Logger.LogWarning("Error While Reloading"); } - GameObject.Find("/PauseMenu/PauseMenuManagers").GetComponent().OnSkipToNextTimeLoop(); + SearchUtilities.Find("/PauseMenu/PauseMenuManagers").GetComponent().OnSkipToNextTimeLoop(); Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem); diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs index 46a5ca16..af140b5d 100644 --- a/NewHorizons/Utility/SearchUtilities.cs +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -129,7 +129,7 @@ namespace NewHorizons.Utility return null; } - public static GameObject Find(string path) + public static GameObject Find(string path, bool warn = true) { if (CachedGameObjects.ContainsKey(path)) { @@ -150,7 +150,7 @@ namespace NewHorizons.Utility var t = root?.transform; if (t == null) { - Logger.LogWarning($"Couldn't find root object in path ({names[0]})"); + if (warn) Logger.LogWarning($"Couldn't find root object in path ({names[0]})"); } else { @@ -172,7 +172,7 @@ namespace NewHorizons.Utility if (child == null) { - Logger.LogWarning($"Couldn't find object in path ({names[i]})"); + if (warn) Logger.LogWarning($"Couldn't find object in path ({names[i]})"); t = null; break; } @@ -187,7 +187,7 @@ namespace NewHorizons.Utility if (go == null) { var name = names.Last(); - Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}"); + if (warn) Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}"); go = FindObjectOfTypeAndName(name); } From ec0d500ef1725cb3043f7f0debccc1abfeaa5620 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 03:33:28 -0400 Subject: [PATCH 38/72] Try Catch --- NewHorizons/Main.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index d4bcc7fc..f4c9ad09 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -158,7 +158,14 @@ namespace NewHorizons private static void OnWakeUp() { IsSystemReady = true; - Instance.OnStarSystemLoaded?.Invoke(Instance.CurrentStarSystem); + try + { + Instance.OnStarSystemLoaded?.Invoke(Instance.CurrentStarSystem); + } + catch (Exception e) + { + Logger.LogError($"Exception thrown when invoking star system loaded event with parameter [{Instance.CurrentStarSystem}] : {e.GetType().FullName} {e.Message} {e.StackTrace}"); + } } private void OnSceneUnloaded(Scene scene) From c8e88f10b2b401d03edd7d567919ea5333765343 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 03:33:57 -0400 Subject: [PATCH 39/72] Star Light Radius --- NewHorizons/Builder/Body/StarBuilder.cs | 1 + NewHorizons/External/Modules/VariableSize/StarModule.cs | 8 +++++++- NewHorizons/Schemas/body_schema.json | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index aa0cc253..a2c81ed1 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -87,6 +87,7 @@ namespace NewHorizons.Builder.Body var light = sunLight.AddComponent(); light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.solarLuminosity; + light.range = starModule.lightRadius; light.range *= Mathf.Sqrt(starModule.solarLuminosity); Color lightColour = light.color; diff --git a/NewHorizons/External/Modules/VariableSize/StarModule.cs b/NewHorizons/External/Modules/VariableSize/StarModule.cs index d722be68..201571e3 100644 --- a/NewHorizons/External/Modules/VariableSize/StarModule.cs +++ b/NewHorizons/External/Modules/VariableSize/StarModule.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using NewHorizons.Utility; using Newtonsoft.Json; @@ -55,5 +55,11 @@ namespace NewHorizons.External.Modules.VariableSize /// Colour of the star. /// public MColor tint; + + /// + /// How far the light from the star can reach. + /// + [DefaultValue(50000f)] [Range(0f, double.MaxValue)] + public float lightRadius = 50000f; } } diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index cc33cc0e..662f19a4 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1772,6 +1772,13 @@ "tint": { "description": "Colour of the star.", "$ref": "#/definitions/MColor" + }, + "lightRadius": { + "type": "number", + "description": "How far the light from the star can reach.", + "format": "float", + "default": 50000.0, + "minimum": 0.0 } } }, From 96e9294ef0c047322cf806bcd4808ea0558edc0a Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 30 May 2022 22:12:12 -0400 Subject: [PATCH 40/72] rename --- NewHorizons/Builder/Props/DetailBuilder.cs | 4 ++-- NewHorizons/External/Modules/PropModule.cs | 2 +- NewHorizons/Schemas/body_schema.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 61287cb4..c070b6a4 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -62,9 +62,9 @@ namespace NewHorizons.Builder.Props detailGO = newDetailGO; } - if (detail.comment != null) + if (detail.rename != null) { - detailGO.name = detail.comment; + detailGO.name = detail.rename; } detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO; diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index c1650079..c378c7af 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -116,7 +116,7 @@ namespace NewHorizons.External.Modules /// /// An optional rename of the detail /// - public string comment; + public string rename; /// /// Do we override rotation and try to automatically align this object to stand upright on the body's surface? diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 662f19a4..f5943fe5 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -813,7 +813,7 @@ "type": "object", "additionalProperties": false, "properties": { - "comment": { + "rename": { "type": "string", "description": "An optional rename of the detail" }, From c66804da55bdd7bdf0e5bbdc4cd83bb260d8a5e9 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 1 Jun 2022 06:37:24 -0400 Subject: [PATCH 41/72] Customizable Travel Audio (#31) --- .../External/Configs/StarSystemConfig.cs | 10 ++++++++ NewHorizons/Handlers/SystemCreationHandler.cs | 24 +++++++++++++++++++ NewHorizons/Schemas/star_system_schema.json | 8 +++++++ 3 files changed, 42 insertions(+) diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index a939a456..86cc9c2b 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -51,6 +51,16 @@ namespace NewHorizons.External.Configs /// public bool startHere; + /// + /// Name of an existing AudioClip in the game that will play when travelling in space. + /// + public string travelAudioClip; + + /// + /// Relative filepath to the .wav file to use as the audio. Mutually exclusive with travelAudioClip. + /// + public string travelAudioFilePath; + public class NomaiCoordinates { public int[] x; diff --git a/NewHorizons/Handlers/SystemCreationHandler.cs b/NewHorizons/Handlers/SystemCreationHandler.cs index 473cb372..f4c0ca99 100644 --- a/NewHorizons/Handlers/SystemCreationHandler.cs +++ b/NewHorizons/Handlers/SystemCreationHandler.cs @@ -26,6 +26,30 @@ namespace NewHorizons.Handlers var timeLoopController = new GameObject("TimeLoopController"); timeLoopController.AddComponent(); } + + AudioClip clip = null; + if (system.Config.travelAudioClip != null) clip = SearchUtilities.FindResourceOfTypeAndName(system.Config.travelAudioClip); + else if (system.Config.travelAudioFilePath != null) + { + try + { + clip = AudioUtilities.LoadAudio(system.Mod.ModHelper.Manifest.ModFolderPath + "/" + system.Config.travelAudioFilePath); + } + catch (System.Exception e) + { + Utility.Logger.LogError($"Couldn't load audio file {system.Config.travelAudioFilePath} : {e.Message}"); + } + } + + if (clip != null) + { + var travelSource = Locator.GetGlobalMusicController()._travelSource; + travelSource._audioLibraryClip = AudioType.None; + travelSource._clipArrayIndex = 0; + travelSource._clipArrayLength = 0; + travelSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL; + travelSource.clip = clip; + } } } } diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index 13ae6ecc..1a4076a5 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -38,6 +38,14 @@ "type": "boolean", "description": "Set to `true` if you want to spawn here after dying, not Timber Hearth. You can still warp back to the main star\nsystem." }, + "travelAudioClip": { + "type": "string", + "description": "Name of an existing AudioClip in the game that will play when travelling in space." + }, + "travelAudioFilePath": { + "type": "string", + "description": "Relative filepath to the .wav file to use as the audio. Mutually exclusive with travelAudioClip." + }, "$schema": { "type": "string", "description": "The schema to validate with" From 095e8819c817919c76fd1429f1e6886f954f16a2 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 01:27:23 -0400 Subject: [PATCH 42/72] Target When Close For Ship --- NewHorizons/Builder/General/RFVolumeBuilder.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index 83e76cb5..e34b29a0 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -19,8 +19,10 @@ namespace NewHorizons.Builder.General var RFV = rfGO.AddComponent(); + var minTargetDistance = module.targetWhenClose ? 0 : sphereOfInfluence; + var RV = new ReferenceFrame(owrb); - RV._minSuitTargetDistance = module.targetWhenClose ? 0 : sphereOfInfluence; + RV._minSuitTargetDistance = minTargetDistance; RV._maxTargetDistance = 0; RV._autopilotArrivalDistance = 2.0f * sphereOfInfluence; RV._autoAlignmentDistance = sphereOfInfluence * 1.5f; @@ -32,7 +34,7 @@ namespace NewHorizons.Builder.General RV._bracketsRadius = module.bracketRadius > -1 ? module.bracketRadius : sphereOfInfluence; RFV._referenceFrame = RV; - RFV._minColliderRadius = sphereOfInfluence; + RFV._minColliderRadius = minTargetDistance; RFV._maxColliderRadius = sphereOfInfluence * 2f; RFV._isPrimaryVolume = true; RFV._isCloseRangeVolume = false; From 2da8e22b4b5c36afef00cbc661eb07b547b59294 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 01:44:56 -0400 Subject: [PATCH 43/72] Max Target Distance --- NewHorizons/Builder/General/RFVolumeBuilder.cs | 2 +- NewHorizons/External/Modules/ReferenceFrameModule.cs | 5 +++++ NewHorizons/Schemas/body_schema.json | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index e34b29a0..178234e4 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -35,7 +35,7 @@ namespace NewHorizons.Builder.General RFV._referenceFrame = RV; RFV._minColliderRadius = minTargetDistance; - RFV._maxColliderRadius = sphereOfInfluence * 2f; + RFV._maxColliderRadius = module.maxTargetDistance > -1 ? module.maxTargetDistance : sphereOfInfluence * 2f; RFV._isPrimaryVolume = true; RFV._isCloseRangeVolume = false; diff --git a/NewHorizons/External/Modules/ReferenceFrameModule.cs b/NewHorizons/External/Modules/ReferenceFrameModule.cs index e9dc02a4..793bb5f0 100644 --- a/NewHorizons/External/Modules/ReferenceFrameModule.cs +++ b/NewHorizons/External/Modules/ReferenceFrameModule.cs @@ -24,5 +24,10 @@ namespace NewHorizons.External.Modules /// If it should be targetable even when super close. /// public bool targetWhenClose; + + /// + /// The maximum distance that the reference frame can be targeted from. Defaults to double the sphereOfInfluence. + /// + [DefaultValue(-1)] public float maxTargetDistance = -1; } } \ No newline at end of file diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index f5943fe5..3dfefb56 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -476,6 +476,12 @@ "targetWhenClose": { "type": "boolean", "description": "If it should be targetable even when super close." + }, + "maxTargetDistance": { + "type": "number", + "description": "The maximum distance that the reference frame can be targeted from. Defaults to double the sphereOfInfluence.", + "format": "float", + "default": -1 } } }, From 7188dd9d6a6d8b78f474a34918523eea00e2cf69 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 01:45:54 -0400 Subject: [PATCH 44/72] Log --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index dcca9126..a3059dc8 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -99,6 +99,8 @@ namespace NewHorizons.Builder.ShipLog { const float unviewedIconOffset = 15; + Logger.Log($"Adding ship log astro object for {body.Config.name}"); + GameObject unviewedReference = SearchUtilities.CachedFind(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/UnviewedIcon"); ShipLogAstroObject astroObject = gameObject.AddComponent(); From 883e5669f6d88996511232ccccafd90cbe86f969 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 02:39:45 -0400 Subject: [PATCH 45/72] Stop setting centerOfMass for kinematic rigidbody Setting it does nothing except spam the log. --- NewHorizons/Builder/General/RigidBodyBuilder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/Builder/General/RigidBodyBuilder.cs b/NewHorizons/Builder/General/RigidBodyBuilder.cs index a827cc2e..d016f469 100644 --- a/NewHorizons/Builder/General/RigidBodyBuilder.cs +++ b/NewHorizons/Builder/General/RigidBodyBuilder.cs @@ -19,7 +19,6 @@ namespace NewHorizons.Builder.General rigidBody.collisionDetectionMode = CollisionDetectionMode.Discrete; KinematicRigidbody kinematicRigidBody = body.AddComponent(); - kinematicRigidBody.centerOfMass = Vector3.zero; OWRigidbody owRigidBody = body.AddComponent(); owRigidBody._kinematicSimulation = true; From 9780163b8d80b70a8f2d4f6dc0659fd29a0eda3d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 02:46:21 -0400 Subject: [PATCH 46/72] Map Mode Focal Point --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index a3059dc8..16ca369b 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -237,6 +237,12 @@ namespace NewHorizons.Builder.ShipLog { GameObject newMapModeGO = CreateMapModeGameObject(body, transformParent, layer, body.Config.ShipLog?.mapMode?.manualPosition); ShipLogAstroObject newAstroObject = AddShipLogAstroObject(newMapModeGO, body, greyScaleMaterial, layer); + if (body.Config.FocalPoint != null) + { + newAstroObject._imageObj.GetComponent().enabled = false; + newAstroObject._outlineObj.GetComponent().enabled = false; + newAstroObject._unviewedObj.GetComponent().enabled = false; + } MakeDetails(body, newMapModeGO.transform, greyScaleMaterial); Vector2 navigationPosition = body.Config.ShipLog?.mapMode?.manualNavigationPosition; navMatrix[(int)navigationPosition.y][(int)navigationPosition.x] = newAstroObject; @@ -483,7 +489,7 @@ namespace NewHorizons.Builder.ShipLog GameObject newNodeGO = CreateMapModeGameObject(node.mainBody, parent, layer, position); ShipLogAstroObject astroObject = AddShipLogAstroObject(newNodeGO, node.mainBody, greyScaleMaterial, layer); if (node.mainBody.Config.FocalPoint != null) - { + { astroObject._imageObj.GetComponent().enabled = false; astroObject._outlineObj.GetComponent().enabled = false; astroObject._unviewedObj.GetComponent().enabled = false; From ba63099a72cbd53d25bc79f8e1c816de05d007d4 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 03:03:59 -0400 Subject: [PATCH 47/72] Fix focal point children not showing up --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 16ca369b..157ff721 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -388,7 +388,7 @@ namespace NewHorizons.Builder.ShipLog return new MapModeObject(); } - private static List ConstructChildrenNodes(MapModeObject parent, List searchList, string secondaryName = "") + private static List ConstructChildrenNodes(MapModeObject parent, List searchList, string secondaryName = "", string focalPointName = "") { List children = new List(); int newX = parent.x; @@ -396,7 +396,7 @@ namespace NewHorizons.Builder.ShipLog int newLevel = parent.level + 1; MapModeObject lastSibling = parent; - foreach (NewHorizonsBody body in searchList.Where(b => b.Config.Orbit.primaryBody == parent.mainBody.Config.name || b.Config.name == secondaryName)) + foreach (NewHorizonsBody body in searchList.Where(b => b.Config.Orbit.primaryBody == parent.mainBody.Config.name || (b.Config.Orbit.primaryBody == focalPointName && b.Config.name != parent.mainBody.Config.name) || b.Config.name == secondaryName)) { bool even = newLevel % 2 == 0; newX = even ? newX : newX + 1; @@ -411,13 +411,15 @@ namespace NewHorizons.Builder.ShipLog lastSibling = lastSibling }; string newSecondaryName = ""; + string newFocalPointName = ""; if (body.Config.FocalPoint != null) { + newFocalPointName = body.Config.name; newNode.mainBody = searchList.Find(b => b.Config.name == body.Config.FocalPoint.primary); newSecondaryName = searchList.Find(b => b.Config.name == body.Config.FocalPoint.secondary).Config.name; } - newNode.children = ConstructChildrenNodes(newNode, searchList, newSecondaryName); + newNode.children = ConstructChildrenNodes(newNode, searchList, newSecondaryName, newFocalPointName); if (even) { newY += newNode.branch_height; From 229844505565309223d9814817979d3106fd910e Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 03:46:30 -0400 Subject: [PATCH 48/72] Cloak Enter & Exit Events --- .../Components/CloakSectorController.cs | 32 +++++++++++ NewHorizons/Patches/HUDPatches.cs | 56 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 NewHorizons/Patches/HUDPatches.cs diff --git a/NewHorizons/Components/CloakSectorController.cs b/NewHorizons/Components/CloakSectorController.cs index 72a83aea..8d0ed0bb 100644 --- a/NewHorizons/Components/CloakSectorController.cs +++ b/NewHorizons/Components/CloakSectorController.cs @@ -20,9 +20,17 @@ namespace NewHorizons.Components // Lets just clear these off idc _cloak.OnPlayerEnter = new OWEvent(); _cloak.OnPlayerExit = new OWEvent(); + _cloak.OnProbeEnter = new OWEvent(); + _cloak.OnProbeExit = new OWEvent(); + _cloak.OnShipEnter = new OWEvent(); + _cloak.OnShipExit = new OWEvent(); _cloak.OnPlayerEnter += OnPlayerEnter; _cloak.OnPlayerExit += OnPlayerExit; + _cloak.OnProbeEnter += OnProbeEnter; + _cloak.OnProbeExit += OnProbeExit; + _cloak.OnShipEnter += OnShipEnter; + _cloak.OnShipExit += OnShipExit; _isInitialized = true; } @@ -49,6 +57,8 @@ namespace NewHorizons.Components { renderer.forceRenderingOff = false; } + + GlobalMessenger.FireEvent("PlayerEnterCloakField"); } public void OnPlayerExit() @@ -59,6 +69,28 @@ namespace NewHorizons.Components { renderer.forceRenderingOff = true; } + + GlobalMessenger.FireEvent("PlayerExitCloakField"); + } + + public void OnProbeEnter() + { + GlobalMessenger.FireEvent("ProbeEnterCloakField"); + } + + public void OnProbeExit() + { + GlobalMessenger.FireEvent("ProbeExitCloakField"); + } + + public void OnShipEnter() + { + GlobalMessenger.FireEvent("ShipEnterCloakField"); + } + + public void OnShipExit() + { + GlobalMessenger.FireEvent("ShipExitCloakField"); } public void EnableCloak() diff --git a/NewHorizons/Patches/HUDPatches.cs b/NewHorizons/Patches/HUDPatches.cs new file mode 100644 index 00000000..4ef50dd8 --- /dev/null +++ b/NewHorizons/Patches/HUDPatches.cs @@ -0,0 +1,56 @@ +using HarmonyLib; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public static class HUDPatches + { + [HarmonyPostfix] + [HarmonyPatch(typeof(HUDMarker), nameof(HUDMarker.Awake))] + public static void HUDMarker_Awake(HUDMarker __instance) + { + GlobalMessenger.AddListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); + GlobalMessenger.AddListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(HUDMarker), nameof(HUDMarker.OnDestroy))] + public static void HUDMarker_OnDestroy(HUDMarker __instance) + { + GlobalMessenger.RemoveListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); + GlobalMessenger.RemoveListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(ProbeHUDMarker), nameof(ProbeHUDMarker.Awake))] + public static void ProbeHUDMarker_Awake(ProbeHUDMarker __instance) + { + GlobalMessenger.AddListener("ProbeEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.AddListener("ProbeExitCloakField", __instance.RefreshOwnVisibility); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(ProbeHUDMarker), nameof(ProbeHUDMarker.OnDestroy))] + public static void ProbeHUDMarker_OnDestroy(ProbeHUDMarker __instance) + { + GlobalMessenger.RemoveListener("ProbeEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.RemoveListener("ProbeExitCloakField", __instance.RefreshOwnVisibility); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(ShipHUDMarker), nameof(ShipHUDMarker.Awake))] + public static void ShipHUDMarker_Awake(ShipHUDMarker __instance) + { + GlobalMessenger.AddListener("ShipEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.AddListener("ShipExitCloakField", __instance.RefreshOwnVisibility); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(ShipHUDMarker), nameof(ShipHUDMarker.OnDestroy))] + public static void ShipHUDMarker_OnDestroy(ShipHUDMarker __instance) + { + GlobalMessenger.RemoveListener("ShipEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.RemoveListener("ShipExitCloakField", __instance.RefreshOwnVisibility); + } + } +} From 2a74e783e1325c3db344b5f880c10ef436b7c486 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 04:04:55 -0400 Subject: [PATCH 49/72] Probe Interference --- NewHorizons/Components/CloakSectorController.cs | 10 ++++++++++ NewHorizons/Patches/HUDPatches.cs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/NewHorizons/Components/CloakSectorController.cs b/NewHorizons/Components/CloakSectorController.cs index 8d0ed0bb..e7d8e9b0 100644 --- a/NewHorizons/Components/CloakSectorController.cs +++ b/NewHorizons/Components/CloakSectorController.cs @@ -12,6 +12,10 @@ namespace NewHorizons.Components private List _renderers = null; + internal static bool isPlayerInside = false; + internal static bool isProbeInside = false; + internal static bool isShipInside = false; + public void Init(CloakFieldController cloak, GameObject root) { _cloak = cloak; @@ -58,6 +62,7 @@ namespace NewHorizons.Components renderer.forceRenderingOff = false; } + isPlayerInside = true; GlobalMessenger.FireEvent("PlayerEnterCloakField"); } @@ -70,26 +75,31 @@ namespace NewHorizons.Components renderer.forceRenderingOff = true; } + isPlayerInside = false; GlobalMessenger.FireEvent("PlayerExitCloakField"); } public void OnProbeEnter() { + isProbeInside = true; GlobalMessenger.FireEvent("ProbeEnterCloakField"); } public void OnProbeExit() { + isProbeInside = false; GlobalMessenger.FireEvent("ProbeExitCloakField"); } public void OnShipEnter() { + isShipInside = true; GlobalMessenger.FireEvent("ShipEnterCloakField"); } public void OnShipExit() { + isShipInside = false; GlobalMessenger.FireEvent("ShipExitCloakField"); } diff --git a/NewHorizons/Patches/HUDPatches.cs b/NewHorizons/Patches/HUDPatches.cs index 4ef50dd8..bbb0061a 100644 --- a/NewHorizons/Patches/HUDPatches.cs +++ b/NewHorizons/Patches/HUDPatches.cs @@ -52,5 +52,12 @@ namespace NewHorizons.Patches GlobalMessenger.RemoveListener("ShipEnterCloakField", __instance.RefreshOwnVisibility); GlobalMessenger.RemoveListener("ShipExitCloakField", __instance.RefreshOwnVisibility); } + + [HarmonyPostfix] + [HarmonyPatch(typeof(ProbeCamera), nameof(ProbeCamera.HasInterference))] + public static void ProbeCamera_HasInterference(ProbeCamera __instance, ref bool __result) + { + __result = __result || Components.CloakSectorController.isPlayerInside != Components.CloakSectorController.isProbeInside; + } } } From ef262b456d5c77cad79817320b503ed46fb43311 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 Jun 2022 04:50:33 -0400 Subject: [PATCH 50/72] Cloak Inside Patch --- NewHorizons/Main.cs | 5 ++++- NewHorizons/Patches/LocatorPatches.cs | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index f4c9ad09..814ab525 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -116,7 +116,10 @@ namespace NewHorizons public void Start() { // Patches - Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); + Harmony harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); + harmony.Patch(typeof(CloakFieldController).GetMethod("get_" + nameof(CloakFieldController.isPlayerInsideCloak), BindingFlags.Public | BindingFlags.Instance), postfix: new HarmonyMethod(typeof(Patches.LocatorPatches).GetMethod(nameof(Patches.LocatorPatches.CloakFieldController_isPlayerInsideCloak), BindingFlags.Static | BindingFlags.Public))); + harmony.Patch(typeof(CloakFieldController).GetMethod("get_" + nameof(CloakFieldController.isProbeInsideCloak), BindingFlags.Public | BindingFlags.Instance), postfix: new HarmonyMethod(typeof(Patches.LocatorPatches).GetMethod(nameof(Patches.LocatorPatches.CloakFieldController_isProbeInsideCloak), BindingFlags.Static | BindingFlags.Public))); + harmony.Patch(typeof(CloakFieldController).GetMethod("get_" + nameof(CloakFieldController.isShipInsideCloak), BindingFlags.Public | BindingFlags.Instance), postfix: new HarmonyMethod(typeof(Patches.LocatorPatches).GetMethod(nameof(Patches.LocatorPatches.CloakFieldController_isShipInsideCloak), BindingFlags.Static | BindingFlags.Public))); OnChangeStarSystem = new StarSystemEvent(); OnStarSystemLoaded = new StarSystemEvent(); diff --git a/NewHorizons/Patches/LocatorPatches.cs b/NewHorizons/Patches/LocatorPatches.cs index eb933baf..e826ba06 100644 --- a/NewHorizons/Patches/LocatorPatches.cs +++ b/NewHorizons/Patches/LocatorPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; namespace NewHorizons.Patches { [HarmonyPatch] @@ -10,5 +10,20 @@ namespace NewHorizons.Patches { return Locator._cloakFieldController == null; } + + public static void CloakFieldController_isPlayerInsideCloak(CloakFieldController __instance, ref bool __result) + { + __result = __result || Components.CloakSectorController.isPlayerInside; + } + + public static void CloakFieldController_isProbeInsideCloak(CloakFieldController __instance, ref bool __result) + { + __result = __result || Components.CloakSectorController.isProbeInside; + } + + public static void CloakFieldController_isShipInsideCloak(CloakFieldController __instance, ref bool __result) + { + __result = __result || Components.CloakSectorController.isShipInside; + } } } From 90f65ee5b94f56d523ed2b40e3c214b7fc93363f Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 6 Jun 2022 09:54:52 -0400 Subject: [PATCH 51/72] Modified bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index acf37283..249ac6bb 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -26,7 +26,7 @@ body: - Epic Games - Xbox Game Pass validations: - required: true + required: false - type: textarea id: mods attributes: @@ -34,7 +34,7 @@ body: description: Please define which mods you had enabled when the problem occurred. render: Markdown validations: - required: true + required: false - type: textarea id: logs attributes: From e620f1a093a866a23c814e017c3278617f814447 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 6 Jun 2022 16:05:34 +0000 Subject: [PATCH 52/72] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 96 +++++++++++++++------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 3dfefb56..ce1071f5 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -75,6 +75,10 @@ "description": "Spawn various objects on this body", "$ref": "#/definitions/PropModule" }, + "ReferenceFrame": { + "description": "Reference frame properties of this body", + "$ref": "#/definitions/ReferenceFrameModule" + }, "removeChildren": { "type": "array", "description": "A list of paths to child GameObjects to destroy on this planet", @@ -289,25 +293,6 @@ } } }, - "CloakModule": { - "type": "object", - "additionalProperties": false, - "properties": { - "radius": { - "type": "number", - "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", - "format": "float" - }, - "audioClip": { - "type": "string", - "description": "Name of an existing AudioClip in the game that will play when entering the cloaking field." - }, - "audioFilePath": { - "type": "string", - "description": "Relative filepath to the .wav file to use as the audio. Mutually exclusive with audioClip." - } - } - }, "CloudInfo": { "type": "object", "additionalProperties": false, @@ -454,37 +439,11 @@ }, "zeroGravityRadius": { "type": "number", - "description": "Radius of the zero gravity sphere. This sphere will make gravity no longer affect you while you are inside it. Useful for satellites.", + "description": "Radius of the zero gravity volume. This will make it so no gravity from any planet will affect you. Useful for satellites.", "format": "float" } } }, - "ReferenceFrameModule": { - "type": "object", - "additionalProperties": false, - "properties": { - "hideInMap": { - "type": "boolean", - "description": "Stop the object from being targeted on the map." - }, - "bracketRadius": { - "type": "number", - "description": "Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence.", - "format": "float", - "default": -1 - }, - "targetWhenClose": { - "type": "boolean", - "description": "If it should be targetable even when super close." - }, - "maxTargetDistance": { - "type": "number", - "description": "The maximum distance that the reference frame can be targeted from. Defaults to double the sphereOfInfluence.", - "format": "float", - "default": -1 - } - } - }, "MVector3": { "type": "object", "additionalProperties": false, @@ -515,6 +474,25 @@ "inverseSquared" ] }, + "CloakModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "radius": { + "type": "number", + "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", + "format": "float" + }, + "audioClip": { + "type": "string", + "description": "Name of an existing AudioClip in the game that will play when entering the cloaking field." + }, + "audioFilePath": { + "type": "string", + "description": "Relative filepath to the .wav file to use as the audio. Mutually exclusive with audioClip." + } + } + }, "FocalPointModule": { "type": "object", "additionalProperties": false, @@ -1349,6 +1327,32 @@ } } }, + "ReferenceFrameModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "hideInMap": { + "type": "boolean", + "description": "Stop the object from being targeted on the map." + }, + "bracketRadius": { + "type": "number", + "description": "Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence.", + "format": "float", + "default": -1 + }, + "targetWhenClose": { + "type": "boolean", + "description": "If it should be targetable even when super close." + }, + "maxTargetDistance": { + "type": "number", + "description": "The maximum distance that the reference frame can be targeted from. Defaults to double the sphereOfInfluence.", + "format": "float", + "default": -1 + } + } + }, "RingModule": { "type": "object", "additionalProperties": false, From c02d43371bcd3bace12354be53df23ddc5ac9b59 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 6 Jun 2022 12:25:10 -0400 Subject: [PATCH 53/72] Tidied CloudsBuilder.cs --- .../Builder/Atmosphere/CloudsBuilder.cs | 407 +++++++++--------- 1 file changed, 207 insertions(+), 200 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 82900a6b..656edac1 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -1,224 +1,231 @@ +#region + +using System; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; -using System; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Builder.Atmosphere + +#endregion + +namespace NewHorizons.Builder.Atmosphere; + +public static class CloudsBuilder { - public static class CloudsBuilder + private static Shader _sphereShader; + private static Material[] _gdCloudMaterials; + private static GameObject _lightningPrefab; + private static Texture2D _colorRamp; + private static readonly int Color1 = Shader.PropertyToID("_Color"); + private static readonly int TintColor = Shader.PropertyToID("_TintColor"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int RampTex = Shader.PropertyToID("_RampTex"); + private static readonly int CapTex = Shader.PropertyToID("_CapTex"); + private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); + + public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) { - private static Shader _sphereShader = null; - private static Material[] _gdCloudMaterials; - private static GameObject _lightningPrefab; - private static Texture2D _colorRamp; - private static readonly int Color1 = Shader.PropertyToID("_Color"); - private static readonly int TintColor = Shader.PropertyToID("_TintColor"); - private static readonly int MainTex = Shader.PropertyToID("_MainTex"); - private static readonly int RampTex = Shader.PropertyToID("_RampTex"); - private static readonly int CapTex = Shader.PropertyToID("_CapTex"); - private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); + if (_lightningPrefab == null) + _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); + if (_colorRamp == null) + _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); - public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) + var cloudsMainGO = new GameObject("Clouds"); + cloudsMainGO.SetActive(false); + cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; + + MakeTopClouds(cloudsMainGO, atmo, mod); + + var cloudsBottomGO = new GameObject("BottomClouds"); + cloudsBottomGO.SetActive(false); + cloudsBottomGO.transform.parent = cloudsMainGO.transform; + cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; + + var bottomTSR = cloudsBottomGO.AddComponent(); + bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM") + .GetComponent().tessellationMeshGroup; + var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent() + .sharedMaterials; + + // If they set a colour apply it to all the materials else keep the default QM one + if (atmo.clouds.tint != null) { - if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); - if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); + var bottomColor = atmo.clouds.tint.ToColor(); - GameObject cloudsMainGO = new GameObject("Clouds"); - cloudsMainGO.SetActive(false); - cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; + var bottomTSRTempArray = new Material[2]; - MakeTopClouds(cloudsMainGO, atmo, mod); + bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); + bottomTSRTempArray[0].SetColor(Color1, bottomColor); + bottomTSRTempArray[0].SetColor(TintColor, bottomColor); + bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); - GameObject cloudsBottomGO = new GameObject("BottomClouds"); - cloudsBottomGO.SetActive(false); - cloudsBottomGO.transform.parent = cloudsMainGO.transform; - cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; + bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); - TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); - bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; - var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; + bottomTSR.sharedMaterials = bottomTSRTempArray; + } + else + { + bottomTSR.sharedMaterials = bottomTSRMaterials; + } - // If they set a colour apply it to all the materials else keep the default QM one - if (atmo.clouds.tint != null) + bottomTSR.maxLOD = 6; + bottomTSR.LODBias = 0; + bottomTSR.LODRadius = 1f; + + var bottomTSST = cloudsBottomGO.AddComponent(); + bottomTSST._sector = sector; + + var cloudsFluidGO = new GameObject("CloudsFluid"); + cloudsFluidGO.SetActive(false); + cloudsFluidGO.layer = 17; + cloudsFluidGO.transform.parent = cloudsMainGO.transform; + + var fluidSC = cloudsFluidGO.AddComponent(); + fluidSC.isTrigger = true; + fluidSC.radius = atmo.size; + + var fluidOWSC = cloudsFluidGO.AddComponent(); + fluidOWSC._innerRadius = atmo.size * 0.9f; + + var fluidCLFV = cloudsFluidGO.AddComponent(); + fluidCLFV._layer = 5; + fluidCLFV._priority = 1; + fluidCLFV._density = 1.2f; + + var fluidType = FluidVolume.Type.CLOUD; + + try + { + fluidType = (FluidVolume.Type) Enum.Parse(typeof(FluidVolume.Type), + Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); + } + catch (Exception ex) + { + Logger.LogError( + $"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); + } + + fluidCLFV._fluidType = fluidType; + fluidCLFV._allowShipAutoroll = true; + fluidCLFV._disableOnStart = false; + + // Fix the rotations once the rest is done + cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); + // For the base shader it has to be rotated idk + if (atmo.clouds.useBasicCloudShader) + cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + + // Lightning + if (atmo.clouds.hasLightning) + { + var lightning = _lightningPrefab.InstantiateInactive(); + lightning.transform.parent = cloudsMainGO.transform; + lightning.transform.localPosition = Vector3.zero; + + var lightningGenerator = lightning.GetComponent(); + lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; + lightningGenerator._audioSector = sector; + if (atmo.clouds.lightningGradient != null) { - var bottomColor = atmo.clouds.tint.ToColor(); + var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; - var bottomTSRTempArray = new Material[2]; - - bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); - bottomTSRTempArray[0].SetColor(Color1, bottomColor); - bottomTSRTempArray[0].SetColor(TintColor, bottomColor); - bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); - - bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); - - bottomTSR.sharedMaterials = bottomTSRTempArray; - } - else - { - bottomTSR.sharedMaterials = bottomTSRMaterials; - } - - bottomTSR.maxLOD = 6; - bottomTSR.LODBias = 0; - bottomTSR.LODRadius = 1f; - - TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); - bottomTSST._sector = sector; - - GameObject cloudsFluidGO = new GameObject("CloudsFluid"); - cloudsFluidGO.SetActive(false); - cloudsFluidGO.layer = 17; - cloudsFluidGO.transform.parent = cloudsMainGO.transform; - - SphereCollider fluidSC = cloudsFluidGO.AddComponent(); - fluidSC.isTrigger = true; - fluidSC.radius = atmo.size; - - OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); - fluidOWSC._innerRadius = atmo.size * 0.9f; - - CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); - fluidCLFV._layer = 5; - fluidCLFV._priority = 1; - fluidCLFV._density = 1.2f; - - var fluidType = FluidVolume.Type.CLOUD; - - try - { - fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); - } - catch (Exception ex) - { - Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); - } - - fluidCLFV._fluidType = fluidType; - fluidCLFV._allowShipAutoroll = true; - fluidCLFV._disableOnStart = false; - - // Fix the rotations once the rest is done - cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); - // For the base shader it has to be rotated idk - if (atmo.clouds.useBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - - // Lightning - if (atmo.clouds.hasLightning) - { - var lightning = _lightningPrefab.InstantiateInactive(); - lightning.transform.parent = cloudsMainGO.transform; - lightning.transform.localPosition = Vector3.zero; - - var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; - lightningGenerator._audioSector = sector; - if (atmo.clouds.lightningGradient != null) + for (var i = 0; i < atmo.clouds.lightningGradient.Length; i++) { - var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; - - for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) - { - var pair = atmo.clouds.lightningGradient[i]; - gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); - } - - lightningGenerator._lightColor.colorKeys = gradient; + var pair = atmo.clouds.lightningGradient[i]; + gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); } - lightning.SetActive(true); + + lightningGenerator._lightColor.colorKeys = gradient; } - cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - - cloudsBottomGO.SetActive(true); - cloudsFluidGO.SetActive(true); - cloudsMainGO.SetActive(true); + lightning.SetActive(true); } - public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) - { - Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; + cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - Texture2D image, cap, ramp; - - try - { - image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); - - if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); - else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); - if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); - else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); - } - catch (Exception e) - { - Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); - return null; - } - - GameObject cloudsTopGO = new GameObject("TopClouds"); - cloudsTopGO.SetActive(false); - cloudsTopGO.transform.parent = rootObject.transform; - cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; - - MeshFilter topMF = cloudsTopGO.AddComponent(); - topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; - - MeshRenderer topMR = cloudsTopGO.AddComponent(); - - if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); - if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; - var tempArray = new Material[2]; - - if (atmo.clouds.useBasicCloudShader) - { - var material = new Material(_sphereShader); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; - - tempArray[0] = material; - } - else - { - var material = new Material(_gdCloudMaterials[0]); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; - tempArray[0] = material; - } - - // This is the stencil material for the fog under the clouds - tempArray[1] = new Material(_gdCloudMaterials[1]); - topMR.sharedMaterials = tempArray; - - foreach (var material in topMR.sharedMaterials) - { - material.SetColor(Color1, cloudTint); - material.SetColor(TintColor, cloudTint); - - material.SetTexture(MainTex, image); - material.SetTexture(RampTex, ramp); - material.SetTexture(CapTex, cap); - } - - if (atmo.clouds.unlit) - { - cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); - } - - RotateTransform topRT = cloudsTopGO.AddComponent(); - // Idk why but the axis is weird - topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; - topRT._degreesPerSecond = 10; - topRT._randomizeRotationRate = false; - - cloudsTopGO.transform.localPosition = Vector3.zero; - - cloudsTopGO.SetActive(true); - - return cloudsTopGO; - } + cloudsBottomGO.SetActive(true); + cloudsFluidGO.SetActive(true); + cloudsMainGO.SetActive(true); } -} + + public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) + { + var cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; + + Texture2D image, cap, ramp; + + try + { + image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); + + cap = atmo.clouds.capPath == null ? ImageUtilities.ClearTexture(128, 128) : ImageUtilities.GetTexture(mod, atmo.clouds.capPath); + ramp = atmo.clouds.rampPath == null ? ImageUtilities.CanvasScaled(image, 1, image.height) : ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); + } + catch (Exception e) + { + Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); + return null; + } + + var cloudsTopGO = new GameObject("TopClouds"); + cloudsTopGO.SetActive(false); + cloudsTopGO.transform.parent = rootObject.transform; + cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; + + var topMF = cloudsTopGO.AddComponent(); + topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; + + var topMR = cloudsTopGO.AddComponent(); + + _sphereShader ??= Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); + _gdCloudMaterials ??= SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; + var tempArray = new Material[2]; + + if (atmo.clouds.useBasicCloudShader) + { + var material = new Material(_sphereShader); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; + + tempArray[0] = material; + } + else + { + var material = new Material(_gdCloudMaterials[0]); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; + tempArray[0] = material; + } + + // This is the stencil material for the fog under the clouds + tempArray[1] = new Material(_gdCloudMaterials[1]); + topMR.sharedMaterials = tempArray; + + foreach (var material in topMR.sharedMaterials) + { + material.SetColor(Color1, cloudTint); + material.SetColor(TintColor, cloudTint); + + material.SetTexture(MainTex, image); + material.SetTexture(RampTex, ramp); + material.SetTexture(CapTex, cap); + } + + if (atmo.clouds.unlit) cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); + + var topRT = cloudsTopGO.AddComponent(); + // Idk why but the axis is weird + topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; + topRT._degreesPerSecond = 10; + topRT._randomizeRotationRate = false; + + cloudsTopGO.transform.localPosition = Vector3.zero; + + cloudsTopGO.SetActive(true); + + return cloudsTopGO; + } +} \ No newline at end of file From 9dd45a1f3eb47e71e0eb65d8f278c12e228dce19 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 6 Jun 2022 12:26:02 -0400 Subject: [PATCH 54/72] Remove #region in CloudsBuilder.cs --- NewHorizons/Builder/Atmosphere/CloudsBuilder.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 656edac1..86b30854 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -1,5 +1,3 @@ -#region - using System; using NewHorizons.External.Modules; using NewHorizons.Utility; @@ -7,8 +5,6 @@ using OWML.Common; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -#endregion - namespace NewHorizons.Builder.Atmosphere; public static class CloudsBuilder From 740bba9879f7a190613a7ec3e9e1e8fdc5510fa0 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 6 Jun 2022 09:57:49 -0700 Subject: [PATCH 55/72] Revert "Remove #region in CloudsBuilder.cs" This reverts commit 9dd45a1f3eb47e71e0eb65d8f278c12e228dce19. --- NewHorizons/Builder/Atmosphere/CloudsBuilder.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 86b30854..656edac1 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -1,3 +1,5 @@ +#region + using System; using NewHorizons.External.Modules; using NewHorizons.Utility; @@ -5,6 +7,8 @@ using OWML.Common; using UnityEngine; using Logger = NewHorizons.Utility.Logger; +#endregion + namespace NewHorizons.Builder.Atmosphere; public static class CloudsBuilder From e514a52f2fbc0c761874c41c694fd4e9a93e2a7b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 6 Jun 2022 09:57:50 -0700 Subject: [PATCH 56/72] Revert "Tidied CloudsBuilder.cs" This reverts commit c02d43371bcd3bace12354be53df23ddc5ac9b59. --- .../Builder/Atmosphere/CloudsBuilder.cs | 409 +++++++++--------- 1 file changed, 201 insertions(+), 208 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 656edac1..82900a6b 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -1,231 +1,224 @@ -#region - -using System; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; +using System; using UnityEngine; using Logger = NewHorizons.Utility.Logger; - -#endregion - -namespace NewHorizons.Builder.Atmosphere; - -public static class CloudsBuilder +namespace NewHorizons.Builder.Atmosphere { - private static Shader _sphereShader; - private static Material[] _gdCloudMaterials; - private static GameObject _lightningPrefab; - private static Texture2D _colorRamp; - private static readonly int Color1 = Shader.PropertyToID("_Color"); - private static readonly int TintColor = Shader.PropertyToID("_TintColor"); - private static readonly int MainTex = Shader.PropertyToID("_MainTex"); - private static readonly int RampTex = Shader.PropertyToID("_RampTex"); - private static readonly int CapTex = Shader.PropertyToID("_CapTex"); - private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); - - public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) + public static class CloudsBuilder { - if (_lightningPrefab == null) - _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); - if (_colorRamp == null) - _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); + private static Shader _sphereShader = null; + private static Material[] _gdCloudMaterials; + private static GameObject _lightningPrefab; + private static Texture2D _colorRamp; + private static readonly int Color1 = Shader.PropertyToID("_Color"); + private static readonly int TintColor = Shader.PropertyToID("_TintColor"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int RampTex = Shader.PropertyToID("_RampTex"); + private static readonly int CapTex = Shader.PropertyToID("_CapTex"); + private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); - var cloudsMainGO = new GameObject("Clouds"); - cloudsMainGO.SetActive(false); - cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; - - MakeTopClouds(cloudsMainGO, atmo, mod); - - var cloudsBottomGO = new GameObject("BottomClouds"); - cloudsBottomGO.SetActive(false); - cloudsBottomGO.transform.parent = cloudsMainGO.transform; - cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; - - var bottomTSR = cloudsBottomGO.AddComponent(); - bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM") - .GetComponent().tessellationMeshGroup; - var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent() - .sharedMaterials; - - // If they set a colour apply it to all the materials else keep the default QM one - if (atmo.clouds.tint != null) + public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) { - var bottomColor = atmo.clouds.tint.ToColor(); + if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); + if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); - var bottomTSRTempArray = new Material[2]; + GameObject cloudsMainGO = new GameObject("Clouds"); + cloudsMainGO.SetActive(false); + cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; - bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); - bottomTSRTempArray[0].SetColor(Color1, bottomColor); - bottomTSRTempArray[0].SetColor(TintColor, bottomColor); - bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); + MakeTopClouds(cloudsMainGO, atmo, mod); - bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); + GameObject cloudsBottomGO = new GameObject("BottomClouds"); + cloudsBottomGO.SetActive(false); + cloudsBottomGO.transform.parent = cloudsMainGO.transform; + cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; - bottomTSR.sharedMaterials = bottomTSRTempArray; - } - else - { - bottomTSR.sharedMaterials = bottomTSRMaterials; - } + TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); + bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; + var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; - bottomTSR.maxLOD = 6; - bottomTSR.LODBias = 0; - bottomTSR.LODRadius = 1f; - - var bottomTSST = cloudsBottomGO.AddComponent(); - bottomTSST._sector = sector; - - var cloudsFluidGO = new GameObject("CloudsFluid"); - cloudsFluidGO.SetActive(false); - cloudsFluidGO.layer = 17; - cloudsFluidGO.transform.parent = cloudsMainGO.transform; - - var fluidSC = cloudsFluidGO.AddComponent(); - fluidSC.isTrigger = true; - fluidSC.radius = atmo.size; - - var fluidOWSC = cloudsFluidGO.AddComponent(); - fluidOWSC._innerRadius = atmo.size * 0.9f; - - var fluidCLFV = cloudsFluidGO.AddComponent(); - fluidCLFV._layer = 5; - fluidCLFV._priority = 1; - fluidCLFV._density = 1.2f; - - var fluidType = FluidVolume.Type.CLOUD; - - try - { - fluidType = (FluidVolume.Type) Enum.Parse(typeof(FluidVolume.Type), - Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); - } - catch (Exception ex) - { - Logger.LogError( - $"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); - } - - fluidCLFV._fluidType = fluidType; - fluidCLFV._allowShipAutoroll = true; - fluidCLFV._disableOnStart = false; - - // Fix the rotations once the rest is done - cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); - // For the base shader it has to be rotated idk - if (atmo.clouds.useBasicCloudShader) - cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - - // Lightning - if (atmo.clouds.hasLightning) - { - var lightning = _lightningPrefab.InstantiateInactive(); - lightning.transform.parent = cloudsMainGO.transform; - lightning.transform.localPosition = Vector3.zero; - - var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; - lightningGenerator._audioSector = sector; - if (atmo.clouds.lightningGradient != null) + // If they set a colour apply it to all the materials else keep the default QM one + if (atmo.clouds.tint != null) { - var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; + var bottomColor = atmo.clouds.tint.ToColor(); - for (var i = 0; i < atmo.clouds.lightningGradient.Length; i++) - { - var pair = atmo.clouds.lightningGradient[i]; - gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); - } + var bottomTSRTempArray = new Material[2]; - lightningGenerator._lightColor.colorKeys = gradient; + bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); + bottomTSRTempArray[0].SetColor(Color1, bottomColor); + bottomTSRTempArray[0].SetColor(TintColor, bottomColor); + bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); + + bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); + + bottomTSR.sharedMaterials = bottomTSRTempArray; + } + else + { + bottomTSR.sharedMaterials = bottomTSRMaterials; } - lightning.SetActive(true); + bottomTSR.maxLOD = 6; + bottomTSR.LODBias = 0; + bottomTSR.LODRadius = 1f; + + TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); + bottomTSST._sector = sector; + + GameObject cloudsFluidGO = new GameObject("CloudsFluid"); + cloudsFluidGO.SetActive(false); + cloudsFluidGO.layer = 17; + cloudsFluidGO.transform.parent = cloudsMainGO.transform; + + SphereCollider fluidSC = cloudsFluidGO.AddComponent(); + fluidSC.isTrigger = true; + fluidSC.radius = atmo.size; + + OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); + fluidOWSC._innerRadius = atmo.size * 0.9f; + + CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); + fluidCLFV._layer = 5; + fluidCLFV._priority = 1; + fluidCLFV._density = 1.2f; + + var fluidType = FluidVolume.Type.CLOUD; + + try + { + fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); + } + + fluidCLFV._fluidType = fluidType; + fluidCLFV._allowShipAutoroll = true; + fluidCLFV._disableOnStart = false; + + // Fix the rotations once the rest is done + cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); + // For the base shader it has to be rotated idk + if (atmo.clouds.useBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + + // Lightning + if (atmo.clouds.hasLightning) + { + var lightning = _lightningPrefab.InstantiateInactive(); + lightning.transform.parent = cloudsMainGO.transform; + lightning.transform.localPosition = Vector3.zero; + + var lightningGenerator = lightning.GetComponent(); + lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; + lightningGenerator._audioSector = sector; + if (atmo.clouds.lightningGradient != null) + { + var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; + + for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) + { + var pair = atmo.clouds.lightningGradient[i]; + gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); + } + + lightningGenerator._lightColor.colorKeys = gradient; + } + lightning.SetActive(true); + } + + cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + + cloudsBottomGO.SetActive(true); + cloudsFluidGO.SetActive(true); + cloudsMainGO.SetActive(true); } - cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) + { + Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; - cloudsBottomGO.SetActive(true); - cloudsFluidGO.SetActive(true); - cloudsMainGO.SetActive(true); + Texture2D image, cap, ramp; + + try + { + image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); + + if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); + else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); + if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); + else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); + } + catch (Exception e) + { + Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); + return null; + } + + GameObject cloudsTopGO = new GameObject("TopClouds"); + cloudsTopGO.SetActive(false); + cloudsTopGO.transform.parent = rootObject.transform; + cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; + + MeshFilter topMF = cloudsTopGO.AddComponent(); + topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; + + MeshRenderer topMR = cloudsTopGO.AddComponent(); + + if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); + if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; + var tempArray = new Material[2]; + + if (atmo.clouds.useBasicCloudShader) + { + var material = new Material(_sphereShader); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; + + tempArray[0] = material; + } + else + { + var material = new Material(_gdCloudMaterials[0]); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; + tempArray[0] = material; + } + + // This is the stencil material for the fog under the clouds + tempArray[1] = new Material(_gdCloudMaterials[1]); + topMR.sharedMaterials = tempArray; + + foreach (var material in topMR.sharedMaterials) + { + material.SetColor(Color1, cloudTint); + material.SetColor(TintColor, cloudTint); + + material.SetTexture(MainTex, image); + material.SetTexture(RampTex, ramp); + material.SetTexture(CapTex, cap); + } + + if (atmo.clouds.unlit) + { + cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); + } + + RotateTransform topRT = cloudsTopGO.AddComponent(); + // Idk why but the axis is weird + topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; + topRT._degreesPerSecond = 10; + topRT._randomizeRotationRate = false; + + cloudsTopGO.transform.localPosition = Vector3.zero; + + cloudsTopGO.SetActive(true); + + return cloudsTopGO; + } } - - public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) - { - var cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; - - Texture2D image, cap, ramp; - - try - { - image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); - - cap = atmo.clouds.capPath == null ? ImageUtilities.ClearTexture(128, 128) : ImageUtilities.GetTexture(mod, atmo.clouds.capPath); - ramp = atmo.clouds.rampPath == null ? ImageUtilities.CanvasScaled(image, 1, image.height) : ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); - } - catch (Exception e) - { - Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); - return null; - } - - var cloudsTopGO = new GameObject("TopClouds"); - cloudsTopGO.SetActive(false); - cloudsTopGO.transform.parent = rootObject.transform; - cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; - - var topMF = cloudsTopGO.AddComponent(); - topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; - - var topMR = cloudsTopGO.AddComponent(); - - _sphereShader ??= Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); - _gdCloudMaterials ??= SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; - var tempArray = new Material[2]; - - if (atmo.clouds.useBasicCloudShader) - { - var material = new Material(_sphereShader); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; - - tempArray[0] = material; - } - else - { - var material = new Material(_gdCloudMaterials[0]); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; - tempArray[0] = material; - } - - // This is the stencil material for the fog under the clouds - tempArray[1] = new Material(_gdCloudMaterials[1]); - topMR.sharedMaterials = tempArray; - - foreach (var material in topMR.sharedMaterials) - { - material.SetColor(Color1, cloudTint); - material.SetColor(TintColor, cloudTint); - - material.SetTexture(MainTex, image); - material.SetTexture(RampTex, ramp); - material.SetTexture(CapTex, cap); - } - - if (atmo.clouds.unlit) cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); - - var topRT = cloudsTopGO.AddComponent(); - // Idk why but the axis is weird - topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; - topRT._degreesPerSecond = 10; - topRT._randomizeRotationRate = false; - - cloudsTopGO.transform.localPosition = Vector3.zero; - - cloudsTopGO.SetActive(true); - - return cloudsTopGO; - } -} \ No newline at end of file +} From 12700fc93205700c8eafdfb8c97e5ad3b7986b3a Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Mon, 6 Jun 2022 12:12:00 -0400 Subject: [PATCH 57/72] cherry picked commit that adds qm clouds as an option to base your planets clouds on, as opposed to the default of giants deep --- .../Builder/Atmosphere/CloudsBuilder.cs | 451 +++++++++--------- .../External/Modules/AtmosphereModule.cs | 15 +- 2 files changed, 241 insertions(+), 225 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 82900a6b..05e07ee8 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -1,224 +1,227 @@ -using NewHorizons.External.Modules; -using NewHorizons.Utility; -using OWML.Common; -using System; -using UnityEngine; -using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Builder.Atmosphere -{ - public static class CloudsBuilder - { - private static Shader _sphereShader = null; - private static Material[] _gdCloudMaterials; - private static GameObject _lightningPrefab; - private static Texture2D _colorRamp; - private static readonly int Color1 = Shader.PropertyToID("_Color"); - private static readonly int TintColor = Shader.PropertyToID("_TintColor"); - private static readonly int MainTex = Shader.PropertyToID("_MainTex"); - private static readonly int RampTex = Shader.PropertyToID("_RampTex"); - private static readonly int CapTex = Shader.PropertyToID("_CapTex"); - private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); - - public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) - { - if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); - if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); - - GameObject cloudsMainGO = new GameObject("Clouds"); - cloudsMainGO.SetActive(false); - cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; - - MakeTopClouds(cloudsMainGO, atmo, mod); - - GameObject cloudsBottomGO = new GameObject("BottomClouds"); - cloudsBottomGO.SetActive(false); - cloudsBottomGO.transform.parent = cloudsMainGO.transform; - cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; - - TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); - bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; - var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; - - // If they set a colour apply it to all the materials else keep the default QM one - if (atmo.clouds.tint != null) - { - var bottomColor = atmo.clouds.tint.ToColor(); - - var bottomTSRTempArray = new Material[2]; - - bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); - bottomTSRTempArray[0].SetColor(Color1, bottomColor); - bottomTSRTempArray[0].SetColor(TintColor, bottomColor); - bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); - - bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); - - bottomTSR.sharedMaterials = bottomTSRTempArray; - } - else - { - bottomTSR.sharedMaterials = bottomTSRMaterials; - } - - bottomTSR.maxLOD = 6; - bottomTSR.LODBias = 0; - bottomTSR.LODRadius = 1f; - - TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); - bottomTSST._sector = sector; - - GameObject cloudsFluidGO = new GameObject("CloudsFluid"); - cloudsFluidGO.SetActive(false); - cloudsFluidGO.layer = 17; - cloudsFluidGO.transform.parent = cloudsMainGO.transform; - - SphereCollider fluidSC = cloudsFluidGO.AddComponent(); - fluidSC.isTrigger = true; - fluidSC.radius = atmo.size; - - OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); - fluidOWSC._innerRadius = atmo.size * 0.9f; - - CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); - fluidCLFV._layer = 5; - fluidCLFV._priority = 1; - fluidCLFV._density = 1.2f; - - var fluidType = FluidVolume.Type.CLOUD; - - try - { - fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); - } - catch (Exception ex) - { - Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); - } - - fluidCLFV._fluidType = fluidType; - fluidCLFV._allowShipAutoroll = true; - fluidCLFV._disableOnStart = false; - - // Fix the rotations once the rest is done - cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); - // For the base shader it has to be rotated idk - if (atmo.clouds.useBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - - // Lightning - if (atmo.clouds.hasLightning) - { - var lightning = _lightningPrefab.InstantiateInactive(); - lightning.transform.parent = cloudsMainGO.transform; - lightning.transform.localPosition = Vector3.zero; - - var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; - lightningGenerator._audioSector = sector; - if (atmo.clouds.lightningGradient != null) - { - var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; - - for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) - { - var pair = atmo.clouds.lightningGradient[i]; - gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); - } - - lightningGenerator._lightColor.colorKeys = gradient; - } - lightning.SetActive(true); - } - - cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - - cloudsBottomGO.SetActive(true); - cloudsFluidGO.SetActive(true); - cloudsMainGO.SetActive(true); - } - - public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) - { - Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; - - Texture2D image, cap, ramp; - - try - { - image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); - - if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); - else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); - if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); - else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); - } - catch (Exception e) - { - Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); - return null; - } - - GameObject cloudsTopGO = new GameObject("TopClouds"); - cloudsTopGO.SetActive(false); - cloudsTopGO.transform.parent = rootObject.transform; - cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; - - MeshFilter topMF = cloudsTopGO.AddComponent(); - topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; - - MeshRenderer topMR = cloudsTopGO.AddComponent(); - - if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); - if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; - var tempArray = new Material[2]; - - if (atmo.clouds.useBasicCloudShader) - { - var material = new Material(_sphereShader); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; - - tempArray[0] = material; - } - else - { - var material = new Material(_gdCloudMaterials[0]); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; - tempArray[0] = material; - } - - // This is the stencil material for the fog under the clouds - tempArray[1] = new Material(_gdCloudMaterials[1]); - topMR.sharedMaterials = tempArray; - - foreach (var material in topMR.sharedMaterials) - { - material.SetColor(Color1, cloudTint); - material.SetColor(TintColor, cloudTint); - - material.SetTexture(MainTex, image); - material.SetTexture(RampTex, ramp); - material.SetTexture(CapTex, cap); - } - - if (atmo.clouds.unlit) - { - cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); - } - - RotateTransform topRT = cloudsTopGO.AddComponent(); - // Idk why but the axis is weird - topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; - topRT._degreesPerSecond = 10; - topRT._randomizeRotationRate = false; - - cloudsTopGO.transform.localPosition = Vector3.zero; - - cloudsTopGO.SetActive(true); - - return cloudsTopGO; - } - } -} +using NewHorizons.External.Modules; +using NewHorizons.Utility; +using OWML.Common; +using System; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; +namespace NewHorizons.Builder.Atmosphere +{ + public static class CloudsBuilder + { + private static Shader _sphereShader = null; + private static Material[] _gdCloudMaterials; + private static Material[] _qmCloudMaterials; + private static GameObject _lightningPrefab; + private static Texture2D _colorRamp; + private static readonly int Color1 = Shader.PropertyToID("_Color"); + private static readonly int TintColor = Shader.PropertyToID("_TintColor"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int RampTex = Shader.PropertyToID("_RampTex"); + private static readonly int CapTex = Shader.PropertyToID("_CapTex"); + private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); + + public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) + { + if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); + if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); + + GameObject cloudsMainGO = new GameObject("Clouds"); + cloudsMainGO.SetActive(false); + cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; + + MakeTopClouds(cloudsMainGO, atmo, mod); + + GameObject cloudsBottomGO = new GameObject("BottomClouds"); + cloudsBottomGO.SetActive(false); + cloudsBottomGO.transform.parent = cloudsMainGO.transform; + cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; + + TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); + bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; + var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; + + // If they set a colour apply it to all the materials else keep the default QM one + if (atmo.clouds.tint != null) + { + var bottomColor = atmo.clouds.tint.ToColor(); + + var bottomTSRTempArray = new Material[2]; + + bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); + bottomTSRTempArray[0].SetColor(Color1, bottomColor); + bottomTSRTempArray[0].SetColor(TintColor, bottomColor); + bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); + + bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); + + bottomTSR.sharedMaterials = bottomTSRTempArray; + } + else + { + bottomTSR.sharedMaterials = bottomTSRMaterials; + } + + bottomTSR.maxLOD = 6; + bottomTSR.LODBias = 0; + bottomTSR.LODRadius = 1f; + + TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); + bottomTSST._sector = sector; + + GameObject cloudsFluidGO = new GameObject("CloudsFluid"); + cloudsFluidGO.SetActive(false); + cloudsFluidGO.layer = 17; + cloudsFluidGO.transform.parent = cloudsMainGO.transform; + + SphereCollider fluidSC = cloudsFluidGO.AddComponent(); + fluidSC.isTrigger = true; + fluidSC.radius = atmo.size; + + OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); + fluidOWSC._innerRadius = atmo.size * 0.9f; + + CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); + fluidCLFV._layer = 5; + fluidCLFV._priority = 1; + fluidCLFV._density = 1.2f; + + var fluidType = FluidVolume.Type.CLOUD; + + try + { + fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); + } + + fluidCLFV._fluidType = fluidType; + fluidCLFV._allowShipAutoroll = true; + fluidCLFV._disableOnStart = false; + + // Fix the rotations once the rest is done + cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); + // For the base shader it has to be rotated idk + if (atmo.clouds.useBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + + // Lightning + if (atmo.clouds.hasLightning) + { + var lightning = _lightningPrefab.InstantiateInactive(); + lightning.transform.parent = cloudsMainGO.transform; + lightning.transform.localPosition = Vector3.zero; + + var lightningGenerator = lightning.GetComponent(); + lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; + lightningGenerator._audioSector = sector; + if (atmo.clouds.lightningGradient != null) + { + var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; + + for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) + { + var pair = atmo.clouds.lightningGradient[i]; + gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); + } + + lightningGenerator._lightColor.colorKeys = gradient; + } + lightning.SetActive(true); + } + + cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + + cloudsBottomGO.SetActive(true); + cloudsFluidGO.SetActive(true); + cloudsMainGO.SetActive(true); + } + + public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) + { + Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; + + Texture2D image, cap, ramp; + + try + { + image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); + + if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); + else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); + if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); + else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); + } + catch (Exception e) + { + Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); + return null; + } + + GameObject cloudsTopGO = new GameObject("TopClouds"); + cloudsTopGO.SetActive(false); + cloudsTopGO.transform.parent = rootObject.transform; + cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; + + MeshFilter topMF = cloudsTopGO.AddComponent(); + topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; + + MeshRenderer topMR = cloudsTopGO.AddComponent(); + + if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); + if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; + if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent().sharedMaterials; + Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials; + var tempArray = new Material[2]; + + if (atmo.clouds.useBasicCloudShader) + { + var material = new Material(_sphereShader); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; + + tempArray[0] = material; + } + else + { + var material = new Material(prefabMaterials[0]); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; + tempArray[0] = material; + } + + // This is the stencil material for the fog under the clouds + tempArray[1] = new Material(prefabMaterials[1]); + topMR.sharedMaterials = tempArray; + + foreach (var material in topMR.sharedMaterials) + { + material.SetColor(Color1, cloudTint); + material.SetColor(TintColor, cloudTint); + + material.SetTexture(MainTex, image); + material.SetTexture(RampTex, ramp); + material.SetTexture(CapTex, cap); + } + + if (atmo.clouds.unlit) + { + cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); + } + + RotateTransform topRT = cloudsTopGO.AddComponent(); + // Idk why but the axis is weird + topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; + topRT._degreesPerSecond = 10; + topRT._randomizeRotationRate = false; + + cloudsTopGO.transform.localPosition = Vector3.zero; + + cloudsTopGO.SetActive(true); + + return cloudsTopGO; + } + } +} diff --git a/NewHorizons/External/Modules/AtmosphereModule.cs b/NewHorizons/External/Modules/AtmosphereModule.cs index d58bbe61..e9be6bd6 100644 --- a/NewHorizons/External/Modules/AtmosphereModule.cs +++ b/NewHorizons/External/Modules/AtmosphereModule.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; @@ -20,6 +20,14 @@ namespace NewHorizons.External.Modules [EnumMember(Value = @"sand")] Sand = 3, [EnumMember(Value = @"plasma")] Plasma = 4 + } + + [JsonConverter(typeof(StringEnumConverter))] + public enum CloudPrefabType + { + [EnumMember(Value = @"giantsDeep")] GiantsDeep = 0, + + [EnumMember(Value = @"quantumMoon")] QuantumMoon = 1, } [JsonObject] @@ -88,6 +96,11 @@ namespace NewHorizons.External.Modules [JsonObject] public class CloudInfo { + /// + /// Should these clouds be based on Giant's Deep's banded clouds, or the Quantum Moon's non-banded clouds? + /// + public CloudPrefabType cloudsPrefab; + /// /// Relative filepath to the cloud cap texture, if the planet has clouds. /// From 51a607718070aaafc3bc89f65798035d62f1b4b0 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Mon, 6 Jun 2022 12:32:27 -0400 Subject: [PATCH 58/72] cherry picked commit that made useBasicShader obsolete --- .../Builder/Atmosphere/CloudsBuilder.cs | 432 +++++++++--------- NewHorizons/External/Configs/PlanetConfig.cs | 6 +- .../External/Modules/AtmosphereModule.cs | 12 +- 3 files changed, 232 insertions(+), 218 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 05e07ee8..c6594b48 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -1,227 +1,227 @@ -using NewHorizons.External.Modules; -using NewHorizons.Utility; -using OWML.Common; -using System; -using UnityEngine; -using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Builder.Atmosphere -{ - public static class CloudsBuilder - { - private static Shader _sphereShader = null; +using NewHorizons.External.Modules; +using NewHorizons.Utility; +using OWML.Common; +using System; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; +namespace NewHorizons.Builder.Atmosphere +{ + public static class CloudsBuilder + { + private static Shader _sphereShader = null; private static Material[] _gdCloudMaterials; private static Material[] _qmCloudMaterials; - private static GameObject _lightningPrefab; - private static Texture2D _colorRamp; - private static readonly int Color1 = Shader.PropertyToID("_Color"); - private static readonly int TintColor = Shader.PropertyToID("_TintColor"); - private static readonly int MainTex = Shader.PropertyToID("_MainTex"); - private static readonly int RampTex = Shader.PropertyToID("_RampTex"); - private static readonly int CapTex = Shader.PropertyToID("_CapTex"); - private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); - - public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) - { + private static GameObject _lightningPrefab; + private static Texture2D _colorRamp; + private static readonly int Color1 = Shader.PropertyToID("_Color"); + private static readonly int TintColor = Shader.PropertyToID("_TintColor"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int RampTex = Shader.PropertyToID("_RampTex"); + private static readonly int CapTex = Shader.PropertyToID("_CapTex"); + private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); + + public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) + { if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); - if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); - - GameObject cloudsMainGO = new GameObject("Clouds"); - cloudsMainGO.SetActive(false); - cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; - - MakeTopClouds(cloudsMainGO, atmo, mod); - - GameObject cloudsBottomGO = new GameObject("BottomClouds"); - cloudsBottomGO.SetActive(false); - cloudsBottomGO.transform.parent = cloudsMainGO.transform; - cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; - - TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); + if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); + + GameObject cloudsMainGO = new GameObject("Clouds"); + cloudsMainGO.SetActive(false); + cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; + + MakeTopClouds(cloudsMainGO, atmo, mod); + + GameObject cloudsBottomGO = new GameObject("BottomClouds"); + cloudsBottomGO.SetActive(false); + cloudsBottomGO.transform.parent = cloudsMainGO.transform; + cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; + + TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; - - // If they set a colour apply it to all the materials else keep the default QM one - if (atmo.clouds.tint != null) - { - var bottomColor = atmo.clouds.tint.ToColor(); - - var bottomTSRTempArray = new Material[2]; - - bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); - bottomTSRTempArray[0].SetColor(Color1, bottomColor); - bottomTSRTempArray[0].SetColor(TintColor, bottomColor); - bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); - - bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); - - bottomTSR.sharedMaterials = bottomTSRTempArray; - } - else - { - bottomTSR.sharedMaterials = bottomTSRMaterials; - } - - bottomTSR.maxLOD = 6; - bottomTSR.LODBias = 0; - bottomTSR.LODRadius = 1f; - - TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); - bottomTSST._sector = sector; - - GameObject cloudsFluidGO = new GameObject("CloudsFluid"); - cloudsFluidGO.SetActive(false); - cloudsFluidGO.layer = 17; - cloudsFluidGO.transform.parent = cloudsMainGO.transform; - - SphereCollider fluidSC = cloudsFluidGO.AddComponent(); - fluidSC.isTrigger = true; - fluidSC.radius = atmo.size; - - OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); - fluidOWSC._innerRadius = atmo.size * 0.9f; - - CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); - fluidCLFV._layer = 5; - fluidCLFV._priority = 1; - fluidCLFV._density = 1.2f; - - var fluidType = FluidVolume.Type.CLOUD; - - try - { - fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); - } - catch (Exception ex) - { - Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); - } - - fluidCLFV._fluidType = fluidType; - fluidCLFV._allowShipAutoroll = true; - fluidCLFV._disableOnStart = false; - - // Fix the rotations once the rest is done - cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); - // For the base shader it has to be rotated idk - if (atmo.clouds.useBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - - // Lightning - if (atmo.clouds.hasLightning) - { - var lightning = _lightningPrefab.InstantiateInactive(); - lightning.transform.parent = cloudsMainGO.transform; - lightning.transform.localPosition = Vector3.zero; - - var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; - lightningGenerator._audioSector = sector; - if (atmo.clouds.lightningGradient != null) - { - var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; - - for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) - { - var pair = atmo.clouds.lightningGradient[i]; - gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); - } - - lightningGenerator._lightColor.colorKeys = gradient; - } - lightning.SetActive(true); - } - - cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - - cloudsBottomGO.SetActive(true); - cloudsFluidGO.SetActive(true); - cloudsMainGO.SetActive(true); - } - - public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) - { - Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; - - Texture2D image, cap, ramp; - - try - { - image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); - - if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); - else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); - if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); - else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); - } - catch (Exception e) - { - Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); - return null; - } - - GameObject cloudsTopGO = new GameObject("TopClouds"); - cloudsTopGO.SetActive(false); - cloudsTopGO.transform.parent = rootObject.transform; - cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; - - MeshFilter topMF = cloudsTopGO.AddComponent(); + + // If they set a colour apply it to all the materials else keep the default QM one + if (atmo.clouds.tint != null) + { + var bottomColor = atmo.clouds.tint.ToColor(); + + var bottomTSRTempArray = new Material[2]; + + bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); + bottomTSRTempArray[0].SetColor(Color1, bottomColor); + bottomTSRTempArray[0].SetColor(TintColor, bottomColor); + bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); + + bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); + + bottomTSR.sharedMaterials = bottomTSRTempArray; + } + else + { + bottomTSR.sharedMaterials = bottomTSRMaterials; + } + + bottomTSR.maxLOD = 6; + bottomTSR.LODBias = 0; + bottomTSR.LODRadius = 1f; + + TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); + bottomTSST._sector = sector; + + GameObject cloudsFluidGO = new GameObject("CloudsFluid"); + cloudsFluidGO.SetActive(false); + cloudsFluidGO.layer = 17; + cloudsFluidGO.transform.parent = cloudsMainGO.transform; + + SphereCollider fluidSC = cloudsFluidGO.AddComponent(); + fluidSC.isTrigger = true; + fluidSC.radius = atmo.size; + + OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); + fluidOWSC._innerRadius = atmo.size * 0.9f; + + CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); + fluidCLFV._layer = 5; + fluidCLFV._priority = 1; + fluidCLFV._density = 1.2f; + + var fluidType = FluidVolume.Type.CLOUD; + + try + { + fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); + } + + fluidCLFV._fluidType = fluidType; + fluidCLFV._allowShipAutoroll = true; + fluidCLFV._disableOnStart = false; + + // Fix the rotations once the rest is done + cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); + // For the base shader it has to be rotated idk + if (atmo.clouds.useBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + + // Lightning + if (atmo.clouds.hasLightning) + { + var lightning = _lightningPrefab.InstantiateInactive(); + lightning.transform.parent = cloudsMainGO.transform; + lightning.transform.localPosition = Vector3.zero; + + var lightningGenerator = lightning.GetComponent(); + lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; + lightningGenerator._audioSector = sector; + if (atmo.clouds.lightningGradient != null) + { + var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; + + for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) + { + var pair = atmo.clouds.lightningGradient[i]; + gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); + } + + lightningGenerator._lightColor.colorKeys = gradient; + } + lightning.SetActive(true); + } + + cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + + cloudsBottomGO.SetActive(true); + cloudsFluidGO.SetActive(true); + cloudsMainGO.SetActive(true); + } + + public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) + { + Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; + + Texture2D image, cap, ramp; + + try + { + image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); + + if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); + else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); + if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); + else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); + } + catch (Exception e) + { + Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); + return null; + } + + GameObject cloudsTopGO = new GameObject("TopClouds"); + cloudsTopGO.SetActive(false); + cloudsTopGO.transform.parent = rootObject.transform; + cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; + + MeshFilter topMF = cloudsTopGO.AddComponent(); topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; - - MeshRenderer topMR = cloudsTopGO.AddComponent(); - - if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); + + MeshRenderer topMR = cloudsTopGO.AddComponent(); + + if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent().sharedMaterials; Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials; - var tempArray = new Material[2]; - - if (atmo.clouds.useBasicCloudShader) - { - var material = new Material(_sphereShader); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; - - tempArray[0] = material; - } - else - { + var tempArray = new Material[2]; + + if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic) + { + var material = new Material(_sphereShader); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; + + tempArray[0] = material; + } + else + { var material = new Material(prefabMaterials[0]); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; - tempArray[0] = material; - } - - // This is the stencil material for the fog under the clouds + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; + tempArray[0] = material; + } + + // This is the stencil material for the fog under the clouds tempArray[1] = new Material(prefabMaterials[1]); - topMR.sharedMaterials = tempArray; - - foreach (var material in topMR.sharedMaterials) - { - material.SetColor(Color1, cloudTint); - material.SetColor(TintColor, cloudTint); - - material.SetTexture(MainTex, image); - material.SetTexture(RampTex, ramp); - material.SetTexture(CapTex, cap); - } - - if (atmo.clouds.unlit) - { - cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); - } - - RotateTransform topRT = cloudsTopGO.AddComponent(); - // Idk why but the axis is weird - topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; - topRT._degreesPerSecond = 10; - topRT._randomizeRotationRate = false; - - cloudsTopGO.transform.localPosition = Vector3.zero; - - cloudsTopGO.SetActive(true); - - return cloudsTopGO; - } - } -} + topMR.sharedMaterials = tempArray; + + foreach (var material in topMR.sharedMaterials) + { + material.SetColor(Color1, cloudTint); + material.SetColor(TintColor, cloudTint); + + material.SetTexture(MainTex, image); + material.SetTexture(RampTex, ramp); + material.SetTexture(CapTex, cap); + } + + if (atmo.clouds.unlit) + { + cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); + } + + RotateTransform topRT = cloudsTopGO.AddComponent(); + // Idk why but the axis is weird + topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; + topRT._degreesPerSecond = 10; + topRT._randomizeRotationRate = false; + + cloudsTopGO.transform.localPosition = Vector3.zero; + + cloudsTopGO.SetActive(true); + + return cloudsTopGO; + } + } +} diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index ee652297..98876470 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -234,7 +234,11 @@ namespace NewHorizons.External.Configs // Former is obsolete, latter is to validate if (Atmosphere.hasAtmosphere || Atmosphere.atmosphereTint != null) - Atmosphere.useAtmosphereShader = true; + Atmosphere.useAtmosphereShader = true; + + // useBasicCloudShader is obsolete + if (Atmosphere.clouds != null && Atmosphere.clouds.useBasicCloudShader) + Atmosphere.clouds.cloudsPrefab = CloudPrefabType.Basic; } if (Props?.tornados != null) diff --git a/NewHorizons/External/Modules/AtmosphereModule.cs b/NewHorizons/External/Modules/AtmosphereModule.cs index e9be6bd6..926b65fd 100644 --- a/NewHorizons/External/Modules/AtmosphereModule.cs +++ b/NewHorizons/External/Modules/AtmosphereModule.cs @@ -27,7 +27,9 @@ namespace NewHorizons.External.Modules { [EnumMember(Value = @"giantsDeep")] GiantsDeep = 0, - [EnumMember(Value = @"quantumMoon")] QuantumMoon = 1, + [EnumMember(Value = @"quantumMoon")] QuantumMoon = 1, + + [EnumMember(Value = @"basic")] Basic = 2, } [JsonObject] @@ -151,11 +153,19 @@ namespace NewHorizons.External.Modules /// If the top layer shouldn't have shadows. Set to true if you're making a brown dwarf for example. /// public bool unlit; + + + + #region Obsolete /// /// Set to `false` in order to use Giant's Deep's shader. Set to `true` to just apply the cloud texture as is. /// + [Obsolete("useBasicCloudShader is deprecated, please use cloudsPrefab=\"basic\" instead")] public bool useBasicCloudShader; + + #endregion Obsolete + } From 5f6bd90f004edf3a8f0d6877c6245c0860341f4c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 7 Jun 2022 12:37:39 +0000 Subject: [PATCH 59/72] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index ce1071f5..00b268c8 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -297,6 +297,10 @@ "type": "object", "additionalProperties": false, "properties": { + "cloudsPrefab": { + "description": "Should these clouds be based on Giant's Deep's banded clouds, or the Quantum Moon's non-banded clouds?", + "$ref": "#/definitions/CloudPrefabType" + }, "capPath": { "type": "string", "description": "Relative filepath to the cloud cap texture, if the planet has clouds." @@ -341,13 +345,23 @@ "unlit": { "type": "boolean", "description": "If the top layer shouldn't have shadows. Set to true if you're making a brown dwarf for example." - }, - "useBasicCloudShader": { - "type": "boolean", - "description": "Set to `false` in order to use Giant's Deep's shader. Set to `true` to just apply the cloud texture as is." } } }, + "CloudPrefabType": { + "type": "string", + "description": "", + "x-enumNames": [ + "GiantsDeep", + "QuantumMoon", + "Basic" + ], + "enum": [ + "giantsDeep", + "quantumMoon", + "basic" + ] + }, "CloudFluidType": { "type": "string", "description": "", From 66c7fbb075f13df03a2597600471c2b247b870c0 Mon Sep 17 00:00:00 2001 From: Tlya <94857119+Tllya@users.noreply.github.com> Date: Wed, 8 Jun 2022 12:26:21 +0500 Subject: [PATCH 60/72] No sussy amogus --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93571fe0..ce9b9a73 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ New Horizons was made with help from: - And the Outer Wilds modding server. Translation credits: -- Russian: GrayFix and Tlya +- Russian: Tlya - German: Nolram - Spanish: Ciborgm9 and Ink From 9acdebebb1e60901867f45216342559a99d6beec Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 8 Jun 2022 11:12:06 -0700 Subject: [PATCH 61/72] Bump Version --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 3aa5a918..db43d14c 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,7 +3,7 @@ "author": "xen, Bwc9876, & Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.2.2", + "version": "1.2.3", "owmlVersion": "2.3.3", "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.AutoResume", "PacificEngine.OW_Randomizer" ], "pathsToPreserve": [ "planets", "systems", "translations" ] From 65e87886d1d827301c60f2dca0519fa82a6dfb15 Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 8 Jun 2022 14:40:06 -0400 Subject: [PATCH 62/72] Fix NRE in WarpDrivePatches.cs --- NewHorizons/Patches/WarpDrivePatches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Patches/WarpDrivePatches.cs b/NewHorizons/Patches/WarpDrivePatches.cs index 5f0d51a7..610cfbdd 100644 --- a/NewHorizons/Patches/WarpDrivePatches.cs +++ b/NewHorizons/Patches/WarpDrivePatches.cs @@ -15,7 +15,7 @@ namespace NewHorizons.Patches var newPrompt = TranslationHandler.GetTranslation("INTERSTELLAR_MODE", TranslationHandler.TextType.UI); __instance._detectiveModePrompt.SetText(newPrompt); - var text = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); + var text = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); text.text = newPrompt; } From fc155a19c115025fca649f5e6dc4080cd938eb9d Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 8 Jun 2022 11:43:50 -0700 Subject: [PATCH 63/72] replace useBasicCloudShader with cloudsPrefab == CloudPrefabType.Basic --- .../Builder/Atmosphere/CloudsBuilder.cs | 440 +++++++++--------- 1 file changed, 220 insertions(+), 220 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index c6594b48..ae0a3243 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -1,227 +1,227 @@ -using NewHorizons.External.Modules; -using NewHorizons.Utility; -using OWML.Common; -using System; -using UnityEngine; -using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Builder.Atmosphere -{ - public static class CloudsBuilder - { - private static Shader _sphereShader = null; +using NewHorizons.External.Modules; +using NewHorizons.Utility; +using OWML.Common; +using System; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; +namespace NewHorizons.Builder.Atmosphere +{ + public static class CloudsBuilder + { + private static Shader _sphereShader = null; private static Material[] _gdCloudMaterials; - private static Material[] _qmCloudMaterials; - private static GameObject _lightningPrefab; - private static Texture2D _colorRamp; - private static readonly int Color1 = Shader.PropertyToID("_Color"); - private static readonly int TintColor = Shader.PropertyToID("_TintColor"); - private static readonly int MainTex = Shader.PropertyToID("_MainTex"); - private static readonly int RampTex = Shader.PropertyToID("_RampTex"); - private static readonly int CapTex = Shader.PropertyToID("_CapTex"); - private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); - - public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) - { + private static Material[] _qmCloudMaterials; + private static GameObject _lightningPrefab; + private static Texture2D _colorRamp; + private static readonly int Color1 = Shader.PropertyToID("_Color"); + private static readonly int TintColor = Shader.PropertyToID("_TintColor"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int RampTex = Shader.PropertyToID("_RampTex"); + private static readonly int CapTex = Shader.PropertyToID("_CapTex"); + private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); + + public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) + { if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); - if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); - - GameObject cloudsMainGO = new GameObject("Clouds"); - cloudsMainGO.SetActive(false); - cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; - - MakeTopClouds(cloudsMainGO, atmo, mod); - - GameObject cloudsBottomGO = new GameObject("BottomClouds"); - cloudsBottomGO.SetActive(false); - cloudsBottomGO.transform.parent = cloudsMainGO.transform; - cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; - - TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); + if (_colorRamp == null) _colorRamp = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/textures/Clouds_Bottom_ramp.png"); + + GameObject cloudsMainGO = new GameObject("Clouds"); + cloudsMainGO.SetActive(false); + cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; + + MakeTopClouds(cloudsMainGO, atmo, mod); + + GameObject cloudsBottomGO = new GameObject("BottomClouds"); + cloudsBottomGO.SetActive(false); + cloudsBottomGO.transform.parent = cloudsMainGO.transform; + cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; + + TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); bottomTSR.tessellationMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; var bottomTSRMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; - - // If they set a colour apply it to all the materials else keep the default QM one - if (atmo.clouds.tint != null) - { - var bottomColor = atmo.clouds.tint.ToColor(); - - var bottomTSRTempArray = new Material[2]; - - bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); - bottomTSRTempArray[0].SetColor(Color1, bottomColor); - bottomTSRTempArray[0].SetColor(TintColor, bottomColor); - bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); - - bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); - - bottomTSR.sharedMaterials = bottomTSRTempArray; - } - else - { - bottomTSR.sharedMaterials = bottomTSRMaterials; - } - - bottomTSR.maxLOD = 6; - bottomTSR.LODBias = 0; - bottomTSR.LODRadius = 1f; - - TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); - bottomTSST._sector = sector; - - GameObject cloudsFluidGO = new GameObject("CloudsFluid"); - cloudsFluidGO.SetActive(false); - cloudsFluidGO.layer = 17; - cloudsFluidGO.transform.parent = cloudsMainGO.transform; - - SphereCollider fluidSC = cloudsFluidGO.AddComponent(); - fluidSC.isTrigger = true; - fluidSC.radius = atmo.size; - - OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); - fluidOWSC._innerRadius = atmo.size * 0.9f; - - CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); - fluidCLFV._layer = 5; - fluidCLFV._priority = 1; - fluidCLFV._density = 1.2f; - - var fluidType = FluidVolume.Type.CLOUD; - - try - { - fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); - } - catch (Exception ex) - { - Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); - } - - fluidCLFV._fluidType = fluidType; - fluidCLFV._allowShipAutoroll = true; - fluidCLFV._disableOnStart = false; - - // Fix the rotations once the rest is done - cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); - // For the base shader it has to be rotated idk - if (atmo.clouds.useBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); - - // Lightning - if (atmo.clouds.hasLightning) - { - var lightning = _lightningPrefab.InstantiateInactive(); - lightning.transform.parent = cloudsMainGO.transform; - lightning.transform.localPosition = Vector3.zero; - - var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; - lightningGenerator._audioSector = sector; - if (atmo.clouds.lightningGradient != null) - { - var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; - - for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) - { - var pair = atmo.clouds.lightningGradient[i]; - gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); - } - - lightningGenerator._lightColor.colorKeys = gradient; - } - lightning.SetActive(true); - } - - cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); - - cloudsBottomGO.SetActive(true); - cloudsFluidGO.SetActive(true); - cloudsMainGO.SetActive(true); - } - - public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) - { - Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; - - Texture2D image, cap, ramp; - - try - { - image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); - - if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); - else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); - if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); - else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); - } - catch (Exception e) - { - Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); - return null; - } - - GameObject cloudsTopGO = new GameObject("TopClouds"); - cloudsTopGO.SetActive(false); - cloudsTopGO.transform.parent = rootObject.transform; - cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; - - MeshFilter topMF = cloudsTopGO.AddComponent(); + + // If they set a colour apply it to all the materials else keep the default QM one + if (atmo.clouds.tint != null) + { + var bottomColor = atmo.clouds.tint.ToColor(); + + var bottomTSRTempArray = new Material[2]; + + bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); + bottomTSRTempArray[0].SetColor(Color1, bottomColor); + bottomTSRTempArray[0].SetColor(TintColor, bottomColor); + bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); + + bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); + + bottomTSR.sharedMaterials = bottomTSRTempArray; + } + else + { + bottomTSR.sharedMaterials = bottomTSRMaterials; + } + + bottomTSR.maxLOD = 6; + bottomTSR.LODBias = 0; + bottomTSR.LODRadius = 1f; + + TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); + bottomTSST._sector = sector; + + GameObject cloudsFluidGO = new GameObject("CloudsFluid"); + cloudsFluidGO.SetActive(false); + cloudsFluidGO.layer = 17; + cloudsFluidGO.transform.parent = cloudsMainGO.transform; + + SphereCollider fluidSC = cloudsFluidGO.AddComponent(); + fluidSC.isTrigger = true; + fluidSC.radius = atmo.size; + + OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); + fluidOWSC._innerRadius = atmo.size * 0.9f; + + CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); + fluidCLFV._layer = 5; + fluidCLFV._priority = 1; + fluidCLFV._density = 1.2f; + + var fluidType = FluidVolume.Type.CLOUD; + + try + { + fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), Enum.GetName(typeof(CloudFluidType), atmo.clouds.fluidType).ToUpper()); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't parse fluid volume type [{atmo.clouds.fluidType}]: {ex.Message}, {ex.StackTrace}"); + } + + fluidCLFV._fluidType = fluidType; + fluidCLFV._allowShipAutoroll = true; + fluidCLFV._disableOnStart = false; + + // Fix the rotations once the rest is done + cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); + // For the base shader it has to be rotated idk + if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + + // Lightning + if (atmo.clouds.hasLightning) + { + var lightning = _lightningPrefab.InstantiateInactive(); + lightning.transform.parent = cloudsMainGO.transform; + lightning.transform.localPosition = Vector3.zero; + + var lightningGenerator = lightning.GetComponent(); + lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; + lightningGenerator._audioSector = sector; + if (atmo.clouds.lightningGradient != null) + { + var gradient = new GradientColorKey[atmo.clouds.lightningGradient.Length]; + + for(int i = 0; i < atmo.clouds.lightningGradient.Length; i++) + { + var pair = atmo.clouds.lightningGradient[i]; + gradient[i] = new GradientColorKey(pair.tint.ToColor(), pair.time); + } + + lightningGenerator._lightColor.colorKeys = gradient; + } + lightning.SetActive(true); + } + + cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsFluidGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + + cloudsBottomGO.SetActive(true); + cloudsFluidGO.SetActive(true); + cloudsMainGO.SetActive(true); + } + + public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) + { + Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; + + Texture2D image, cap, ramp; + + try + { + image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); + + if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128); + else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath); + if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); + else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); + } + catch (Exception e) + { + Logger.LogError($"Couldn't load Cloud textures for [{rootObject.name}], {e.Message}, {e.StackTrace}"); + return null; + } + + GameObject cloudsTopGO = new GameObject("TopClouds"); + cloudsTopGO.SetActive(false); + cloudsTopGO.transform.parent = rootObject.transform; + cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; + + MeshFilter topMF = cloudsTopGO.AddComponent(); topMF.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; - - MeshRenderer topMR = cloudsTopGO.AddComponent(); - - if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); + + MeshRenderer topMR = cloudsTopGO.AddComponent(); + + if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent().sharedMaterials; - Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials; - var tempArray = new Material[2]; - - if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic) - { - var material = new Material(_sphereShader); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; - - tempArray[0] = material; - } - else - { - var material = new Material(prefabMaterials[0]); - if (atmo.clouds.unlit) material.renderQueue = 2550; - material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; - tempArray[0] = material; - } - - // This is the stencil material for the fog under the clouds - tempArray[1] = new Material(prefabMaterials[1]); - topMR.sharedMaterials = tempArray; - - foreach (var material in topMR.sharedMaterials) - { - material.SetColor(Color1, cloudTint); - material.SetColor(TintColor, cloudTint); - - material.SetTexture(MainTex, image); - material.SetTexture(RampTex, ramp); - material.SetTexture(CapTex, cap); - } - - if (atmo.clouds.unlit) - { - cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); - } - - RotateTransform topRT = cloudsTopGO.AddComponent(); - // Idk why but the axis is weird - topRT._localAxis = atmo.clouds.useBasicCloudShader ? Vector3.forward : Vector3.up; - topRT._degreesPerSecond = 10; - topRT._randomizeRotationRate = false; - - cloudsTopGO.transform.localPosition = Vector3.zero; - - cloudsTopGO.SetActive(true); - - return cloudsTopGO; - } - } -} + Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials; + var tempArray = new Material[2]; + + if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic) + { + var material = new Material(_sphereShader); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; + + tempArray[0] = material; + } + else + { + var material = new Material(prefabMaterials[0]); + if (atmo.clouds.unlit) material.renderQueue = 2550; + material.name = atmo.clouds.unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; + tempArray[0] = material; + } + + // This is the stencil material for the fog under the clouds + tempArray[1] = new Material(prefabMaterials[1]); + topMR.sharedMaterials = tempArray; + + foreach (var material in topMR.sharedMaterials) + { + material.SetColor(Color1, cloudTint); + material.SetColor(TintColor, cloudTint); + + material.SetTexture(MainTex, image); + material.SetTexture(RampTex, ramp); + material.SetTexture(CapTex, cap); + } + + if (atmo.clouds.unlit) + { + cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); + } + + RotateTransform topRT = cloudsTopGO.AddComponent(); + // Idk why but the axis is weird + topRT._localAxis = atmo.clouds.cloudsPrefab == CloudPrefabType.Basic ? Vector3.forward : Vector3.up; + topRT._degreesPerSecond = 10; + topRT._randomizeRotationRate = false; + + cloudsTopGO.transform.localPosition = Vector3.zero; + + cloudsTopGO.SetActive(true); + + return cloudsTopGO; + } + } +} From 664ee452cb38e79ba0cc45ab9d2f2743f936358c Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 8 Jun 2022 14:59:58 -0400 Subject: [PATCH 64/72] Fixed NRE in CloakBuilder.cs --- NewHorizons/Builder/Body/CloakBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index ab18f6bf..05bbd140 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -41,7 +41,7 @@ namespace NewHorizons.Builder.Body cloakFieldController._nearCloakRadius = radius * 800 / 3000f; cloakFieldController._referenceFrameVolume = OWRB._attachedRFVolume; - cloakFieldController._exclusionSector = null; + cloakFieldController._exclusionSector = sector; cloakFieldController._cloakSphereVolume = (sector?.transform ?? planetGO.transform).GetComponentInChildren(); var cloakSectorController = newCloak.AddComponent(); From 68f2b3e402a48f09702680a2f4612dfdce1b7bb5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 8 Jun 2022 12:22:20 -0700 Subject: [PATCH 65/72] put SupernovaVolumePlaceholder into correct layer so it doesnt complain --- NewHorizons/Builder/Body/StarBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index a2c81ed1..d50ae5c7 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -134,6 +134,7 @@ namespace NewHorizons.Builder.Body // It fucking insists on this existing and its really annoying var supernovaVolume = new GameObject("SupernovaVolumePlaceholder"); supernovaVolume.transform.SetParent(starGO.transform); + supernovaVolume.layer = LayerMask.NameToLayer("BasicEffectVolume"); var sphere = supernovaVolume.AddComponent(); sphere.radius = 0f; sphere.isTrigger = true; From ce1ccc7601c5c148045fdc3743dd1c06b39bd0fd Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 8 Jun 2022 12:44:46 -0700 Subject: [PATCH 66/72] put ship warp audio on Environment track so it wont complain --- NewHorizons/Components/ShipWarpController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index 9f4a8cc3..5e7b6d8a 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -39,6 +39,7 @@ namespace NewHorizons.Components _isWarpingIn = false; _oneShotSource = base.gameObject.AddComponent(); + _oneShotSource._track = OWAudioMixer.TrackName.Environment; GlobalMessenger.AddListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); } From a8e519e690029c74763954f76906dd9dcb9c62be Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 8 Jun 2022 12:44:46 -0700 Subject: [PATCH 67/72] put ship warp audio on Environment track so it wont complain --- NewHorizons/Components/ShipWarpController.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index 9f4a8cc3..c5b9597f 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -38,7 +38,10 @@ namespace NewHorizons.Components _isWarpingIn = false; + gameObject.SetActive(false); _oneShotSource = base.gameObject.AddComponent(); + _oneShotSource._track = OWAudioMixer.TrackName.Environment; + gameObject.SetActive(true); GlobalMessenger.AddListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); } From 7add9f8d8d7be1c43f1b7d3cb42b213fe9559823 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 8 Jun 2022 12:55:10 -0700 Subject: [PATCH 68/72] use Ship track cuz its louder --- NewHorizons/Components/ShipWarpController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index c5b9597f..d412d1e9 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -40,7 +40,7 @@ namespace NewHorizons.Components gameObject.SetActive(false); _oneShotSource = base.gameObject.AddComponent(); - _oneShotSource._track = OWAudioMixer.TrackName.Environment; + _oneShotSource._track = OWAudioMixer.TrackName.Ship; gameObject.SetActive(true); GlobalMessenger.AddListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); From b67207555fd4ab0efd7e83e9e35ea1a15bfac550 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 8 Jun 2022 13:38:04 -0700 Subject: [PATCH 69/72] use annotation instead of yucky manual way --- NewHorizons/Main.cs | 5 +---- NewHorizons/Patches/LocatorPatches.cs | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 852686b5..49c6690f 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -116,10 +116,7 @@ namespace NewHorizons public void Start() { // Patches - Harmony harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); - harmony.Patch(typeof(CloakFieldController).GetMethod("get_" + nameof(CloakFieldController.isPlayerInsideCloak), BindingFlags.Public | BindingFlags.Instance), postfix: new HarmonyMethod(typeof(Patches.LocatorPatches).GetMethod(nameof(Patches.LocatorPatches.CloakFieldController_isPlayerInsideCloak), BindingFlags.Static | BindingFlags.Public))); - harmony.Patch(typeof(CloakFieldController).GetMethod("get_" + nameof(CloakFieldController.isProbeInsideCloak), BindingFlags.Public | BindingFlags.Instance), postfix: new HarmonyMethod(typeof(Patches.LocatorPatches).GetMethod(nameof(Patches.LocatorPatches.CloakFieldController_isProbeInsideCloak), BindingFlags.Static | BindingFlags.Public))); - harmony.Patch(typeof(CloakFieldController).GetMethod("get_" + nameof(CloakFieldController.isShipInsideCloak), BindingFlags.Public | BindingFlags.Instance), postfix: new HarmonyMethod(typeof(Patches.LocatorPatches).GetMethod(nameof(Patches.LocatorPatches.CloakFieldController_isShipInsideCloak), BindingFlags.Static | BindingFlags.Public))); + Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); OnChangeStarSystem = new StarSystemEvent(); OnStarSystemLoaded = new StarSystemEvent(); diff --git a/NewHorizons/Patches/LocatorPatches.cs b/NewHorizons/Patches/LocatorPatches.cs index e826ba06..30c76cf2 100644 --- a/NewHorizons/Patches/LocatorPatches.cs +++ b/NewHorizons/Patches/LocatorPatches.cs @@ -11,16 +11,22 @@ namespace NewHorizons.Patches return Locator._cloakFieldController == null; } + [HarmonyPostfix] + [HarmonyPatch(typeof(CloakFieldController), nameof(CloakFieldController.isPlayerInsideCloak), MethodType.Getter)] public static void CloakFieldController_isPlayerInsideCloak(CloakFieldController __instance, ref bool __result) { __result = __result || Components.CloakSectorController.isPlayerInside; } + [HarmonyPostfix] + [HarmonyPatch(typeof(CloakFieldController), nameof(CloakFieldController.isProbeInsideCloak), MethodType.Getter)] public static void CloakFieldController_isProbeInsideCloak(CloakFieldController __instance, ref bool __result) { __result = __result || Components.CloakSectorController.isProbeInside; } + [HarmonyPostfix] + [HarmonyPatch(typeof(CloakFieldController), nameof(CloakFieldController.isShipInsideCloak), MethodType.Getter)] public static void CloakFieldController_isShipInsideCloak(CloakFieldController __instance, ref bool __result) { __result = __result || Components.CloakSectorController.isShipInside; From a1026e72adfbc9616987481fe0571b9b95ab44a0 Mon Sep 17 00:00:00 2001 From: Ben C Date: Fri, 10 Jun 2022 14:20:23 -0400 Subject: [PATCH 70/72] Fixed Ship Going Haywire In `Start()` --- NewHorizons/Components/ShipWarpController.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index d412d1e9..b79a60d9 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -37,11 +37,9 @@ namespace NewHorizons.Components MakeWhiteHole(); _isWarpingIn = false; - - gameObject.SetActive(false); - _oneShotSource = base.gameObject.AddComponent(); + + _oneShotSource = gameObject.AddComponent(); _oneShotSource._track = OWAudioMixer.TrackName.Ship; - gameObject.SetActive(true); GlobalMessenger.AddListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); } From 46f6f297601d52119573f1198fd091239299d961 Mon Sep 17 00:00:00 2001 From: Ben C Date: Fri, 10 Jun 2022 14:20:38 -0400 Subject: [PATCH 71/72] Fixed Cloaks Not Working In Custom Systems --- NewHorizons/Builder/Body/CloakBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index 05bbd140..ab18f6bf 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -41,7 +41,7 @@ namespace NewHorizons.Builder.Body cloakFieldController._nearCloakRadius = radius * 800 / 3000f; cloakFieldController._referenceFrameVolume = OWRB._attachedRFVolume; - cloakFieldController._exclusionSector = sector; + cloakFieldController._exclusionSector = null; cloakFieldController._cloakSphereVolume = (sector?.transform ?? planetGO.transform).GetComponentInChildren(); var cloakSectorController = newCloak.AddComponent(); From cabc0b6203e234dafc8c68c5ec8fd1e2e9d356fe Mon Sep 17 00:00:00 2001 From: Ben C Date: Fri, 10 Jun 2022 14:20:53 -0400 Subject: [PATCH 72/72] Bumped Version --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index db43d14c..45398176 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,7 +3,7 @@ "author": "xen, Bwc9876, & Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.2.3", + "version": "1.2.4", "owmlVersion": "2.3.3", "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.AutoResume", "PacificEngine.OW_Randomizer" ], "pathsToPreserve": [ "planets", "systems", "translations" ]