mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add parentPath to scatter
This commit is contained in:
parent
fb9e10fee7
commit
3265f8b076
@ -3,6 +3,7 @@ using NewHorizons.External.Modules.Props;
|
||||
using NewHorizons.Utility;
|
||||
using NewHorizons.Utility.Files;
|
||||
using NewHorizons.Utility.Geometry;
|
||||
using NewHorizons.Utility.OWML;
|
||||
using OWML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -120,10 +121,27 @@ namespace NewHorizons.Builder.Props
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var parent = sector?.transform ?? go.transform;
|
||||
|
||||
if (go != null && !string.IsNullOrEmpty(propInfo.parentPath))
|
||||
{
|
||||
var newParent = go.transform.Find(propInfo.parentPath);
|
||||
if (newParent != null)
|
||||
{
|
||||
parent = newParent;
|
||||
sector = newParent.GetComponentInParent<Sector>();
|
||||
}
|
||||
else
|
||||
{
|
||||
NHLogger.LogError($"Cannot find parent object at path: {go.name}/{propInfo.parentPath}");
|
||||
}
|
||||
}
|
||||
|
||||
var prop = scatterPrefab.InstantiateInactive();
|
||||
prop.transform.SetParent(sector?.transform ?? go.transform);
|
||||
prop.transform.localPosition = go.transform.TransformPoint(point * height);
|
||||
var up = go.transform.InverseTransformPoint(prop.transform.position).normalized;
|
||||
prop.transform.SetParent(parent, false);
|
||||
prop.transform.position = go.transform.TransformPoint(point * height);
|
||||
var up = (prop.transform.position - go.transform.position).normalized;
|
||||
prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up);
|
||||
|
||||
if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset);
|
||||
|
||||
@ -66,5 +66,10 @@ namespace NewHorizons.External.Modules.Props
|
||||
/// Should this detail stay loaded even if you're outside the sector (good for very large props)
|
||||
/// </summary>
|
||||
public bool keepLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// The relative path from the planet to the parent of this object. Optional (will default to the root sector).
|
||||
/// </summary>
|
||||
public string parentPath;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user