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.
ReStocked/Source/Restock/Constraints/CopyRotationConstraint.cs

40 lines
1.1 KiB
C#

using UnityEngine;
namespace Restock.Constraints
{
[System.Serializable]
public class CopyRotationConstraint : IConstraint
{
private readonly string rotatorsName;
private readonly string targetName;
private readonly bool local = false;
// Cached components
private readonly Transform target;
private readonly Transform rotator;
public CopyRotationConstraint(ConfigNode node, Part p)
{
node.TryGetValue("rotatorsName", ref rotatorsName);
node.TryGetValue("targetName", ref targetName);
rotator = p.FindModelTransform(rotatorsName);
target = p.FindModelTransform(targetName);
}
public void Update()
{
if (rotator == null || target == null) return;
if (local)
{
rotator.localRotation = target.localRotation;
}
else
{
rotator.rotation = target.rotation;
}
}
}
}