From 2b988257e0d6850658ea2a1e83fa53571f221496 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 06:22:39 -0500 Subject: [PATCH] Incorporate light intensity into choice of "closest" star --- NewHorizons/Builder/Props/PropBuilder.cs | 35 ++++++++-------------- NewHorizons/External/PropModule.cs | 2 ++ NewHorizons/Utility/StarLightController.cs | 2 +- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/NewHorizons/Builder/Props/PropBuilder.cs b/NewHorizons/Builder/Props/PropBuilder.cs index 4fa930c7..9f88c56f 100644 --- a/NewHorizons/Builder/Props/PropBuilder.cs +++ b/NewHorizons/Builder/Props/PropBuilder.cs @@ -13,15 +13,15 @@ namespace NewHorizons.Builder.Props { public static class PropBuilder { - public static void Make(GameObject body, string propToClone, Vector3 position, Sector sector) + public static GameObject Make(GameObject body, string propToClone, Vector3 position, Sector sector) { var prefab = GameObject.Find(propToClone); - Make(body, prefab, position, sector); + return Make(body, prefab, position, sector); } - public static void Make(GameObject body, GameObject prefab, Vector3 position, Sector sector) + public static GameObject Make(GameObject body, GameObject prefab, Vector3 position, Sector sector) { - if (prefab == null) return; + if (prefab == null) return null; GameObject prop = GameObject.Instantiate(prefab, sector.transform); prop.transform.localPosition = position; @@ -43,7 +43,6 @@ namespace NewHorizons.Builder.Props sector.OnOccupantEnterSector += ((SectorDetector sd) => StreamingManager.LoadStreamingAssets(assetBundle)); } - /* foreach(var component in prop.GetComponentsInChildren()) { try @@ -61,25 +60,13 @@ namespace NewHorizons.Builder.Props Logger.Log($"Found a _sector field in {component}"); sectorField.SetValue(component, sector); } - else - { - if(component is Campfire) - { - Logger.Log("CAMPFIRE"); - Campfire campfire = component as Campfire; - if (campfire._sector != null) - campfire._sector.OnSectorOccupantsUpdated -= campfire.OnSectorOccupantsUpdated; - - campfire._sector = sector; - campfire._sector.OnSectorOccupantsUpdated += campfire.OnSectorOccupantsUpdated; - } - } } catch (Exception e) { Logger.Log($"{e.Message}, {e.StackTrace}"); } } - */ prop.SetActive(true); + + return prop; } public static void Scatter(GameObject body, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector) @@ -87,14 +74,16 @@ namespace NewHorizons.Builder.Props var area = 4f * Mathf.PI * radius * radius; var points = FibonacciSphere((int)area); - foreach (var scatterer in scatterInfo) + foreach (var propInfo in scatterInfo) { - var prefab = GameObject.Find(scatterer.path); - for(int i = 0; i < scatterer.count; i++) + var prefab = GameObject.Find(propInfo.path); + for(int i = 0; i < propInfo.count; i++) { var randomInd = (int)Random.Range(0, points.Count); var point = points[randomInd]; - Make(body, prefab, point.normalized * radius, sector); + var prop = Make(body, prefab, point.normalized * radius, sector); + if(propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); + if(propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); points.RemoveAt(randomInd); if (points.Count == 0) return; } diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index 175be630..367485a2 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -16,6 +16,8 @@ namespace NewHorizons.External { public string path; public int count; + public MVector3 offset; + public MVector3 rotation; } } } diff --git a/NewHorizons/Utility/StarLightController.cs b/NewHorizons/Utility/StarLightController.cs index e65880f1..5e3f8948 100644 --- a/NewHorizons/Utility/StarLightController.cs +++ b/NewHorizons/Utility/StarLightController.cs @@ -63,7 +63,7 @@ namespace NewHorizons.Utility origin = Locator.GetActiveCamera().transform.position; } - if ((star.transform.position - origin).sqrMagnitude < (_activeStar.transform.position - origin).sqrMagnitude) + if (star.Intensity * (star.transform.position - origin).sqrMagnitude < star.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) { ChangeActiveStar(star); break;