Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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;
                }

                var createdClones = new List <GameObject>(10);
                var cloneConfig   = ObjectCloning.DefaultConfig;
                var cloneOffset   = _handleDragExtrData.ExtrudeDir * boxSize;
                for (int cloneIndex = 0; cloneIndex < iNumClones; ++cloneIndex)
                {
                    foreach (var targetParent in _targetParents)
                    {
                        if (_ignoredParentObjects.Contains(targetParent))
                        {
                            continue;
                        }

                        if (!Hotkeys.EnableOverlapTest.IsActive())
                        {
                            cloneConfig.Parent = targetParent.transform.parent;
                            var 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);
                            var overlappedObjects = RTScene.Get.OverlapBox(targetOBB, _sceneOverlapFilter);
                            if (overlappedObjects.Count != 0)
                            {
                                continue;
                            }

                            cloneConfig.Parent = targetParent.transform.parent;
                            var 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 (var targetParent in _targetParents)
                {
                    if (!_ignoredParentObjects.Contains(targetParent))
                    {
                        targetParent.transform.position += Gizmo.RelativeDragOffset;
                    }
                }

                if (ExtrudeUpdate != null)
                {
                    ExtrudeUpdate(createdClones);
                }
            }
        }