Convert ModuleRestockLookAtConstrain into ModuleRestockConstraints

New module is extendable and modular, allowing constraints to be run in the expected order without relying on possibly undefined behavior
This commit is contained in:
2020-01-30 18:37:27 -08:00
parent 073b7d2948
commit 931d891644
12 changed files with 255 additions and 189 deletions

View File

@ -0,0 +1,40 @@
using UnityEngine;
namespace Restock.Constraints
{
[System.Serializable]
public class CopyPositionConstraint : IConstraint
{
private readonly string moversName;
private readonly string targetName;
private readonly bool local = false;
// Cached components
private readonly Transform mover;
private readonly Transform target;
public CopyPositionConstraint(ConfigNode node, Part p)
{
node.TryGetValue("rotatorsName", ref moversName);
node.TryGetValue("targetName", ref targetName);
mover = p.FindModelTransform(moversName);
target = p.FindModelTransform(targetName);
}
public void Update()
{
if (mover == null || target == null) return;
if (local)
{
mover.localPosition = target.localPosition;
}
else
{
mover.position = target.position;
}
}
}
}