From 97a2ccd25864999164bcbb5a523da9201c64dc08 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 24 Dec 2022 14:08:07 -0500 Subject: [PATCH] Actually add the renaming and parenting stuff --- .../Builder/Body/SingularityBuilder.cs | 34 +++++++++++++++---- NewHorizons/Builder/Props/GeyserBuilder.cs | 17 +++++++++- .../Builder/Props/ProjectionBuilder.cs | 9 ++--- NewHorizons/Builder/Props/RaftBuilder.cs | 30 ++++++++++++++-- NewHorizons/Builder/Props/RemoteBuilder.cs | 9 +---- NewHorizons/Builder/Props/TornadoBuilder.cs | 2 +- NewHorizons/Builder/Props/VolcanoBuilder.cs | 26 ++++++++++++-- .../Builder/ShipLog/EntryLocationBuilder.cs | 25 ++++++++++++-- 8 files changed, 124 insertions(+), 28 deletions(-) diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index 0c4d12f1..432c57f0 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -88,9 +88,8 @@ namespace NewHorizons.Builder.Body Vector3 localPosition = singularity?.position == null ? Vector3.zero : singularity.position; Vector3 localRotation = singularity?.rotation == null ? Vector3.zero : singularity.rotation; - GameObject newSingularity = null; - newSingularity = MakeSingularity(go, sector, localPosition, localRotation, polarity, horizonRadius, distortRadius, - hasHazardVolume, singularity.targetStarSystem, singularity.curve, singularity.hasWarpEffects, singularity.renderQueueOverride); + GameObject newSingularity = MakeSingularity(go, sector, localPosition, localRotation, polarity, horizonRadius, distortRadius, + hasHazardVolume, singularity.targetStarSystem, singularity.curve, singularity.hasWarpEffects, singularity.renderQueueOverride, singularity.rename, singularity.parentPath, singularity.isRelativeToParent); var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID; _singularitiesByID.Add(uniqueID, newSingularity); @@ -134,15 +133,32 @@ namespace NewHorizons.Builder.Body } public static GameObject MakeSingularity(GameObject planetGO, Sector sector, Vector3 position, Vector3 rotation, bool polarity, float horizon, float distort, - bool hasDestructionVolume, string targetStarSystem = null, TimeValuePair[] curve = null, bool warpEffects = true, int renderQueue = 2985) + bool hasDestructionVolume, string targetStarSystem = null, TimeValuePair[] curve = null, bool warpEffects = true, int renderQueue = 2985, string rename = null, string parentPath = null, bool isRelativeToParent = false) { InitPrefabs(); // polarity true = black, false = white - var singularity = new GameObject(polarity ? "BlackHole" : "WhiteHole"); + var singularity = new GameObject(!string.IsNullOrEmpty(rename) ? rename : (polarity ? "BlackHole" : "WhiteHole")); singularity.transform.parent = sector?.transform ?? planetGO.transform; - singularity.transform.position = planetGO.transform.TransformPoint(position); + + if (!string.IsNullOrEmpty(parentPath)) + { + var newParent = planetGO.transform.Find(parentPath); + if (newParent != null) + { + singularity.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{parentPath}"); + } + } + + if (isRelativeToParent) + singularity.transform.localPosition = position; + else + singularity.transform.position = planetGO.transform.TransformPoint(position); var singularityRenderer = MakeSingularityGraphics(singularity, polarity, horizon, distort, renderQueue); @@ -257,7 +273,11 @@ namespace NewHorizons.Builder.Body whiteHoleFluidVolume.enabled = true; } - singularity.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(rotation)); + var rot = Quaternion.Euler(rotation); + if (isRelativeToParent) + singularity.transform.localRotation = rot; + else + singularity.transform.rotation = planetGO.transform.TransformRotation(rot); singularity.SetActive(true); return singularity; diff --git a/NewHorizons/Builder/Props/GeyserBuilder.cs b/NewHorizons/Builder/Props/GeyserBuilder.cs index 2ef988d8..dd6a12ce 100644 --- a/NewHorizons/Builder/Props/GeyserBuilder.cs +++ b/NewHorizons/Builder/Props/GeyserBuilder.cs @@ -1,6 +1,8 @@ using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + namespace NewHorizons.Builder.Props { public static class GeyserBuilder @@ -17,8 +19,21 @@ namespace NewHorizons.Builder.Props InitPrefab(); var geyserGO = _geyserPrefab.InstantiateInactive(); + geyserGO.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "Geyser"; geyserGO.transform.parent = sector?.transform ?? planetGO.transform; - geyserGO.name = "Geyser"; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + geyserGO.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } var pos = (Vector3)info.position; diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 09e086c4..2c912aff 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -94,7 +94,7 @@ namespace NewHorizons.Builder.Props if (_slideReelPrefab == null) return null; var slideReelObj = _slideReelPrefab.InstantiateInactive(); - slideReelObj.name = $"Prefab_IP_Reel_{mod.ModHelper.Manifest.Name}"; + slideReelObj.name = !string.IsNullOrEmpty(info.rename) ? info.rename : $"Prefab_IP_Reel_{mod.ModHelper.Manifest.Name}"; var slideReel = slideReelObj.GetComponent(); slideReel.SetSector(sector); @@ -196,7 +196,7 @@ namespace NewHorizons.Builder.Props if (_autoPrefab == null) return null; var projectorObj = _autoPrefab.InstantiateInactive(); - projectorObj.name = $"Prefab_IP_AutoProjector_{mod.ModHelper.Manifest.Name}"; + projectorObj.name = !string.IsNullOrEmpty(info.rename) ? info.rename : $"Prefab_IP_AutoProjector_{mod.ModHelper.Manifest.Name}"; var autoProjector = projectorObj.GetComponent(); autoProjector._sector = sector; @@ -276,7 +276,7 @@ namespace NewHorizons.Builder.Props return null; } - g.name = "VisionStaffDetector"; + g.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "VisionStaffDetector"; // The number of slides is unlimited, 15 is only for texturing the actual slide reel item. This is not a slide reel item var slides = info.slides; @@ -312,7 +312,8 @@ namespace NewHorizons.Builder.Props position = info.position, rotation = info.rotation, parentPath = info.parentPath, - isRelativeToParent = info.isRelativeToParent + isRelativeToParent = info.isRelativeToParent, + rename = info.rename }; var standingTorch = DetailBuilder.Make(planetGO, sector, _standingVisionTorchPrefab, detailInfo); diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index ae27cea2..77295611 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -53,10 +53,34 @@ namespace NewHorizons.Builder.Props if (_prefab == null || sector == null) return null; GameObject raftObject = _prefab.InstantiateInactive(); - raftObject.name = "Raft_Body"; + raftObject.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "Raft_Body"; raftObject.transform.parent = sector?.transform ?? planetGO.transform; - raftObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero); - raftObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.identity); + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + raftObject.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + + var pos = (Vector3)(info.position ?? Vector3.zero); + var rot = Quaternion.identity; + if (info.isRelativeToParent) + { + raftObject.transform.localPosition = pos; + raftObject.transform.localRotation = rot; + } + else + { + raftObject.transform.position = planetGO.transform.TransformPoint(pos); + raftObject.transform.rotation = planetGO.transform.TransformRotation(rot); + } StreamingHandler.SetUpStreaming(raftObject, sector); diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs index 83c66158..bfe446d4 100644 --- a/NewHorizons/Builder/Props/RemoteBuilder.cs +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -252,14 +252,7 @@ namespace NewHorizons.Builder.Props { var shareStone = _shareStonePrefab.InstantiateInactive(); - if (!string.IsNullOrEmpty(info.rename)) - { - shareStone.name = info.rename; - } - else - { - shareStone.name = "ShareStone_" + id.ToString(); - } + shareStone.name = !string.IsNullOrEmpty(info.rename) ? info.rename : ("ShareStone_" + id.ToString()); shareStone.transform.parent = sector?.transform ?? go.transform; diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 9ec65b5b..2b63bd52 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -99,7 +99,7 @@ namespace NewHorizons.Builder.Props private static void MakeTornado(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, Vector3 position, bool downwards) { var tornadoGO = downwards ? _downPrefab.InstantiateInactive() : _upPrefab.InstantiateInactive(); - tornadoGO.name = downwards ? "Tornado_Down" : "Tornado_Up"; + tornadoGO.name = !string.IsNullOrEmpty(info.rename) ? info.rename : (downwards ? "Tornado_Down" : "Tornado_Up"); tornadoGO.transform.parent = sector?.transform ?? planetGO.transform; tornadoGO.transform.position = planetGO.transform.TransformPoint(position); tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, planetGO.transform.TransformDirection(position.normalized)); diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs index dd449e1f..478213cf 100644 --- a/NewHorizons/Builder/Props/VolcanoBuilder.cs +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -1,6 +1,8 @@ using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + namespace NewHorizons.Builder.Props { public static class VolcanoBuilder @@ -44,10 +46,30 @@ namespace NewHorizons.Builder.Props InitPrefab(); var launcherGO = _meteorLauncherPrefab.InstantiateInactive(); + launcherGO.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "MeteorLauncher"; launcherGO.transform.parent = sector?.transform ?? planetGO.transform; launcherGO.transform.position = planetGO.transform.TransformPoint(info.position == null ? Vector3.zero : (Vector3)info.position); - launcherGO.transform.rotation = Quaternion.FromToRotation(launcherGO.transform.TransformDirection(Vector3.up), ((Vector3)info.position).normalized).normalized; - launcherGO.name = "MeteorLauncher"; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + launcherGO.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + + var pos = (Vector3)(info.position ?? Vector3.zero); + if (info.isRelativeToParent) + launcherGO.transform.localPosition = pos; + else + launcherGO.transform.position = planetGO.transform.TransformPoint(pos); + + launcherGO.transform.rotation = Quaternion.FromToRotation(launcherGO.transform.TransformDirection(Vector3.up), pos.normalized).normalized; var meteorLauncher = launcherGO.GetComponent(); meteorLauncher._audioSector = sector; diff --git a/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs b/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs index b35ec450..4218e400 100644 --- a/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs +++ b/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs @@ -2,6 +2,8 @@ using NewHorizons.External.Modules; using OWML.Common; using System.Collections.Generic; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + namespace NewHorizons.Builder.ShipLog { public static class EntryLocationBuilder @@ -9,10 +11,29 @@ namespace NewHorizons.Builder.ShipLog private static readonly List _locationsToInitialize = new List(); public static void Make(GameObject go, Sector sector, PropModule.EntryLocationInfo info, IModBehaviour mod) { - GameObject entryLocationGameObject = new GameObject("Entry Location (" + info.id + ")"); + GameObject entryLocationGameObject = new GameObject(!string.IsNullOrEmpty(info.rename) ? info.rename : ("Entry Location (" + info.id + ")")); entryLocationGameObject.SetActive(false); entryLocationGameObject.transform.parent = sector?.transform ?? go.transform; - entryLocationGameObject.transform.position = go.transform.TransformPoint(info.position ?? Vector3.zero); + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = go.transform.Find(info.parentPath); + if (newParent != null) + { + entryLocationGameObject.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {go.name}/{info.parentPath}"); + } + } + + var pos = (Vector3)(info.position ?? Vector3.zero); + if (info.isRelativeToParent) + entryLocationGameObject.transform.localPosition = pos; + else + entryLocationGameObject.transform.position = go.transform.TransformPoint(pos); + ShipLogEntryLocation newLocation = entryLocationGameObject.AddComponent(); newLocation._entryID = info.id; newLocation._outerFogWarpVolume = go.GetComponentInChildren();