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);
                }
            }
        }
Ejemplo n.º 2
0
        public static void ActivatePreviousPrefabInPrefabCategory(PrefabCategory prefabCategory)
        {
            List <Prefab> filteredPrefabs = prefabCategory.GetFilteredPrefabs();

            int prefabIndex = prefabCategory.GetPrefabIndex(prefabCategory.ActivePrefab) - 1;

            if (prefabIndex < 0)
            {
                prefabIndex = prefabCategory.NumberOfPrefabs - 1;
            }

            while (prefabIndex >= 0)
            {
                Prefab newActivePrefab = prefabCategory.GetPrefabByIndex(prefabIndex);
                if (filteredPrefabs.Contains(newActivePrefab))
                {
                    prefabCategory.SetActivePrefab(newActivePrefab);
                    return;
                }

                --prefabIndex;
            }

            prefabCategory.SetActivePrefab(null);
        }
Ejemplo n.º 3
0
        private void PlaceObjectFromPlacementGuide(bool checkForIntersection)
        {
            ObjectPlacementGuide placementGuide      = ObjectPlacementGuide.Instance;
            GameObject           placedHierarchyRoot = null;

            OrientedBox       guideHierarchyWorldOrientedBox = ObjectPlacementGuide.SceneObject.GetHierarchyWorldOrientedBox();
            List <GameObject> intersectingObjects            = ObjectQueries.GetIntersectingObjects(guideHierarchyWorldOrientedBox, new List <GameObject> {
                _strokeSurface.SurfaceObject
            }, true);

            if (!checkForIntersection || ObjectPlacementSettings.Get().ObjectIntersectionSettings.AllowIntersectionForDecorPaintSingleModeDrag ||
                intersectingObjects.Count == 0)
            {
                placedHierarchyRoot = Octave3DScene.Get().InstantiateObjectHierarchyFromPrefab(placementGuide.SourcePrefab, placementGuide.gameObject.transform);
                ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoot, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement);

                List <GameObject> allPlacedObjects = placedHierarchyRoot.GetAllChildrenIncludingSelf();
                _objectsPlacedWhileDragging.AddRange(allPlacedObjects);
                DecorPaintObjectPlacement.Get().DecorPaintMask.ObjectCollectionMask.Mask(allPlacedObjects);
            }

            _orientedBoxOfLastPlacedHierarchy = ObjectPlacementGuide.SceneObject.GetHierarchyWorldOrientedBox();
            _pivotPointsOfLastPlacedHierarchy.FromOrientedBoxAndDecorStrokeSurface(_orientedBoxOfLastPlacedHierarchy, _strokeSurface);

            if (DecorPaintObjectPlacementSettings.Get().SingleDecorPaintModeSettings.RandomizePrefabsInActiveCategory)
            {
                PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;
                if (activePrefabCategory != null)
                {
                    activePrefabCategory.RandomizeActivePrefab();
                }
            }
        }
 public void RenamePrefabCategory(PrefabCategory prefabCategory, string newName)
 {
     if (ContainsPrefabCategory(prefabCategory))
     {
         _prefabCategories.RenameEntity(prefabCategory, newName);
     }
 }
