38 lines
1.2 KiB
C#

using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
namespace Streamingle.Utils.LerpConstraints
{
[MovedFrom(true, "Streamingle.Utils.RoughConstraints", "Assembly-CSharp", "RoughScaleConstraint")]
[ExecuteAlways]
[AddComponentMenu("Streamingle Utilities/Constraints/Lerp Scale Constraint")]
public class LerpScaleConstraint : LerpConstraintBase
{
[Header("Scale")]
public Vector3Bool constrainedAxis = Vector3Bool.All;
public Vector3 scaleOffset;
protected override void ExecuteConstraint(float followT)
{
if (!TryGetWeightedScale(out var targetScale))
{
return;
}
targetScale += scaleOffset;
targetScale = ApplyAxisMask(transform.localScale, targetScale, constrainedAxis);
transform.localScale = Vector3.Lerp(transform.localScale, targetScale, followT * weight);
}
protected override void CaptureOffsetsFromCurrentPose()
{
if (!TryGetWeightedScale(out var sourceScale))
{
return;
}
scaleOffset = transform.localScale - sourceScale;
}
}
}