示例#1
0
 public void SnapHierarchyToNearbyObjects(GameObject hierarchyRoot, ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints)
 {
     Object2ObjectSnap.SnapResult snapResult = Object2ObjectSnap.Snap(hierarchyRoot, Settings.ObjectToObjectSnapEpsilon, ObjectSnapping.Get().ObjectSnapMask.ObjectCollectionMask.GetAllMaskedGameObjects());
     if (snapResult.WasSnapped)
     {
         projectedBoxFacePivotPoints.MovePoints(snapResult.SnapDestination - snapResult.SnapPivot);
     }
 }
示例#2
0
        public void UpdateOnMouseMove()
        {
            if (_isActive)
            {
                MouseCursorRayHit cursorRayHit = GetCursorRayHit();
                if (cursorRayHit == null || !cursorRayHit.WasAnythingHit)
                {
                    return;
                }

                Vector3 hitPoint  = Vector3.zero;
                Vector3 hitNormal = Vector3.zero;

                if (!cursorRayHit.WasAnObjectHit && cursorRayHit.WasACellHit)
                {
                    hitPoint  = cursorRayHit.GridCellRayHit.HitPoint;
                    hitNormal = cursorRayHit.GridCellRayHit.HitNormal;
                }
                else
                if (cursorRayHit.WasAnObjectHit && !cursorRayHit.WasACellHit)
                {
                    hitPoint  = cursorRayHit.ClosestObjectRayHit.HitPoint;
                    hitNormal = cursorRayHit.ClosestObjectRayHit.HitNormal;
                }
                else
                if (cursorRayHit.WasAnObjectHit && cursorRayHit.WasACellHit)
                {
                    if (cursorRayHit.ClosestObjectRayHit.HitEnter < cursorRayHit.GridCellRayHit.HitEnter)
                    {
                        hitPoint  = cursorRayHit.ClosestObjectRayHit.HitPoint;
                        hitNormal = cursorRayHit.ClosestObjectRayHit.HitNormal;
                    }
                    else
                    {
                        hitPoint  = cursorRayHit.GridCellRayHit.HitPoint;
                        hitNormal = cursorRayHit.GridCellRayHit.HitNormal;
                    }
                }

                Plane hitPlane           = new Plane(hitNormal, hitPoint);
                Box   selectionWorldAABB = ObjectSelection.Get().GetWorldBox();
                if (selectionWorldAABB.IsInvalid())
                {
                    return;
                }

                Vector3 oldCenter = selectionWorldAABB.Center;
                selectionWorldAABB.Center = hitPoint;
                selectionWorldAABB.MoveInFrontOfPlane(hitPlane);
                Vector3 moveVector = selectionWorldAABB.Center - oldCenter;

                float snapEps = ObjectSelection.Get().Settings.Object2ObjectSnapSettings.SnapEps;

                GameObjectExtensions.RecordObjectTransformsForUndo(_selectedParents);
                foreach (var parent in _selectedParents)
                {
                    parent.transform.position += moveVector;
                }

                var ignoreObjects = new List <GameObject>(_allSelectedObjects);
                ignoreObjects.AddRange(ObjectSnapping.Get().ObjectSnapMask.ObjectCollectionMask.GetAllMaskedGameObjects());
                Object2ObjectSnap.Snap(_selectedParents, snapEps, ignoreObjects);
            }
        }