From e9a400cadf257126322b67d18b7b633b00c41a7b Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 May 2022 15:42:09 -0400 Subject: [PATCH] Add removeComponents option to DetailBuilder --- NewHorizons/Builder/Props/DetailBuilder.cs | 17 +++++++++++++++-- NewHorizons/External/PropModule.cs | 1 + NewHorizons/schema.json | 5 +++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 5343557d..ee320f9b 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -51,6 +51,20 @@ namespace NewHorizons.Builder.Props else Logger.LogWarning($"Couldn't find {childPath}"); } } + + if(detailGO != null && detail.removeComponents) + { + // Just swap all the children to a new game object + var newDetailGO = new GameObject(detailGO.name); + newDetailGO.transform.position = detailGO.transform.position; + newDetailGO.transform.parent = detailGO.transform.parent; + foreach(Transform child in detailGO.transform.GetComponentsInChildren()) + { + child.parent = newDetailGO.transform; + } + GameObject.Destroy(detailGO); + detailGO = newDetailGO; + } } public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) @@ -153,12 +167,11 @@ namespace NewHorizons.Builder.Props prop.transform.position = position == null ? planetGO.transform.position : planetGO.transform.TransformPoint((Vector3)position); Quaternion rot = rotation == null ? Quaternion.identity : Quaternion.Euler((Vector3)rotation); - prop.transform.rotation = planetGO.transform.TransformRotation(Quaternion.identity); if (alignWithNormal) { // Apply the rotation after aligning it with normal var up = planetGO.transform.InverseTransformPoint(prop.transform.position).normalized; - prop.transform.rotation = Quaternion.FromToRotation(prop.transform.up, up) * prop.transform.rotation; + prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up); prop.transform.rotation *= rot; } else diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index 80b982e2..2bf7cbc3 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -43,6 +43,7 @@ namespace NewHorizons.External public float scale { get; set; } = 1f; public bool alignToNormal; public string[] removeChildren; + public bool removeComponents; } public class RaftInfo diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index c70c6faa..9ef93fd7 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -666,6 +666,11 @@ "items": { "type": "string" } + }, + "removeComponents": { + "type": "boolean", + "description": "Do we reset all the components on this object? Useful for certain props that have dialogue components attached to them.", + "default": false } } }