private void OnDestroy()
 {
     if (_uniformScaleRandomizationSettings != null)
     {
         UndoEx.DestroyObjectImmediate(_uniformScaleRandomizationSettings);
     }
 }
        public void RemoveAndDestroyAllObjectGroups()
        {
            List <ObjectGroup> allGroups = GetAllObjectGroups();
            var groupsToDestroy          = new List <ObjectGroup>();

            foreach (ObjectGroup objectGroup in allGroups)
            {
                _objectGroups.RemoveEntity(objectGroup);
                groupsToDestroy.Add(objectGroup);
            }

            foreach (ObjectGroup objectGroup in allGroups)
            {
                GameObject groupParent = objectGroup.GroupObject;
                if (_preserveGroupChildren)
                {
                    groupParent.MoveImmediateChildrenUpOneLevel(true);
                }
                if (groupParent != null)
                {
                    UndoEx.DestroyObjectImmediate(groupParent);
                }
                UndoEx.DestroyObjectImmediate(objectGroup);
            }

            PrefabManagementWindow.Get().Repaint();
        }
        public void RemoveAndDestroyAllPrefabCategories(bool showProgresBar = false)
        {
            List <PrefabCategory> allPrefabCategories = GetAllPrefabCategories();
            var prefabCategoriesToDestroy             = new List <PrefabCategory>();

            foreach (PrefabCategory prefabCategory in allPrefabCategories)
            {
                if (CanPrefabCategoryBeRemovedFromDatabase(prefabCategory))
                {
                    _prefabCategories.RemoveEntity(prefabCategory);
                    PrefabCategoryWasRemovedFromDatabaseMessage.SendToInterestedListeners(prefabCategory);

                    prefabCategoriesToDestroy.Add(prefabCategory);
                }
            }

            if (showProgresBar)
            {
                for (int categoryIndex = 0; categoryIndex < prefabCategoriesToDestroy.Count; ++categoryIndex)
                {
                    PrefabCategory prefabCategory = prefabCategoriesToDestroy[categoryIndex];
                    EditorUtility.DisplayProgressBar("Removing categories", "Please wait... (" + prefabCategory.Name + ")", (categoryIndex + 1) / (float)prefabCategoriesToDestroy.Count);
                    UndoEx.DestroyObjectImmediate(prefabCategory);
                }
                EditorUtility.ClearProgressBar();
            }
            else
            {
                foreach (PrefabCategory prefabCategory in prefabCategoriesToDestroy)
                {
                    UndoEx.DestroyObjectImmediate(prefabCategory);
                }
            }
        }
Example #4
0
 private void OnDestroy()
 {
     if (_nameFilter != null)
     {
         UndoEx.DestroyObjectImmediate(_nameFilter);
     }
 }
Example #5
0
        private void OnDestroy()
        {
            if (_prefabFilter != null)
            {
                UndoEx.DestroyObjectImmediate(_prefabFilter);
            }
            List <Prefab> prefabs = GetAllPrefabs();

            foreach (Prefab prefab in prefabs)
            {
                if (prefab != null)
                {
                    _prefabs.RemoveEntity(prefab);
                }
                PrefabWasRemovedFromCategoryMessage.SendToInterestedListeners(this, prefab);
            }

            //EnsureActivePrefabPassesPrefabFilter();
            foreach (Prefab prefab in prefabs)
            {
                if (prefab != null)
                {
                    UndoEx.DestroyObjectImmediate(prefab);
                }
            }
        }
