48 lines
1023 B
C#
Raw Normal View History

2026-05-07 10:14:44 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Wing.Utils;
namespace Wing.Gizmos
{
public class MoveSnap : SnapBase
{
public Vector3 Center = Vector3.zero;
public MoveSnap()
{
Precision = 1;
}
protected override void CalcTolerance()
{
mTolerance = 0.05f * Precision;
}
public override bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
{
if (!Enable)
{
return false;
}
Vector3 position = inVal;
Vector3 offset = position - Center;
Vector3 dp = GemetryHelper.Vector3Mod(offset, Precision);
if (force || (position - dp).magnitude <= mTolerance)
{
outVal = dp;
return true;
}
else
{
return false;
}
}
}
}