56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
using Wing.Utils;
|
|
|
|
namespace Wing.Gizmos
|
|
{
|
|
public class AngleSnap : SnapBase
|
|
{
|
|
public Vector3 Center = Vector3.zero;
|
|
|
|
private float mAngle = 0;
|
|
public float CurrentAngle
|
|
{
|
|
get
|
|
{
|
|
return mAngle;
|
|
}
|
|
}
|
|
public AngleSnap()
|
|
{
|
|
Precision = 15;
|
|
}
|
|
|
|
protected override void CalcTolerance()
|
|
{
|
|
mTolerance = 0.2f * Precision;
|
|
}
|
|
|
|
public override bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
|
|
{
|
|
if (!Enable)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Vector3 dir = inVal.normalized;
|
|
float angle = GemetryHelper.VectorAngle(Vector3.right, dir);
|
|
|
|
mAngle = GemetryHelper.ValueMod(angle, Precision);
|
|
|
|
if (force || Mathf.Abs(angle - mAngle) <= Precision)
|
|
{
|
|
outVal = Quaternion.Euler(0, mAngle, 0) * Vector3.right;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|