mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Probably fixes duplicate OrbitLines
This commit is contained in:
parent
0ac18fcbe9
commit
cfd4fc3750
@ -10,16 +10,25 @@ namespace NewHorizons.Builder.Orbital
|
||||
private static Material _dottedLineMaterial;
|
||||
private static Material _lineMaterial;
|
||||
|
||||
public static OrbitLine Make(GameObject planetGO, NHAstroObject astroObject, bool isMoon, PlanetConfig config)
|
||||
public static GameObject Make(GameObject planetGO, bool isMoon, PlanetConfig config)
|
||||
{
|
||||
var orbitGO = new GameObject("Orbit");
|
||||
orbitGO.transform.parent = planetGO.transform;
|
||||
orbitGO.transform.localPosition = Vector3.zero;
|
||||
|
||||
Delay.FireOnNextUpdate(() => PostMake(orbitGO, planetGO, isMoon, config));
|
||||
return orbitGO;
|
||||
}
|
||||
|
||||
private static void PostMake(GameObject orbitGO, GameObject planetGO, bool isMoon, PlanetConfig config)
|
||||
{
|
||||
if (_dottedLineMaterial == null) _dottedLineMaterial = SearchUtilities.FindResourceOfTypeAndName<Material>("Effects_SPA_OrbitLine_Dotted_mat");
|
||||
if (_lineMaterial == null) _lineMaterial = SearchUtilities.FindResourceOfTypeAndName<Material>("Effects_SPA_OrbitLine_mat");
|
||||
|
||||
if (_dottedLineMaterial == null || _lineMaterial == null) return null;
|
||||
// Might've been otherwise destroyed when updating
|
||||
if (orbitGO == null) return;
|
||||
|
||||
var orbitGO = new GameObject("Orbit");
|
||||
orbitGO.transform.parent = planetGO.transform;
|
||||
orbitGO.transform.localPosition = Vector3.zero;
|
||||
var astroObject = planetGO.GetComponent<NHAstroObject>();
|
||||
|
||||
var lineRenderer = orbitGO.AddComponent<LineRenderer>();
|
||||
|
||||
@ -47,7 +56,6 @@ namespace NewHorizons.Builder.Orbital
|
||||
else
|
||||
{
|
||||
orbitLine = orbitGO.AddComponent<NHOrbitLine>();
|
||||
|
||||
(orbitLine as NHOrbitLine).SetFromParameters(astroObject);
|
||||
}
|
||||
|
||||
@ -94,8 +102,6 @@ namespace NewHorizons.Builder.Orbital
|
||||
orbitGO.SetActive(false);
|
||||
};
|
||||
}
|
||||
|
||||
return orbitLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -506,7 +506,7 @@ namespace NewHorizons.Handlers
|
||||
|
||||
if (body.Config.Orbit.showOrbitLine && !body.Config.Orbit.isStatic)
|
||||
{
|
||||
Delay.FireOnNextUpdate(() => OrbitlineBuilder.Make(body.Object, ao, body.Config.Orbit.isMoon, body.Config));
|
||||
OrbitlineBuilder.Make(body.Object, body.Config.Orbit.isMoon, body.Config);
|
||||
}
|
||||
|
||||
DetectorBuilder.Make(go, owRigidBody, primaryBody, ao, body.Config);
|
||||
@ -813,11 +813,18 @@ namespace NewHorizons.Handlers
|
||||
if (referenceFrame != null) referenceFrame._attachedAstroObject = newAO;
|
||||
|
||||
// QM and stuff don't have orbit lines
|
||||
var orbitLine = go.GetComponentInChildren<OrbitLine>()?.gameObject;
|
||||
if (orbitLine != null) UnityEngine.Object.Destroy(orbitLine);
|
||||
// Using the name since NH only creates the OrbitLine components next frame
|
||||
var orbitLine = go.transform.Find("Orbit")?.gameObject;
|
||||
if (orbitLine != null)
|
||||
{
|
||||
UnityEngine.Object.Destroy(orbitLine);
|
||||
}
|
||||
|
||||
var isMoon = newAO.GetAstroObjectType() is AstroObject.Type.Moon or AstroObject.Type.Satellite or AstroObject.Type.SpaceStation;
|
||||
if (body.Config.Orbit.showOrbitLine) OrbitlineBuilder.Make(go, newAO, isMoon, body.Config);
|
||||
if (body.Config.Orbit.showOrbitLine)
|
||||
{
|
||||
OrbitlineBuilder.Make(go, isMoon, body.Config);
|
||||
}
|
||||
|
||||
DetectorBuilder.SetDetector(primary, newAO, go.GetComponentInChildren<ConstantForceDetector>());
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user