Ejemplo n.º 5
0
 public PrefabWasTransferredToCategoryMessage(Prefab prefab, PrefabCategory sourceCategory, PrefabCategory destinationCategory)
     : base(MessageType.PrefabWasTransferredToCategory)
 {
     _sourceCategory      = sourceCategory;
     _destinationCategory = destinationCategory;
     _prefab = prefab;
 }
        private void RenderObjectGroupSelectionPopup()
        {
            ObjectGroupDatabase objectGroupDatabase = Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase;

            if (objectGroupDatabase.NumberOfGroups == 0)
            {
                EditorGUILayoutEx.InformativeLabel("No object groups are currently available.");
                return;
            }

            PrefabCategoryDatabase prefabCategoryDatabase = PrefabCategoryDatabase.Get();
            PrefabCategory         activeCategory         = prefabCategoryDatabase.ActivePrefabCategory;

            List <ObjectGroup> allObjectGroups = objectGroupDatabase.GetAllObjectGroups();

            if (activeCategory.ObjectGroup == null)
            {
                activeCategory.SetObjectGroup(allObjectGroups[0]);
            }

            int currentGroupIndex = allObjectGroups.FindIndex(0, item => item == activeCategory.ObjectGroup);

            if (currentGroupIndex < 0)
            {
                return;
            }

            int newGroupIndex = EditorGUILayoutEx.Popup(GetContentForObjectGroupSelectionPopup(), currentGroupIndex, objectGroupDatabase.GetAllObjectGroupNames());

            if (newGroupIndex != currentGroupIndex)
            {
                UndoEx.RecordForToolAction(activeCategory);
                activeCategory.SetObjectGroup(allObjectGroups[newGroupIndex]);
            }
        }
        private static void EnsureGuideUsesBeginTileConnectionPrefab()
        {
            ObjectPlacementPathTileConnectionSettings     tileConnectionSettings      = ObjectPlacement.Get().PathObjectPlacement.PathSettings.TileConnectionSettings;
            ObjectPlacementPathTileConnectionTypeSettings beginTileConnectionSettings = tileConnectionSettings.GetSettingsForTileConnectionType(ObjectPlacementPathTileConnectionType.Begin);

            if (CanRefreshGuideToUseBeginTileConnectionPrefab(beginTileConnectionSettings))
            {
                PrefabCategory categoryWhichContainsBeginPrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(beginTileConnectionSettings.Prefab);
                if (categoryWhichContainsBeginPrefab == null)
                {
                    return;
                }

                PrefabCategoryDatabase.Get().SetActivePrefabCategory(categoryWhichContainsBeginPrefab);
                categoryWhichContainsBeginPrefab.SetActivePrefab(beginTileConnectionSettings.Prefab);

                ObjectPlacement.Get().DestroyPlacementGuide();
                ObjectPlacementGuide.CreateFromActivePrefabIfNotExists();
            }

            // Note: When using tile connections, we will always use the original prefab scale
            if (ObjectPlacementGuide.ExistsInScene)
            {
                ObjectPlacementGuide.Instance.WorldScale = beginTileConnectionSettings.Prefab.InitialWorldScale;
            }
        }
        private static PrefabCategory CreateNewPrefabCategoryWithUniqueName(string name, List <string> existingCategoryNames)
        {
            PrefabCategory newPrefabCategory = Octave3DWorldBuilder.ActiveInstance.CreateScriptableObject <PrefabCategory>();

            newPrefabCategory.Name = UniqueEntityNameGenerator.GenerateUniqueName(name, existingCategoryNames);

            return(newPrefabCategory);
        }
 public bool CanPrefabCategoryBeRemovedFromDatabase(PrefabCategory prefabCategory)
 {
     if (prefabCategory.Name == DefaultPrefabCategoryName)
     {
         return(false);
     }
     return(true);
 }
 public bool CanPrefabCategoryBeRenamed(PrefabCategory prefabCategory)
 {
     if (prefabCategory.Name == DefaultPrefabCategoryName)
     {
         return(false);
     }
     return(true);
 }
        private void CreateNewCategoryFromDroppedFolderAndAssignPrefabs(PrefabFolderDropData prefabFolderDropData)
        {
            PrefabCategory newPrefabCategory = PrefabCategoryDatabase.Get().CreatePrefabCategory(prefabFolderDropData.FolderNameInPath);

            newPrefabCategory.SetPathFolderNames(FileSystem.GetFolderNamesInPath(prefabFolderDropData.FolderPath));
            newPrefabCategory.AddPrefabCollection(prefabFolderDropData.ValidPrefabs);
            _lastCreatedCategory = newPrefabCategory;
        }
Ejemplo n.º 12
0
        protected override void PerformDrop()
        {
            PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;

            PerformPrefabsToCategoryDropOperation(activePrefabCategory);
            PerformPrefabFoldersToCategoryDropOperation(activePrefabCategory);
            PrefabTagsWindow.Get().RepaintOctave3DWindow();
        }