Example #6
0
        public static GameObject ReplaceGameObjectHierarchyPrefab(GameObject gameObject, GameObject newPrefab)
        {
            if (gameObject == null || PrefabUtility.GetPrefabType(newPrefab) != PrefabType.Prefab)
            {
                return(null);
            }

            // Store any needed object data
            OrientedBox originalWorldOrientedBox = gameObject.GetHierarchyWorldOrientedBox();

            if (originalWorldOrientedBox.IsInvalid())
            {
                return(null);
            }
            int  originalObjectLayer = gameObject.layer;
            bool isObjectStatic      = gameObject.isStatic;

            Transform  originalObjectTransform = gameObject.transform;
            Vector3    worldScale    = originalObjectTransform.lossyScale;
            Quaternion worldRotation = originalObjectTransform.rotation;

            // Create a new game object from the specified prefab
            GameObject newObject = PrefabUtility.InstantiatePrefab(newPrefab) as GameObject;

            if (newObject != null)
            {
                // Register the created object for Undo and set its transform data. Also store any significant
                // data that the original object had before it was destroyed.
                UndoEx.RegisterCreatedGameObject(newObject);
                Transform newObjectTransform = newObject.transform;
                newObjectTransform.localScale = worldScale;
                newObjectTransform.rotation   = worldRotation;
                newObjectTransform.parent     = originalObjectTransform.transform.parent;
                newObject.SetSelectedHierarchyWireframeHidden(ObjectPlacementSettings.Get().HideWireframeWhenPlacingObjects);
                newObject.layer    = originalObjectLayer;
                newObject.isStatic = isObjectStatic;

                // We will adjust the new object's position such that its center is the same as the
                // one the original object had. This produces better results especially when the new
                // object is a multi-level object hierarchy.
                OrientedBox newHierarchyWorldOrientedBox = newObject.GetHierarchyWorldOrientedBox();
                if (newHierarchyWorldOrientedBox.IsInvalid())
                {
                    GameObject.DestroyImmediate(newObject);
                    return(null);
                }
                newObjectTransform.position = ObjectPositionCalculator.CalculateObjectHierarchyPosition(newPrefab, originalWorldOrientedBox.Center, worldScale, worldRotation);

                // We will also inform the scene that a new object was created so that all the necessary steps can be performed
                Octave3DScene.Get().RegisterObjectHierarchy(newObject);

                // Destroy the old object
                UndoEx.DestroyObjectImmediate(gameObject);

                return(newObject);
            }

            return(null);
        }
Example #7
0
 private void OnDestroy()
 {
     if (_prefabTagFilter != null)
     {
         UndoEx.DestroyObjectImmediate(_prefabTagFilter);
     }
     MessageListenerDatabase.Instance.UnregisterListener(this);
 }
 public void RemoveAndDestroyConfiguration(ObjectPlacementPathTileConnectionConfiguration configuration)
 {
     if (ContainsConfiguration(configuration))
     {
         _configurations.RemoveEntity(configuration);
         UndoEx.DestroyObjectImmediate(configuration);
     }
 }
 public void RemoveAndDestroyElement(DecorPaintObjectPlacementBrushElement element)
 {
     if (ContainsElement(element) && element != null)
     {
         _elements.Remove(element);
         ClampActiveElementIndex();
         UndoEx.DestroyObjectImmediate(element);
     }
 }
        public void RemoveAndDestroyPattern(ObjectPlacementPathHeightPattern pathHeightPattern)
        {
            if (ContainsPattern(pathHeightPattern))
            {
                _pathHeightPatterns.RemoveEntity(pathHeightPattern);
                ObjectPlacementPathHeightPatternWasRemovedFromDatabaseMessage.SendToInterestedListeners(pathHeightPattern);

                UndoEx.DestroyObjectImmediate(pathHeightPattern);
            }
        }
        public void RemoveAndDestroyBrush(DecorPaintObjectPlacementBrush brush)
        {
            if (ContainsBrush(brush))
            {
                _brushes.RemoveEntity(brush);
                // ToDo: Send message that brush was removed

                UndoEx.DestroyObjectImmediate(brush);
            }
        }
        public void RemoveAndDestroyPrefabTag(PrefabTag prefabTag)
        {
            if (ContainsPrefabTag(prefabTag))
            {
                _prefabTags.RemoveEntity(prefabTag);
                PrefabTagWasRemovedFromDatabaseMessage.SendToInterestedListeners(prefabTag);

                UndoEx.DestroyObjectImmediate(prefabTag);
            }
        }
Example #13
0
        public void RemoveAndDestroyPrefab(Prefab prefab)
        {
            if (ContainsPrefab(prefab))
            {
                _prefabs.RemoveEntity(prefab);
                EnsureActivePrefabPassesPrefabFilter();

                PrefabWasRemovedFromCategoryMessage.SendToInterestedListeners(this, prefab);
                UndoEx.DestroyObjectImmediate(prefab);;
            }
        }
Example #14
0
 private static void DestroyGameObject(GameObject gameObject, bool allowUndoRedo)
 {
     if (allowUndoRedo)
     {
         UndoEx.DestroyObjectImmediate(gameObject);
     }
     else
     {
         Octave3DWorldBuilder.DestroyImmediate(gameObject);
     }
 }
