Ejemplo n.º 1
0
        public static void SelectAllObjectsWithSamePrefabAsObject(GameObject gameObject)
        {
            GameObject root = Octave3DWorldBuilder.ActiveInstance.GetRoot(gameObject);

            if (root == null)
            {
                return;
            }

            GameObject sourcePrefab = root.GetSourcePrefab();

            if (sourcePrefab == null)
            {
                return;
            }

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

            foreach (GameObject workingObject in workingObjects)
            {
                GameObject workingObjectRoot = Octave3DWorldBuilder.ActiveInstance.GetRoot(workingObject);
                if (workingObjectRoot == null)
                {
                    continue;
                }

                GameObject workingObjectSourcePrefab = workingObjectRoot.GetSourcePrefab();
                if (workingObjectSourcePrefab != null &&
                    workingObjectSourcePrefab == sourcePrefab)
                {
                    objectSelection.AddGameObjectCollectionToSelection(workingObjectRoot.GetAllChildrenIncludingSelf());
                }
            }
        }
Ejemplo n.º 2
0
        private void AppendObjectsToSelection(List <GameObject> gameObjectsOverlappedBySelectionShape)
        {
            if (gameObjectsOverlappedBySelectionShape.Count != 0)
            {
                ObjectSelection           objectSelection      = ObjectSelection.Get();
                ObjectSelectionUpdateMode _selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode;

                // Note: We only continue if the current object selection is not the same as the
                //       collection of objects we are appending. If it is, we would be registering
                //       an unnecessary Undo operation.
                if (!objectSelection.IsSameAs(gameObjectsOverlappedBySelectionShape))
                {
                    if (_selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy)
                    {
                        UndoEx.RecordForToolAction(objectSelection);
                        objectSelection.AddEntireGameObjectHierarchyToSelection(gameObjectsOverlappedBySelectionShape);
                    }
                    else
                    {
                        UndoEx.RecordForToolAction(objectSelection);
                        objectSelection.AddGameObjectCollectionToSelection(gameObjectsOverlappedBySelectionShape);
                    }
                    objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingSelectionShape();
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateSelectionForNoAppendAndNoDeselect(List <GameObject> gameObjectsOverlappedBySelectionShape)
        {
            ObjectSelection           objectSelection      = ObjectSelection.Get();
            ObjectSelectionUpdateMode _selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode;

            // If no object was overlapped by the selection shape, we can clear the selection.
            // Note: We only clear the selection if the current number of selected objects is not 0. This
            //       allows us to avoid registering an Undo for nothing.
            if (gameObjectsOverlappedBySelectionShape.Count == 0 && objectSelection.NumberOfSelectedObjects != 0)
            {
                UndoEx.RecordForToolAction(objectSelection);
                objectSelection.Clear();
            }
            else
            // When the selection shape has overlapped objects, we must reset the selection by clearing it and selecting only
            // the objects which were overlapped.
            if (gameObjectsOverlappedBySelectionShape.Count != 0)
            {
                UndoEx.RecordForToolAction(objectSelection);
                objectSelection.Clear();

                if (_selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy)
                {
                    objectSelection.AddEntireGameObjectHierarchyToSelection(gameObjectsOverlappedBySelectionShape);
                }
                else
                {
                    objectSelection.AddGameObjectCollectionToSelection(gameObjectsOverlappedBySelectionShape);
                }
                objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingSelectionShape();
            }
        }
Ejemplo n.º 4
0
        public static void AppendAllObjectsInLayerToSelection(int objectLayer)
        {
            List <GameObject> allObjectsInLayer = ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer);

            ObjectSelection objectSelection = ObjectSelection.Get();

            objectSelection.AddGameObjectCollectionToSelection(allObjectsInLayer);
            ObjectSelection.Get().ObjectSelectionGizmos.OnObjectSelectionUpdated();
        }
        public static void SelectAllObjectsInLayer(int objectLayer)
        {
            List <GameObject> allObjectsInLayer = ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer);

            ObjectSelection objectSelection = ObjectSelection.Get();

            objectSelection.Clear();
            objectSelection.AddGameObjectCollectionToSelection(allObjectsInLayer);
            ObjectSelection.Get().ObjectSelectionTransformGizmoSystem.OnObjectSelectionUpdated();
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        public static void SelectAllObjectsInAllLayers()
        {
            ObjectSelection objectSelection = ObjectSelection.Get();

            objectSelection.Clear();

            List <int> allLayers = ObjectLayerDatabase.Get().GetAllObjectLayers();

            foreach (int objectLayer in allLayers)
            {
                objectSelection.AddGameObjectCollectionToSelection(ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer));
            }
            ObjectSelection.Get().ObjectSelectionGizmos.OnObjectSelectionUpdated();
        }
Ejemplo n.º 8
0
        public static void InvertSelection()
        {
            List <GameObject> allWorkingObjects = Octave3DWorldBuilder.ActiveInstance.GetAllWorkingObjects();
            List <GameObject> objectsToSelect   = new List <GameObject>();
            ObjectSelection   objectSelection   = ObjectSelection.Get();

            foreach (var gameObject in allWorkingObjects)
            {
                if (!objectSelection.IsGameObjectSelected(gameObject))
                {
                    objectsToSelect.Add(gameObject);
                }
            }

            objectSelection.Clear();
            objectSelection.AddGameObjectCollectionToSelection(objectsToSelect);
            objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdated();
        }
        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();
            }
        }