Ejemplo n.º 1
0
        private bool TrySnapFaces(Cuboid thisCuboid, List <Cuboid> otherCuboids, out Vector3 Displacement)
        {
            Displacement = Vector3.zero;
            if (thisFaceIndex == null && thatAdjacentFace == null)
            {
                thatAdjacentFace = GetClosestAdjacentFace(thisCuboid, otherCuboids, out thisFaceIndex);
            }

            if (thatAdjacentFace == null)
            {
                isSnapping = false;
                return(false);
            }


            var thisFace = thisCuboid.Faces[thisFaceIndex.Value];
            var thatFace = thatAdjacentFace;

            if (Face.CheckSnapping(thisFace, thatFace, m_Settings.SnappingDistance))
            {
                if (Vector3.Distance(thisFace.ProjectedPivot, thatFace.ProjectedPivot) < m_Settings.SnappingDistance)
                {
                    Displacement = thatFace.ProjectedPivot - thisFace.ProjectedPivot;
                }
                else
                {
                    Displacement = thatFace.GetProjectionVector(thisFace);
                }

                thisCuboid.HighlightFace(thisFace);
                isSnapping = true;
                return(true);
            }
            else
            {
                thisFaceIndex    = null;
                thatAdjacentFace = null;
                isSnapping       = false;
                return(false);
            }
        }