Editor拡張で極めてできの悪いSnapを書く
これは何?
不要不急の必要に迫られ、なんとも言えない理由により自作を迫られたため、備忘だとばかりに書きなぐりました。
普通の生き方をしていたら不要ですが、事情があったのです。

参考にならないかもしれないスクリプト本体
間隔を決める
using UnityEditor;
using UnityEngine;
namespace ObjectSnapping
{
public class ObjectSnappingMaster : EditorWindow
{
[MenuItem("ObjectSnapping/Window")]
private static void Open()
{
GetWindow<ObjectSnappingMaster>("Snapping object in scene.");
}
public static Vector2 GetSnapDistance => _sampleVector2;
private static Vector2 _sampleVector2;
public void OnGUI()
{
using (new GUILayout.HorizontalScope())
{
_sampleVector2 = EditorGUILayout.Vector2Field("Snapping distance", _sampleVector2);
}
}
}
}Snapしたいものに付ける
using UnityEditor;
using UnityEngine;
namespace ObjectSnapping
{
[ExecuteInEditMode]
public class ObjectSnapper : MonoBehaviour
{
private void OnEnable()
{
SceneView.onSceneGUIDelegate += OnEventInSceneView;
}
private void OnEventInSceneView(SceneView scene)
{
if (Event.current.type == EventType.MouseUp)
{
Vector2 current = transform.position;
Vector2 targetPosition = current - (new Vector2(current.x % ObjectSnappingMaster.GetSnapDistance.x,
current.y % ObjectSnappingMaster.GetSnapDistance.y));
Debug.Log($"current {current} target {targetPosition}");
transform.position = targetPosition;
}
}
}
}