private bool TrySnapPivot(Cuboid thisCuboid, List <Cuboid> otherCuboids, out Vector3 Displacement) { Displacement = Vector3.zero; float minDistance; if (m_PeerIndex == null) { m_PeerIndex = otherCuboids.IndexOfMinBy(peer => Vector3.Distance(thisCuboid.Pivot, peer.Pivot), out minDistance); } else { minDistance = Vector3.Distance(thisCuboid.Pivot, otherCuboids[m_PeerIndex.Value].Pivot); } if (minDistance <= m_Settings.SnappingDistance) { Displacement = otherCuboids[m_PeerIndex.Value].Pivot - thisCuboid.Pivot; isSnapping = true; thisCuboid.ChangeHighlightColor(new Color(1, 0.5f, 0)); otherCuboids[m_PeerIndex.Value].ChangeHighlightColor(new Color(1, 0.5f, 0)); return(true); } if (m_PeerIndex != null) { otherCuboids[m_PeerIndex.Value].ChangeHighlightColor(Color.cyan); } m_PeerIndex = null; isSnapping = false; return(false); }