Ejemplo n.º 13
0
        public static void SetPrefabOffsetFromGridSurface(PrefabCategory prefabCategory, float offsetFromGridSurface)
        {
            List <Prefab> allPrefabsInCategory = prefabCategory.GetAllPrefabs();

            foreach (Prefab prefab in allPrefabsInCategory)
            {
                prefab.OffsetFromGridSurface = offsetFromGridSurface;
            }
        }
 private void RenderSetPrefabOffsetFromObjectSurfaceInActiveCategoryButton()
 {
     if (GUILayout.Button(GetContentForSetPrefabOffsetFromObjectSurfaceInActiveCategoryButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth + 3.0f)))
     {
         PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;
         UndoEx.RecordForToolAction(activePrefabCategory.GetAllPrefabs());
         PrefabCategoryActions.SetPrefabOffsetFromObjectSurface(activePrefabCategory, ViewData.PrefabOffsetFromObjectSurface);
     }
 }
Ejemplo n.º 15
0
        private void RenderNextPrefabButton(float buttonWidth)
        {
            if (GUILayout.Button(GetContentForNextPrefabButton(), GUILayout.Width(buttonWidth)))
            {
                PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;

                UndoEx.RecordForToolAction(activePrefabCategory);
                PrefabCategoryActions.ActivateNextPrefabInPrefabCategory(activePrefabCategory);
            }
        }
        public void SetActivePrefabCategory(PrefabCategory newActivePrefabCategory)
        {
            if (newActivePrefabCategory == null || !ContainsPrefabCategory(newActivePrefabCategory))
            {
                return;
            }

            _prefabCategories.MarkEntity(newActivePrefabCategory);
            NewPrefabCategoryWasActivatedMessage.SendToInterestedListeners(newActivePrefabCategory);
        }
        private void RenderCreateNewCategoryButton()
        {
            if (GUILayout.Button(GetContentForCreateNewCategoryButton(), GUILayout.Width(143.0f)))
            {
                PrefabCategoryDatabase prefabCategoryDatabase = PrefabCategoryDatabase.Get();
                UndoEx.RecordForToolAction(prefabCategoryDatabase);

                PrefabCategory newCategory = prefabCategoryDatabase.CreatePrefabCategory(ViewData.NameForNewPrefabCategory);
                prefabCategoryDatabase.SetActivePrefabCategory(newCategory);
            }
        }
Ejemplo n.º 18
0
        private void PerformPrefabFoldersToCategoryDropOperation(PrefabCategory prefabCategory)
        {
            var prefabFoldersDropData = new PrefabFoldersToCategoryDropData(prefabCategory, PrefabFoldersDropSettings.ProcessSubfolders);

            prefabFoldersDropData.FromLastDropOperation();

            if (prefabFoldersDropData.PrefabFoldersDropDataCollection.Count != 0)
            {
                var prefabFoldersDropOperation = new PrefabFoldersToCategoryDropOperation(prefabFoldersDropData);
                prefabFoldersDropOperation.Perform();
            }
        }
Ejemplo n.º 19
0
        private void PerformPrefabsToCategoryDropOperation(PrefabCategory prefabCategory)
        {
            var prefabsDropData = new PrefabsToCategoryDropOperationData(prefabCategory);

            prefabsDropData.FromLastDropOperation();

            if (prefabsDropData.ValidDroppedPrefabs.Count != 0)
            {
                var prefabsDropOperation = new PrefabsToCategoryDropOperation(prefabsDropData);
                prefabsDropOperation.Perform();
            }
        }
 public static PrefabWithPrefabCategoryAssociation Create(Prefab prefab, PrefabCategory prefabCategory)
 {
     if (prefab != null && prefabCategory != null)
     {
         return(CreateNewAssociation(prefab, prefabCategory));
     }
     else
     {
         Debug.LogWarning("Can not create the requested prefab with prefab category association. Null prefab or prefab category was specified.");
         return(null);
     }
 }
        public PrefabCategory CreatePrefabCategory(string categoryName)
        {
            if (!string.IsNullOrEmpty(categoryName))
            {
                PrefabCategory newPrefabCategory = PrefabCategoryFactory.Create(categoryName, GetAllPrefabCategoryNames());

                _prefabCategories.AddEntity(newPrefabCategory);
                return(newPrefabCategory);
            }

            return(null);
        }
        public PrefabCategory GetFirstNonEmptyCategory()
        {
            for (int categoryIndex = 0; categoryIndex < NumberOfCategories; ++categoryIndex)
            {
                PrefabCategory prefabCategory = GetPrefabCategoryByIndex(categoryIndex);
                if (!prefabCategory.IsEmpty)
                {
                    return(prefabCategory);
                }
            }

            return(null);
        }
        public void RemoveAndDestroyPrefabCategory(PrefabCategory prefabCategory)
        {
            if (CanPrefabCategoryBeRemovedFromDatabase(prefabCategory))
            {
                if (ContainsPrefabCategory(prefabCategory))
                {
                    _prefabCategories.RemoveEntity(prefabCategory);
                    PrefabCategoryWasRemovedFromDatabaseMessage.SendToInterestedListeners(prefabCategory);

                    UndoEx.DestroyObjectImmediate(prefabCategory);
                }
            }
        }
