public void Execute() { if (_rootsToDuplicate.Count != 0) { ObjectCloning.Config cloneConfig = ObjectCloning.DefaultConfig; foreach (GameObject root in _rootsToDuplicate) { Transform rootTransform = root.transform; cloneConfig.Layer = root.layer; cloneConfig.Parent = rootTransform.parent; GameObject clonedRoot = ObjectCloning.CloneHierarchy(root, cloneConfig); _duplicateResult.Add(clonedRoot); } RTUndoRedo.Get.RecordAction(this); } }
public override void OnGizmoDragUpdate(int handleId) { if (OwnsHandle(handleId) && Gizmo.RelativeDragOffset.magnitude != 0.0f) { float extrAmount = Gizmo.RelativeDragOffset.magnitude; float boxSize = _boxSize[_handleDragExtrData.AxisIndex]; float fNumClones = boxSize != 0.0f ? (extrAmount / boxSize) : 0.0f; int iNumClones = (int)fNumClones; float absFractional = Mathf.Abs(fNumClones - (int)fNumClones); if (iNumClones == 0 && Mathf.Abs(absFractional - 1.0f) < 1e-5f) { ++iNumClones; } List <GameObject> createdClones = new List <GameObject>(10); ObjectCloning.Config cloneConfig = ObjectCloning.DefaultConfig; Vector3 cloneOffset = _handleDragExtrData.ExtrudeDir * boxSize; for (int cloneIndex = 0; cloneIndex < iNumClones; ++cloneIndex) { foreach (GameObject targetParent in _targetParents) { if (_ignoredParentObjects.Contains(targetParent)) { continue; } if (!Hotkeys.EnableOverlapTest.IsActive()) { cloneConfig.Parent = targetParent.transform.parent; GameObject clonedHierarchy = ObjectCloning.CloneHierarchy(targetParent, cloneConfig); if (clonedHierarchy != null) { _sceneOverlapFilter.IgnoreObjects.AddRange(clonedHierarchy.GetAllChildrenAndSelf()); _dragEndAction.AddExtrudeClone(clonedHierarchy); createdClones.Add(clonedHierarchy); } clonedHierarchy.transform.position += cloneIndex * cloneOffset; } else { OBB targetOBB = ObjectBounds.CalcHierarchyWorldOBB(targetParent, _boundsQConfig); if (!targetOBB.IsValid) { continue; } targetOBB.Center += cloneIndex * cloneOffset; // Bring the size down a tad. Otherwise, we can get false positives when objects are really close to // each other even if they do not intersect. targetOBB.Inflate(-1e-2f); List <GameObject> overlappedObjects = RTScene.Get.OverlapBox(targetOBB, _sceneOverlapFilter); if (overlappedObjects.Count != 0) { continue; } cloneConfig.Parent = targetParent.transform.parent; GameObject clonedHierarchy = ObjectCloning.CloneHierarchy(targetParent, cloneConfig); if (clonedHierarchy != null) { _sceneOverlapFilter.IgnoreObjects.AddRange(clonedHierarchy.GetAllChildrenAndSelf()); _dragEndAction.AddExtrudeClone(clonedHierarchy); createdClones.Add(clonedHierarchy); } clonedHierarchy.transform.position += cloneIndex * cloneOffset; } } } _handleDragExtrData.ExtrudeCenter += Gizmo.RelativeDragOffset; foreach (GameObject targetParent in _targetParents) { if (!_ignoredParentObjects.Contains(targetParent)) { targetParent.transform.position += Gizmo.RelativeDragOffset; } } if (ExtrudeUpdate != null) { ExtrudeUpdate(createdClones); } } }