Exemplo n.º 1
0
        public static void DuplicateSelection()
        {
            if (ObjectSelection.Get().NumberOfSelectedObjects == 0)
            {
                return;
            }

            ObjectSelection   objectSelection    = ObjectSelection.Get();
            List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects();
            List <GameObject> selectedParents    = GameObjectExtensions.GetParents(allSelectedObjects);

            var clonedObjects = new List <GameObject>();
            var clonedParents = new List <GameObject>();

            foreach (GameObject parent in selectedParents)
            {
                GameObject prefab          = parent.GetSourcePrefab();
                Transform  parentTransform = parent.transform;

                if (prefab == null)
                {
                    GameObject clonedParent = parent.CloneAsWorkingObject(parentTransform.parent);
                    //clonedParent.transform.parent = parent.transform.parent;
                    clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf());
                    Octave3DScene.Get().RegisterObjectHierarchy(clonedParent);
                    clonedParents.Add(clonedParent);
                }
                else
                {
                    GameObject clonedParent = ObjectInstantiation.InstantiateObjectHierarchyFromPrefab(prefab, parentTransform.position, parentTransform.rotation, parentTransform.lossyScale);
                    clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf());
                    Octave3DScene.Get().RegisterObjectHierarchy(clonedParent);
                    clonedParents.Add(clonedParent);
                }
            }

            if (clonedObjects.Count != 0)
            {
                objectSelection.Clear();
                objectSelection.AddGameObjectCollectionToSelection(clonedObjects);
                objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdated();
            }

            if (clonedParents.Count != 0)
            {
                ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(clonedParents, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection);
            }

            SceneViewCamera.Instance.SetObjectVisibilityDirty();
        }
Exemplo n.º 2
0
        public static void SelectAllObjectsWithSamePrefabAsCurrentSelection()
        {
            ObjectSelection   objectSelection    = ObjectSelection.Get();
            List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects();
            Dictionary <GameObject, GameObject> prefabToObjectMappings = ObjectQueries.GetPrefabToObjectConnectionMappings(allSelectedObjects);

            List <GameObject> workingObjects = Octave3DWorldBuilder.ActiveInstance.GetAllWorkingObjects();

            foreach (GameObject gameObject in workingObjects)
            {
                GameObject sourcePrefab = gameObject.GetSourcePrefab();
                if (sourcePrefab != null)
                {
                    if (prefabToObjectMappings.ContainsKey(sourcePrefab))
                    {
                        objectSelection.AddGameObjectToSelection(gameObject);
                    }
                }
            }
        }
        public static void DuplicateSelection()
        {
            if (ObjectSelection.Get().NumberOfSelectedObjects == 0)
            {
                return;
            }

            ObjectSelection   objectSelection    = ObjectSelection.Get();
            List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects();
            List <GameObject> selectedParents    = GameObjectExtensions.GetTopParentsFromGameObjectCollection(allSelectedObjects);

            var clonedObjects = new List <GameObject>();

            foreach (GameObject parent in selectedParents)
            {
                GameObject prefab          = parent.GetSourcePrefab();
                Transform  parentTransform = parent.transform;

                if (prefab == null)
                {
                    GameObject clonedParent = parent.CloneAsWorkingObject(parentTransform.parent);
                    //clonedParent.transform.parent = parent.transform.parent;
                    clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf());
                }
                else
                {
                    GameObject clonedParent = ObjectInstantiation.InstantiateObjectHierarchyFromPrefab(prefab, parentTransform.position, parentTransform.rotation, parentTransform.lossyScale);
                    clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf());
                }
            }

            if (clonedObjects.Count != 0)
            {
                objectSelection.Clear();
                objectSelection.AddGameObjectCollectionToSelection(clonedObjects);
                objectSelection.ObjectSelectionTransformGizmoSystem.OnObjectSelectionUpdated();
            }
        }