mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
drewcassidy
85ab757271
• Pretty up some code for consistency • Add documentation to constraint modules • Fix key name for copy position constraint
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace Restock.Constraints
|
|
{
|
|
[System.Serializable]
|
|
/**
|
|
* Copies the rotation of the target object to the rotator object.
|
|
* If `IsLocal` is true, uses local rotation instead of global rotation.
|
|
*/
|
|
public class CopyRotationConstraint : IConstraint
|
|
{
|
|
private readonly string rotatorsName;
|
|
private readonly string targetName;
|
|
|
|
private readonly bool local = false;
|
|
|
|
// Cached components
|
|
private readonly Transform rotator;
|
|
private readonly Transform target;
|
|
|
|
public CopyRotationConstraint(ConfigNode node, Part p)
|
|
{
|
|
node.TryGetValue("rotatorsName", ref rotatorsName);
|
|
node.TryGetValue("targetName", ref targetName);
|
|
node.TryGetValue("isLocal", ref local);
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |