You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
} |