diff --git a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs index 0598d3fd..65fa1fcf 100644 --- a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs +++ b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs @@ -60,7 +60,7 @@ namespace NewHorizons.Builder.Body var prefab = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Geometry_HubDimension"); var detailInfo = new PropModule.DetailInfo(); - var geometry = DetailBuilder.MakeDetail(go, sector, prefab, detailInfo); + var geometry = DetailBuilder.Make(go, sector, prefab, detailInfo); var exitWarps = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/OuterWarp_Hub").InstantiateInactive(); var repelVolume = SearchUtilities.Find("DB_HubDimension_Body/BrambleRepelVolume").InstantiateInactive(); diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 634c907a..68224045 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -20,69 +20,25 @@ namespace NewHorizons.Builder.Props return detailInfoToCorrespondingSpawnedGameObject[detail]; } - public static void Make(GameObject go, Sector sector, IModBehaviour mod, PropModule.DetailInfo detail) + /// + /// Create a detail using an asset bundle. + /// + public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, PropModule.DetailInfo detail) { - GameObject detailGO = null; - if (detail.assetBundle != null) { var prefab = AssetBundleUtilities.LoadPrefab(detail.assetBundle, detail.path, mod); - detailGO = MakeDetail(go, sector, prefab, detail); + return Make(go, sector, prefab, detail); } else - { - var prefab = SearchUtilities.Find(detail.path); - if (prefab == null) Logger.LogError($"Couldn't find detail {detail.path}"); - else detailGO = MakeDetail(go, sector, prefab, detail); - } - - if (detailGO == null) return; - - if (detail.removeChildren != null) - { - var detailPath = detailGO.transform.GetPath(); - var transforms = detailGO.GetComponentsInChildren(true); - foreach (var childPath in detail.removeChildren) - { - // Multiple children can have the same path so we delete all that match - var path = $"{detailPath}/{childPath}"; - - var flag = true; - foreach (var childObj in transforms.Where(x => x.GetPath() == path)) - { - flag = false; - childObj.gameObject.SetActive(false); - } - - if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\"."); - } - } - - if (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; - // Can't modify parents while looping through children bc idk - var children = new List(); - foreach (Transform child in detailGO.transform) - { - children.Add(child); - } - foreach (var child in children) - { - child.parent = newDetailGO.transform; - } - GameObject.Destroy(detailGO); - detailGO = newDetailGO; - } - - detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO; + return Make(go, sector, detail); } - public static GameObject MakeDetail(GameObject planetGO, Sector sector, PropModule.DetailInfo info) + /// + /// Create a detail using a path in the scene hierarchy of the item to copy. + /// + public static GameObject Make(GameObject planetGO, Sector sector, PropModule.DetailInfo info) { var prefab = SearchUtilities.Find(info.path); if (prefab == null) @@ -91,54 +47,13 @@ namespace NewHorizons.Builder.Props return null; } else - { - GameObject detailGO = MakeDetail(planetGO, sector, prefab, info); - - if (info.removeChildren != null) - { - var detailPath = detailGO.transform.GetPath(); - var transforms = detailGO.GetComponentsInChildren(true); - foreach (var childPath in info.removeChildren) - { - // Multiple children can have the same path so we delete all that match - var path = $"{detailPath}/{childPath}"; - - var flag = true; - foreach (var childObj in transforms.Where(x => x.GetPath() == path)) - { - flag = false; - childObj.gameObject.SetActive(false); - } - - if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\"."); - } - } - - if (info.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; - // Can't modify parents while looping through children bc idk - var children = new List(); - foreach (Transform child in detailGO.transform) - { - children.Add(child); - } - foreach (var child in children) - { - child.parent = newDetailGO.transform; - } - GameObject.Destroy(detailGO); - detailGO = newDetailGO; - } - - return detailGO; - } + return Make(planetGO, sector, prefab, info); } - public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, PropModule.DetailInfo info) + /// + /// Create a detail using a prefab. + /// + public static GameObject Make(GameObject planetGO, Sector sector, GameObject prefab, PropModule.DetailInfo info) { if (prefab == null) return null; @@ -193,8 +108,51 @@ namespace NewHorizons.Builder.Props prop.transform.localScale = info.scale != 0 ? Vector3.one * info.scale : prefab.transform.localScale; + if (info.removeChildren != null) + { + var detailPath = prop.transform.GetPath(); + var transforms = prop.GetComponentsInChildren(true); + foreach (var childPath in info.removeChildren) + { + // Multiple children can have the same path so we delete all that match + var path = $"{detailPath}/{childPath}"; + + var flag = true; + foreach (var childObj in transforms.Where(x => x.GetPath() == path)) + { + flag = false; + childObj.gameObject.SetActive(false); + } + + if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\"."); + } + } + + if (info.removeComponents) + { + // Just swap all the children to a new game object + var newProp = new GameObject(prop.name); + newProp.transform.position = prop.transform.position; + newProp.transform.parent = prop.transform.parent; + newProp.SetActive(false); + // Can't modify parents while looping through children bc idk + var children = new List(); + foreach (Transform child in prop.transform) + { + children.Add(child); + } + foreach (var child in children) + { + child.parent = newProp.transform; + } + GameObject.Destroy(prop); + prop = newProp; + } + prop.SetActive(true); + detailInfoToCorrespondingSpawnedGameObject[info] = prop; + return prop; } diff --git a/NewHorizons/Builder/Props/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiTextBuilder.cs index 8e7399d1..9ea62e16 100644 --- a/NewHorizons/Builder/Props/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiTextBuilder.cs @@ -280,7 +280,7 @@ namespace NewHorizons.Builder.Props { position = info.position }; - var computerObject = DetailBuilder.MakeDetail(planetGO, sector, _preCrashComputerPrefab, detailInfo); + var computerObject = DetailBuilder.Make(planetGO, sector, _preCrashComputerPrefab, detailInfo); computerObject.SetActive(false); if (!string.IsNullOrEmpty(info.rename)) @@ -414,7 +414,7 @@ namespace NewHorizons.Builder.Props rotation = info.rotation, position = info.position }; - var recorderObject = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); + var recorderObject = DetailBuilder.Make(planetGO, sector, prefab, detailInfo); recorderObject.SetActive(false); if (!string.IsNullOrEmpty(info.rename)) diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 72a78d3a..19e45099 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -228,7 +228,7 @@ namespace NewHorizons.Builder.Props position = info.position, scale = 2 }; - var g = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); + var g = DetailBuilder.Make(planetGO, sector, prefab, detailInfo); if (!string.IsNullOrEmpty(info.parentPath)) { @@ -294,7 +294,7 @@ namespace NewHorizons.Builder.Props position = info.position, rotation = info.rotation }; - var standingTorch = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); + var standingTorch = DetailBuilder.Make(planetGO, sector, prefab, detailInfo); if (!string.IsNullOrEmpty(info.parentPath)) { diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs index 9cfc911b..9090b76e 100644 --- a/NewHorizons/Builder/Props/RemoteBuilder.cs +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -155,7 +155,7 @@ namespace NewHorizons.Builder.Props position = info.position, rotation = info.rotation }; - var whiteboard = DetailBuilder.MakeDetail(go, sector, _whiteboardPrefab, detailInfo); + var whiteboard = DetailBuilder.Make(go, sector, _whiteboardPrefab, detailInfo); whiteboard.SetActive(false); if (!string.IsNullOrEmpty(info.rename)) @@ -218,7 +218,7 @@ namespace NewHorizons.Builder.Props position = info.position, rotation = info.rotation }; - var platform = DetailBuilder.MakeDetail(go, sector, _remoteCameraPlatformPrefab, detailInfo); + var platform = DetailBuilder.Make(go, sector, _remoteCameraPlatformPrefab, detailInfo); platform.SetActive(false); if (!string.IsNullOrEmpty(info.rename)) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 2816364e..26af9d33 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -98,7 +98,7 @@ namespace NewHorizons.Builder.Props scale = propInfo.scale, alignToNormal = true }; - var prop = DetailBuilder.MakeDetail(go, sector, prefab, detailInfo); + var prop = DetailBuilder.Make(go, sector, prefab, detailInfo); if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); if (propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 1ff9aeff..0ddb9f14 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -118,7 +118,7 @@ namespace NewHorizons scale = scale, alignToNormal = alignWithNormal }; - return DetailBuilder.MakeDetail(planet, sector, prefab, detailInfo); + return DetailBuilder.Make(planet, sector, prefab, detailInfo); } public AudioSignal SpawnSignal(IModBehaviour mod, GameObject root, string audio, string name, string frequency, diff --git a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs index 9e6f25d4..c3bb644c 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs @@ -120,7 +120,7 @@ namespace NewHorizons.Utility.DebugUtilities position = data.pos, rotation = data.norm, }; - var prop = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); + var prop = DetailBuilder.Make(planetGO, sector, prefab, detailInfo); var body = data.hitBodyGameObject.GetComponent(); if (body != null) RegisterProp(body, prop);