Example #15
0
        public static List <GameObject> ReplaceSelectedObjectsPrefabOnMouseClick()
        {
            MouseCursorRayHit cursorRayHit = ObjectSelection.Get().GetObjectPickedByCursor();

            if (cursorRayHit.WasAnObjectHit && !ObjectSelection.Get().IsGameObjectSelected(cursorRayHit.ClosestObjectRayHit.HitObject))
            {
                GameObject hitObject = cursorRayHit.ClosestObjectRayHit.HitObject;
                hitObject = Octave3DWorldBuilder.ActiveInstance.GetRoot(hitObject);
                if (hitObject == null)
                {
                    return(new List <GameObject>());
                }

                GameObject newPrefabForSelectedObjects = hitObject.GetSourcePrefab();
                if (newPrefabForSelectedObjects == null)
                {
                    List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();
                    ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects);

                    List <GameObject> selectedRoots = Octave3DWorldBuilder.ActiveInstance.GetRoots(allSelectedObjects);
                    var newObjects = new List <GameObject>();
                    foreach (var root in selectedRoots)
                    {
                        Transform  rootTransform = root.transform;
                        GameObject newObject     = GameObjectExtensions.CloneAsWorkingObject(hitObject, hitObject.transform.parent, true);
                        if (newObject != null)
                        {
                            Transform objectTransform = newObject.transform;
                            objectTransform.position = rootTransform.position;
                            objectTransform.rotation = rootTransform.rotation;
                            objectTransform.SetWorldScale(rootTransform.lossyScale);
                            newObject.SetSelectedHierarchyWireframeHidden(ObjectPlacementSettings.Get().HideWireframeWhenPlacingObjects);

                            UndoEx.DestroyObjectImmediate(root);
                            newObjects.Add(newObject);
                        }
                    }

                    return(newObjects);
                }
                else
                {
                    List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();
                    ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects);
                    List <GameObject> newObjects = ObjectActions.ReplaceGameObjectHierarchyCollectionPrefab(allSelectedObjects, newPrefabForSelectedObjects);
                    newObjects.RemoveAll(item => item == null);

                    return(newObjects);
                }
            }

            return(new List <GameObject>());
        }
        public void RemoveAndDestroyAllElements()
        {
            var allElements = GetAllBrushElements();

            _elements.Clear();

            _activeElementIndex = -1;
            foreach (var element in allElements)
            {
                UndoEx.DestroyObjectImmediate(element);
            }
        }
        public void RemoveAndDestroyPrefabCategory(PrefabCategory prefabCategory)
        {
            if (CanPrefabCategoryBeRemovedFromDatabase(prefabCategory))
            {
                if (ContainsPrefabCategory(prefabCategory))
                {
                    _prefabCategories.RemoveEntity(prefabCategory);
                    PrefabCategoryWasRemovedFromDatabaseMessage.SendToInterestedListeners(prefabCategory);

                    UndoEx.DestroyObjectImmediate(prefabCategory);
                }
            }
        }
Example #18
0
        public void MakeAllNoLongerGroup()
        {
            UndoEx.RecordForToolAction(this);
            var groupsToRemove = _objectGroups.GetAllEntities();

            _objectGroups.RemoveAllEntities();

            foreach (var group in groupsToRemove)
            {
                UndoEx.DestroyObjectImmediate(group);
            }
            PrefabManagementWindow.Get().Repaint();
        }
