private static Vector2 SnapRadial(Vector3 aWorldPt, Vector2 aOriginalPoint, Vector2 aNewPoint, Matrix4x4 aTransform, Matrix4x4 aInvTransform, PathSnap aSnapMode = PathSnap.Unity) { Vector2 result = aNewPoint; if (!Event.current.control) { return(result); } float angleSnap = EditorTools.GetUnityRotationSnap(); float magnitudeSnap = EditorTools.GetUnityScaleSnap(); Vector2 src = aNewPoint; if (aSnapMode == PathSnap.Local) { src = aNewPoint; } if (aSnapMode == PathSnap.World) { src = aInvTransform.MultiplyVector(aNewPoint); } if (aSnapMode == PathSnap.Relative) { src = aNewPoint; } Vector2 polar = new Vector2(PathUtil.ClockwiseAngle(src, Vector2.right), src.magnitude); Vector3 polarSnap = new Vector3(angleSnap, magnitudeSnap, 0); polar = SnapVector(polar, polarSnap); polar.x *= Mathf.Deg2Rad; result = new Vector2(Mathf.Cos(polar.x) * polar.y, Mathf.Sin(polar.x) * polar.y); if (aSnapMode == PathSnap.World) { result = aInvTransform.MultiplyVector(result); } return(result); }
private static float SnapScale(float aOriginalScale, float aNewScale, PathSnap aSnapMode = PathSnap.Unity) { float result = aNewScale; if (!Event.current.control) { return(result); } float snap = EditorTools.GetUnityScaleSnap(); if (aSnapMode == PathSnap.Local || aSnapMode == PathSnap.World) { result = SnapScalar(aNewScale, snap); } if (aSnapMode == PathSnap.Relative) { result = aOriginalScale + SnapScalar(aNewScale - aOriginalScale, snap); } return(result); }