Snapping.cs 565 B

123456789101112131415161718192021
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace UnityEditor.Experimental.Rendering.Universal.Path2D
  4. {
  5. internal class Snapping : ISnapping<Vector3>
  6. {
  7. public Vector3 Snap(Vector3 position)
  8. {
  9. return new Vector3(
  10. Snap(position.x, EditorPrefs.GetFloat("MoveSnapX", 1f)),
  11. Snap(position.y, EditorPrefs.GetFloat("MoveSnapY", 1f)),
  12. position.z);
  13. }
  14. private float Snap(float value, float snap)
  15. {
  16. return Mathf.Round(value / snap) * snap;
  17. }
  18. }
  19. }