Example #19
0
        public void CombineSelectedObjects(List <GameObject> selectedObjects, List <GameObject> ignoreObjects)
        {
            if (_combineSettings == null || selectedObjects == null)
            {
                return;
            }
            if (selectedObjects.Count == 0)
            {
                EditorUtility.DisplayDialog("No Selected Objects", "The mesh combine process can not start because there are no objects currently selected.", "Ok");
                return;
            }

            List <GameObject> allMeshObjects = new List <GameObject>(selectedObjects.Count);

            foreach (var selectedObject in selectedObjects)
            {
                if (selectedObject.HasMeshFilterWithValidMesh())
                {
                    allMeshObjects.Add(selectedObject);
                }
            }
            if (ignoreObjects != null && ignoreObjects.Count != 0)
            {
                allMeshObjects.RemoveAll(item => ignoreObjects.Contains(item));
            }

            List <MeshCombineMaterial> meshCombineMaterials = GetMeshCombineMaterials(allMeshObjects, null);

            if (meshCombineMaterials.Count == 0)
            {
                EditorUtility.DisplayDialog("No Combinable Objects", "The current selection does not contain any objects which can be combined. Please check the following: \n\r" +
                                            "-the selection must contain mesh objects; \n\r " +
                                            "-check the \'Combine static/dynamic meshes\' toggles to ensure that the objects can actually be combined; \n\r" +
                                            "-if the objects belong to a hierarchy, make sure to unhceck the \'Ignore objects in hierarchies\' toggle.", "Ok");
                return;
            }

            Combine(meshCombineMaterials, _combineSettings.SelectionCombineDestinationParent);

            if (_combineSettings.SelCombineMode == MeshCombineSettings.CombineMode.Replace)
            {
                List <GameObject> parents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(selectedObjects);
                foreach (var parent in parents)
                {
                    UndoEx.DestroyObjectImmediate(parent);
                }
            }

            EditorUtility.DisplayDialog("Done!", "Mesh objects combined successfully!", "Ok");
        }
        public void RemoveAndDestroyAllPrefabTags()
        {
            List <PrefabTag> allPrefabTags = GetAllPrefabTags();

            foreach (PrefabTag prefabTag in allPrefabTags)
            {
                _prefabTags.RemoveEntity(prefabTag);
                PrefabTagWasRemovedFromDatabaseMessage.SendToInterestedListeners(prefabTag);
            }

            foreach (PrefabTag prefabTag in allPrefabTags)
            {
                UndoEx.DestroyObjectImmediate(prefabTag);
            }
        }
Example #21
0
 private void OnEditorUpdate()
 {
     if (!EditorApplication.isPlaying)
     {
         if (Octave3DWorldBuilder.ActiveInstance == null)
         {
             UndoEx.DestroyObjectImmediate(gameObject);
         }
         else
         if (!Selection.Contains(Octave3DWorldBuilder.ActiveInstance.gameObject))
         {
             ObjectPlacement.Get().DestroyPlacementGuide();
         }
     }
 }
        public void RemoveAndDestroyAllBrushes()
        {
            List <DecorPaintObjectPlacementBrush> brushes = GetAllBrushes();

            foreach (DecorPaintObjectPlacementBrush brush in brushes)
            {
                _brushes.RemoveEntity(brush);
                // ToDo: Send message that brush was removed
            }

            foreach (DecorPaintObjectPlacementBrush brush in brushes)
            {
                UndoEx.DestroyObjectImmediate(brush);
            }
        }
        public void RemoveAndDestroyAllPatterns()
        {
            List <ObjectPlacementPathHeightPattern> patterns = GetAllPatterns();

            foreach (ObjectPlacementPathHeightPattern pattern in patterns)
            {
                _pathHeightPatterns.RemoveEntity(pattern);
                ObjectPlacementPathHeightPatternWasRemovedFromDatabaseMessage.SendToInterestedListeners(pattern);
            }

            foreach (ObjectPlacementPathHeightPattern pattern in patterns)
            {
                UndoEx.DestroyObjectImmediate(pattern);
            }
        }
Example #24
0
        public void MakeNoLongerGroup(GameObject gameObject)
        {
            if (!ContainsObjectGroup(gameObject))
            {
                return;
            }

            UndoEx.RecordForToolAction(this);
            var objectGroup = _objectGroups.GetEntityByPredicate(item => item.GroupObject == gameObject);

            _objectGroups.RemoveEntity(objectGroup);

            UndoEx.DestroyObjectImmediate(objectGroup);
            PrefabManagementWindow.Get().Repaint();
        }