Ejemplo n.º 24
0
        private static void ReadAllPrefabsInCategory(PrefabCategory prefabCategory, XmlNodeList prefabNodes)
        {
            if (prefabNodes.Count == 0)
            {
                return;
            }

            for (int prefabNodeIndex = 0; prefabNodeIndex < prefabNodes.Count; ++prefabNodeIndex)
            {
                XmlNode prefabNode     = prefabNodes[prefabNodeIndex];
                XmlNode prefabNameNode = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabNameNode);
                XmlNode prefabPathNode = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabPathNode);
                if (prefabPathNode == null)
                {
                    continue;
                }
                XmlNode offsetFromGridNode   = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabOffsetFromGridSurfaceNode);
                XmlNode offsetFromObjectNode = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabOffsetFromObjectSurfaceNode);

                GameObject unityPrefab = AssetDatabase.LoadAssetAtPath(prefabPathNode.InnerText, typeof(GameObject)) as GameObject;
                if (unityPrefab == null)
                {
                    continue;
                }

                Prefab prefab = PrefabFactory.Create(unityPrefab);
                if (prefabNameNode != null && !string.IsNullOrEmpty(prefabNameNode.InnerText))
                {
                    prefab.Name = prefabNameNode.InnerText;
                }

                float offsetFromGrid = 0.0f;
                if (offsetFromGridNode != null)
                {
                    try { offsetFromGrid = float.Parse(offsetFromGridNode.InnerText); }
                    catch (Exception) { }
                }
                prefab.OffsetFromGridSurface = offsetFromGrid;

                float offsetFromObject = 0.0f;
                if (offsetFromObjectNode != null)
                {
                    try { offsetFromObject = float.Parse(offsetFromObjectNode.InnerText); }
                    catch (Exception) { }
                }
                prefab.OffsetFromObjectSurface = offsetFromObject;

                ReadPrefabTagAssociations(prefab, prefabNode.SelectNodes(PrefabConfigXMLInfo.PrefabAssociatedTagNode));
                prefabCategory.AddPrefab(prefab);
            }
        }
Ejemplo n.º 25
0
        public void TransferAllPrefabsToCategory(PrefabCategory destinationCategory)
        {
            if (destinationCategory == this)
            {
                return;
            }

            List <Prefab> allPrefabs = GetAllPrefabs();

            foreach (Prefab prefab in allPrefabs)
            {
                TransferPrefabToCategory(prefab, destinationCategory);
            }
        }
        private void PerformPrefabsToCategoryDropOperation(PrefabCategory prefabCategory)
        {
            var prefabsDropData = new PrefabsToCategoryDropOperationData(prefabCategory);

            prefabsDropData.FromLastDropOperation();

            if (prefabsDropData.ValidDroppedPrefabs.Count != 0)
            {
                var prefabsDropOperation = new PrefabsToCategoryDropOperation(prefabsDropData);
                prefabsDropOperation.Perform();

                PrefabPreviewTextureCache.Get().GeneratePreviewsForPrefabCollection(prefabsDropData.ValidDroppedPrefabs, true);
            }
        }
Ejemplo n.º 27
0
        private void PerformDropUsingFirstPrefabInValidUnityPrefabCollection(List <GameObject> validUnityPrefabs)
        {
            GameObject     firstValidUnityPrefab       = GetFirstUnityPrefabFromValidUnityPrefabsCollection(validUnityPrefabs);
            PrefabCategory categoryWhichContainsPrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(firstValidUnityPrefab);

            if (categoryWhichContainsPrefab != null)
            {
                AssignPrefabToDestinationTileConnection(categoryWhichContainsPrefab.GetPrefabByUnityPrefab(firstValidUnityPrefab));
            }
            else
            {
                Prefab firstValidPrefab = GetFirstPrefabFromValidPrefabsCollection(PrefabFactory.Create(validUnityPrefabs));
                CreatePrefabToCategoryAssociationAndAssignPrefabToDestinationTileConnection(firstValidPrefab);
            }
        }
Ejemplo n.º 28
0
        public void TransferPrefabToCategory(Prefab prefabToTransfer, PrefabCategory destinationCategory)
        {
            if (destinationCategory == this)
            {
                return;
            }

            if (ContainsPrefab(prefabToTransfer))
            {
                _prefabs.RemoveEntity(prefabToTransfer);
                destinationCategory.AddPrefab(prefabToTransfer);

                PrefabWasTransferredToCategoryMessage.SendToInterestedListeners(prefabToTransfer, this, destinationCategory);
            }
        }
Ejemplo n.º 29
0
 public void AddPrefab(Prefab prefab)
 {
     if (!ContainsPrefab(prefab) && !ContainsPrefab(prefab.UnityPrefab))
     {
         if (!PrefabCategoryDatabase.Get().IsThereCategoryWhichContainsPrefab(prefab))
         {
             _prefabs.AddEntity(prefab);
         }
         else
         {
             PrefabCategory categoryWhichContainsPrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(prefab);
             LogPrefabAlreadyExistsInCategoryMessage(categoryWhichContainsPrefab.Name);
         }
     }
 }
        protected override void PerformDrop()
        {
            if (_dropDestination == DropDestination.Element)
            {
                if (_destinationDecorPaintBrushElement == null)
                {
                    return;
                }

                List <GameObject> validUnityPrefabsInvolvedInDropOperation = PrefabValidator.GetValidPrefabsFromEntityCollection(DragAndDrop.objectReferences, false);
                if (validUnityPrefabsInvolvedInDropOperation.Count != 0)
                {
                    PerformDropUsingFirstPrefabInValidUnityPrefabCollection(validUnityPrefabsInvolvedInDropOperation);
                }
            }
            else
            {
                if (_destinationBrush == null)
                {
                    return;
                }

                List <GameObject> validUnityPrefabs = PrefabValidator.GetValidPrefabsFromEntityCollection(DragAndDrop.objectReferences, false);
                if (validUnityPrefabs.Count != 0)
                {
                    UndoEx.RecordForToolAction(_destinationBrush);
                    foreach (GameObject unityPrefab in validUnityPrefabs)
                    {
                        DecorPaintObjectPlacementBrushElement newElement = _destinationBrush.CreateNewElement();

                        PrefabCategory categoryWhichContainsPrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(unityPrefab);
                        if (categoryWhichContainsPrefab != null)
                        {
                            newElement.Prefab = categoryWhichContainsPrefab.GetPrefabByUnityPrefab(unityPrefab);
                        }
                        else
                        {
                            Prefab prefab = PrefabFactory.Create(unityPrefab);
                            UndoEx.RecordForToolAction(_destinationBrush.DestinationCategoryForElementPrefabs);
                            PrefabWithPrefabCategoryAssociationQueue.Instance.Enqueue(PrefabWithPrefabCategoryAssociationFactory.Create(prefab, _destinationBrush.DestinationCategoryForElementPrefabs));
                            newElement.Prefab = prefab;
                        }
                    }
                }
            }

            Octave3DWorldBuilder.ActiveInstance.RepaintAllEditorWindows();
        }