mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
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:
40
Source/Restock/Constraints/CopyRotationConstraint.cs
Normal file
40
Source/Restock/Constraints/CopyRotationConstraint.cs
Normal file
@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user