Add removeComponents option to DetailBuilder

This commit is contained in:
Nick 2022-05-12 15:42:09 -04:00
parent 07a5f0dade
commit e9a400cadf
3 changed files with 21 additions and 2 deletions

View File

@ -51,6 +51,20 @@ namespace NewHorizons.Builder.Props
else Logger.LogWarning($"Couldn't find {childPath}"); 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<Transform>())
{
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) 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); prop.transform.position = position == null ? planetGO.transform.position : planetGO.transform.TransformPoint((Vector3)position);
Quaternion rot = rotation == null ? Quaternion.identity : Quaternion.Euler((Vector3)rotation); Quaternion rot = rotation == null ? Quaternion.identity : Quaternion.Euler((Vector3)rotation);
prop.transform.rotation = planetGO.transform.TransformRotation(Quaternion.identity);
if (alignWithNormal) if (alignWithNormal)
{ {
// Apply the rotation after aligning it with normal // Apply the rotation after aligning it with normal
var up = planetGO.transform.InverseTransformPoint(prop.transform.position).normalized; 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; prop.transform.rotation *= rot;
} }
else else

View File

@ -43,6 +43,7 @@ namespace NewHorizons.External
public float scale { get; set; } = 1f; public float scale { get; set; } = 1f;
public bool alignToNormal; public bool alignToNormal;
public string[] removeChildren; public string[] removeChildren;
public bool removeComponents;
} }
public class RaftInfo public class RaftInfo

View File

@ -666,6 +666,11 @@
"items": { "items": {
"type": "string" "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
} }
} }
} }