Example #25
0
 private void OnDestroy()
 {
     if (_instantiationSettings != null)
     {
         UndoEx.DestroyObjectImmediate(_instantiationSettings);
     }
     if (_activationSettings != null)
     {
         UndoEx.DestroyObjectImmediate(_activationSettings);
     }
     if (_tagAssociations != null)
     {
         UndoEx.DestroyObjectImmediate(_tagAssociations);
     }
 }
        public void RemoveAndDestroyAllConfigurations()
        {
            List <ObjectPlacementPathTileConnectionConfiguration> allConfigurations = GetAllConfigurations();

            foreach (ObjectPlacementPathTileConnectionConfiguration configuration in allConfigurations)
            {
                _configurations.RemoveEntity(configuration);
            }

            // Note: I can't understand why, but we need to destroy the scriptable object instances in a second pass. Otherwise,
            //       if the active configuration is set to the first configuration in the configuration list, the remove action
            //       can not be undone properly. The active configuration index (i.e. marked entity index) is not restored properly.
            foreach (ObjectPlacementPathTileConnectionConfiguration configuration in allConfigurations)
            {
                UndoEx.DestroyObjectImmediate(configuration);
            }
        }
        public void RemoveAndDestroyObjectGroup(ObjectGroup objectGroup)
        {
            if (ContainsObjectGroup(objectGroup))
            {
                _objectGroups.RemoveEntity(objectGroup);

                GameObject groupParent = objectGroup.GroupObject;
                if (_preserveGroupChildren)
                {
                    groupParent.MoveImmediateChildrenUpOneLevel(true);
                }
                if (groupParent != null)
                {
                    UndoEx.DestroyObjectImmediate(groupParent);
                }
                UndoEx.DestroyObjectImmediate(objectGroup);

                PrefabManagementWindow.Get().Repaint();
            }
        }
Example #28
0
        public void RemoveAndDestroyAllPrefabs()
        {
            // Don't know why, but this has to be done in 2 separate passes. Otherwise, the remove operation
            // is not undone properly in some situations. So first we have to remove the prefabs from the
            // category and then we have to destroy the prefab instances in a second pass. It drives me insane,
            // but I just can't figure out why this is necessary :)
            List <Prefab> prefabs = GetAllPrefabs();

            foreach (Prefab prefab in prefabs)
            {
                _prefabs.RemoveEntity(prefab);
                PrefabWasRemovedFromCategoryMessage.SendToInterestedListeners(this, prefab);
            }

            EnsureActivePrefabPassesPrefabFilter();
            foreach (Prefab prefab in prefabs)
            {
                UndoEx.DestroyObjectImmediate(prefab);
            }
        }
        public void RemoveAndDestroyEmptyPrefabCategories()
        {
            List <PrefabCategory> allPrefabCategories = GetAllPrefabCategories();
            var prefabCategoriesToDestroy             = new List <PrefabCategory>();

            foreach (PrefabCategory prefabCategory in allPrefabCategories)
            {
                if (prefabCategory.IsEmpty && CanPrefabCategoryBeRemovedFromDatabase(prefabCategory))
                {
                    _prefabCategories.RemoveEntity(prefabCategory);
                    PrefabCategoryWasRemovedFromDatabaseMessage.SendToInterestedListeners(prefabCategory);

                    prefabCategoriesToDestroy.Add(prefabCategory);
                }
            }

            foreach (PrefabCategory prefabCategory in prefabCategoriesToDestroy)
            {
                UndoEx.DestroyObjectImmediate(prefabCategory);
            }
        }
        public void CombineSelectedObjects(List <GameObject> selectedObjects, List <GameObject> ignoreObjects)
        {
            if (_combineSettings == null || selectedObjects == null || selectedObjects.Count == 0)
            {
                return;
            }

            List <GameObject> allMeshObjects = new List <GameObject>(selectedObjects.Count);

            foreach (var selectedObject in selectedObjects)
            {
                if (selectedObject.HasMeshFilterWithValidMesh())
                {
                    allMeshObjects.Add(selectedObject);
                }
            }
            if (ignoreObjects != null && ignoreObjects.Count != 0)
            {
                allMeshObjects.RemoveAll(item => ignoreObjects.Contains(item));
            }

            List <MeshCombineMaterial> meshCombineMaterials = GetMeshCombineMaterials(allMeshObjects, null);

            if (meshCombineMaterials.Count == 0)
            {
                return;
            }
            Combine(meshCombineMaterials, _combineSettings.SelectionCombineDestinationParent);

            if (_combineSettings.SelCombineMode == MeshCombineSettings.CombineMode.Replace)
            {
                List <GameObject> parents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(selectedObjects);
                foreach (var parent in parents)
                {
                    UndoEx.DestroyObjectImmediate(parent);
                }
            }
        }