mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix parent path fetching
This commit is contained in:
parent
d8f5f71249
commit
af96853afb
@ -18,10 +18,11 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
if (info is PropModule.GeneralSolarSystemPropInfo solarSystemInfo && !string.IsNullOrEmpty(solarSystemInfo.parentBody))
|
if (info is PropModule.GeneralSolarSystemPropInfo solarSystemInfo && !string.IsNullOrEmpty(solarSystemInfo.parentBody))
|
||||||
{
|
{
|
||||||
|
// This can fail if the prop is built before the target planet. Only use it for SolarSystem module props
|
||||||
var targetPlanet = AstroObjectLocator.GetAstroObject(solarSystemInfo.parentBody);
|
var targetPlanet = AstroObjectLocator.GetAstroObject(solarSystemInfo.parentBody);
|
||||||
if (targetPlanet != null)
|
if (targetPlanet != null)
|
||||||
{
|
{
|
||||||
parent = targetPlanet.transform;
|
parent = targetPlanet._rootSector?.transform ?? targetPlanet.transform;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
Logger.LogError($"Cannot find parent body named {solarSystemInfo.parentBody}");
|
Logger.LogError($"Cannot find parent body named {solarSystemInfo.parentBody}");
|
||||||
@ -37,16 +38,16 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
var parentPath = info.parentPath ?? defaultParentPath;
|
var parentPath = info.parentPath ?? defaultParentPath;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(parentPath))
|
if (parent && !string.IsNullOrEmpty(parentPath))
|
||||||
{
|
{
|
||||||
var newParent = go.transform.Find(parentPath);
|
var newParent = parent.root.transform.Find(parentPath);
|
||||||
if (newParent != null)
|
if (newParent != null)
|
||||||
{
|
{
|
||||||
go.transform.parent = newParent.transform;
|
go.transform.parent = newParent.transform;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogError($"Cannot find parent object at path: {go.name}/{parentPath}");
|
Logger.LogError($"Cannot find parent object at path: {parent.name}/{parentPath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +63,8 @@ namespace NewHorizons.Builder.Props
|
|||||||
go.transform.localRotation = rot;
|
go.transform.localRotation = rot;
|
||||||
} else if (parent)
|
} else if (parent)
|
||||||
{
|
{
|
||||||
go.transform.position = parent.root.TransformPoint(pos);
|
go.transform.position = parent.root.transform.TransformPoint(pos);
|
||||||
go.transform.rotation = parent.root.TransformRotation(rot);
|
go.transform.rotation = parent.root.transform.TransformRotation(rot);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
go.transform.position = pos;
|
go.transform.position = pos;
|
||||||
@ -71,10 +72,9 @@ namespace NewHorizons.Builder.Props
|
|||||||
}
|
}
|
||||||
if (alignToBody)
|
if (alignToBody)
|
||||||
{
|
{
|
||||||
var up = (go.transform.position - parent.position).normalized;
|
var up = (go.transform.position - parent.root.position).normalized;
|
||||||
if (normal != null) up = parent.TransformDirection(normal);
|
if (normal != null) up = parent.TransformDirection(normal);
|
||||||
go.transform.rotation = Quaternion.FromToRotation(Vector3.up, up);
|
go.transform.rotation = Quaternion.FromToRotation(go.transform.up, up) * rot;
|
||||||
go.transform.rotation *= rot;
|
|
||||||
}
|
}
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user