コード例 #1
0
        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]);
            }
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        private void RenderActiveCategorySelectionPopup()
        {
            PrefabCategoryDatabase prefabCategoryDatabase = PrefabCategoryDatabase.Get();
            string newActiveCategoryName = EditorGUILayoutEx.SortedPopup(GetContentForActivePrefabCategorySelectionPopup(),
                                                                         prefabCategoryDatabase.IndexOfActiveCategory,
                                                                         ViewData.ShowPrefabCategoryFolderNames ?
                                                                         prefabCategoryDatabase.GetAllPrefabCategoryNamesWithFolders(ViewData.MaxNumberOfCategoryFolderNames) : prefabCategoryDatabase.GetAllPrefabCategoryNames());

            if (ViewData.ShowPrefabCategoryFolderNames)
            {
                if ((prefabCategoryDatabase.ActivePrefabCategory == null && !string.IsNullOrEmpty(newActiveCategoryName)) ||
                    newActiveCategoryName != prefabCategoryDatabase.ActivePrefabCategory.GetNameWithConcatFolderNames(ViewData.MaxNumberOfCategoryFolderNames))
                {
                    UndoEx.RecordForToolAction(prefabCategoryDatabase);
                    prefabCategoryDatabase.SetActivePrefabCategory(prefabCategoryDatabase.GetPrefabCategoryByNameWithFolders(newActiveCategoryName, ViewData.MaxNumberOfCategoryFolderNames));
                }
            }
            else
            {
                if ((prefabCategoryDatabase.ActivePrefabCategory == null && !string.IsNullOrEmpty(newActiveCategoryName)) ||
                    newActiveCategoryName != prefabCategoryDatabase.ActivePrefabCategory.Name)
                {
                    UndoEx.RecordForToolAction(prefabCategoryDatabase);
                    prefabCategoryDatabase.SetActivePrefabCategory(prefabCategoryDatabase.GetPrefabCategoryByName(newActiveCategoryName));
                }
            }
        }
コード例 #5
0
 private void RespondToMessage(UndoRedoWasPerformedMessage message)
 {
     if (_sourcePrefab != PrefabCategoryDatabase.Get().ActivePrefabCategory.ActivePrefab)
     {
         DestroyIfExists();
         CreateFromActivePrefabIfNotExists();
     }
 }
コード例 #6
0
        private void CreateNewCategoryFromDroppedFolderAndAssignPrefabs(PrefabFolderDropData prefabFolderDropData)
        {
            PrefabCategory newPrefabCategory = PrefabCategoryDatabase.Get().CreatePrefabCategory(prefabFolderDropData.FolderNameInPath);

            newPrefabCategory.SetPathFolderNames(FileSystem.GetFolderNamesInPath(prefabFolderDropData.FolderPath));
            newPrefabCategory.AddPrefabCollection(prefabFolderDropData.ValidPrefabs);
            _lastCreatedCategory = newPrefabCategory;
        }
コード例 #7
0
        protected override void PerformDrop()
        {
            PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;

            PerformPrefabsToCategoryDropOperation(activePrefabCategory);
            PerformPrefabFoldersToCategoryDropOperation(activePrefabCategory);
            PrefabTagsWindow.Get().RepaintOctave3DWindow();
        }
コード例 #8
0
 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);
     }
 }
コード例 #9
0
        private void RenderDestinationCategoryForElementPrefabsSelectionPopup()
        {
            string newString = EditorGUILayoutEx.Popup(GetContentForDestinationCategoryForElementPrefabsSelectionPopup(), _brush.DestinationCategoryForElementPrefabs.Name, PrefabCategoryDatabase.Get().GetAllPrefabCategoryNames());

            if (newString != _brush.DestinationCategoryForElementPrefabs.Name)
            {
                UndoEx.RecordForToolAction(_brush);
                _brush.DestinationCategoryForElementPrefabs = PrefabCategoryDatabase.Get().GetPrefabCategoryByName(newString);
            }
        }
コード例 #10
0
        public static void PerformRegistrationForPrefabCategoryDatabase(PrefabCategoryDatabase prefabCategoryDatabase)
        {
            if (prefabCategoryDatabase != null)
            {
                MessageListenerDatabase listenerDatabase = MessageListenerDatabase.Instance;
                listenerDatabase.UnregisterListener(prefabCategoryDatabase);

                listenerDatabase.RegisterListenerForMessage(MessageType.PrefabTagWasRemovedFromDatabase, prefabCategoryDatabase);
            }
        }
コード例 #11
0
        private void RenderNextPrefabButton(float buttonWidth)
        {
            if (GUILayout.Button(GetContentForNextPrefabButton(), GUILayout.Width(buttonWidth)))
            {
                PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;

                UndoEx.RecordForToolAction(activePrefabCategory);
                PrefabCategoryActions.ActivateNextPrefabInPrefabCategory(activePrefabCategory);
            }
        }
        private void RenderDestinationCategorySelectionPopup()
        {
            string newString = EditorGUILayoutEx.Popup(GetContentForDestinationCategorySelectionPopup(), _settings.DestinationCategory.Name, PrefabCategoryDatabase.Get().GetAllPrefabCategoryNames());

            if (newString != _settings.DestinationCategory.Name)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.DestinationCategory = PrefabCategoryDatabase.Get().GetPrefabCategoryByName(newString);
            }
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
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);
            }
        }
コード例 #15
0
 public void Perform()
 {
     if (_dropData != null && _dropData.PrefabFoldersDropDataCollection.Count != 0)
     {
         if (_prefabFoldersDropSettings.CreatePrefabCategoriesFromDroppedFolders)
         {
             UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get());
         }
         DropPrefabFolders();
         if (ShouldActivateLastPrefabCategoryAfterDrop())
         {
             PrefabCategoryDatabase.Get().SetActivePrefabCategory(_lastCreatedCategory);
         }
     }
 }
コード例 #16
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);
         }
     }
 }
コード例 #17
0
        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();
        }
コード例 #18
0
        private void PlaceObject()
        {
            ObjectPlacementGuide placementGuide      = ObjectPlacementGuide.Instance;
            GameObject           placedHierarchyRoot = Octave3DScene.Get().InstantiateObjectHierarchyFromPrefab(placementGuide.SourcePrefab, placementGuide.WorldPosition, placementGuide.WorldRotation, placementGuide.WorldScale);

            ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoot, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement);

            if (PointAndClickObjectPlacementSettings.Get().RandomizePrefabsInActiveCategory)
            {
                PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;
                if (activePrefabCategory != null)
                {
                    activePrefabCategory.RandomizeActivePrefab();
                }
            }
        }
コード例 #19
0
 public void AddPrefab(GameObject unityPrefab)
 {
     if (!ContainsPrefab(unityPrefab))
     {
         if (!PrefabCategoryDatabase.Get().IsThereCategoryWhichContainsPrefab(unityPrefab))
         {
             Prefab prefab = PrefabFactory.Create(unityPrefab);
             _prefabs.AddEntity(prefab);
         }
         else
         {
             PrefabCategory categoryWhichContainsPrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(unityPrefab);
             LogPrefabAlreadyExistsInCategoryMessage(categoryWhichContainsPrefab.Name);
         }
     }
 }
コード例 #20
0
        private static void WritePrefabCategoryDatabase(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteNewLine(1);
            xmlWriter.WriteStartElement(PrefabConfigXMLInfo.PrefabCategoryDatabaseNode);

            List <PrefabCategory> allPrefabCategories = PrefabCategoryDatabase.Get().GetAllPrefabCategories();

            for (int categoryIndex = 0; categoryIndex < allPrefabCategories.Count; ++categoryIndex)
            {
                EditorUtility.DisplayProgressBar("Saving prefab categories...", "", (categoryIndex + 1) / (float)allPrefabCategories.Count);
                WritePrefabCategory(xmlWriter, allPrefabCategories[categoryIndex]);
            }
            EditorUtility.ClearProgressBar();

            xmlWriter.WriteNewLine(1);
            xmlWriter.WriteEndElement();
        }
コード例 #21
0
        public void LoadAllPrefabsInActiveCategory()
        {
            PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;

            if (activePrefabCategory != null)
            {
                List <Prefab> allPrefabsInCatgory = activePrefabCategory.GetAllPrefabs();
                foreach (var prefab in allPrefabsInCatgory)
                {
                    if (GetElementWithPrefab(prefab) == null)
                    {
                        var element = CreateNewElement();
                        element.Prefab = prefab;
                    }
                }
            }
        }
コード例 #22
0
        public static void LoadConfig(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(fileName);

            UndoEx.RecordForToolAction(PrefabTagDatabase.Get());
            PrefabTagDatabase.Get().RemoveAndDestroyAllPrefabTags();
            XmlNodeList prefabTagsDatabaseNodes = xmlDoc.SelectNodes("//" + PrefabConfigXMLInfo.PrefabTagDatabaseNode);

            if (prefabTagsDatabaseNodes.Count != 0)
            {
                ReadAllPrefabTags(prefabTagsDatabaseNodes[0]);
            }

            UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get());
            PrefabCategoryDatabase.Get().RemoveAndDestroyAllPrefabCategories(true);
            XmlNodeList prefabCategoryDatabaseNodes = xmlDoc.SelectNodes("//" + PrefabConfigXMLInfo.PrefabCategoryDatabaseNode);

            if (prefabCategoryDatabaseNodes.Count != 0)
            {
                ReadAllPrefabCategories(prefabCategoryDatabaseNodes[0]);
            }

            PrefabPreviewTextureCache.Get().GeneratePreviewForAllPrefabCategories(true);

            PrefabCategory firstNonEmptyCategory = PrefabCategoryDatabase.Get().GetFirstNonEmptyCategory();

            if (firstNonEmptyCategory != null)
            {
                PrefabCategoryDatabase.Get().SetActivePrefabCategory(firstNonEmptyCategory);
            }

            XmlNodeList prefabScrollViewLookAndFeelNodes = xmlDoc.SelectNodes("//" + PrefabConfigXMLInfo.PrefabScrollViewLookAndFeelNode);

            if (prefabScrollViewLookAndFeelNodes.Count != 0)
            {
                ReadPrefabScrollViewLookAndFeel(prefabScrollViewLookAndFeelNodes[0]);
            }
        }
コード例 #23
0
        public List <GameObject> MirrorGameObjectHierarchies(List <GameObject> sourceHierarchyRoots)
        {
            if (sourceHierarchyRoots.Count == 0)
            {
                return(new List <GameObject>());
            }

            var mirroredHierarchies = new List <GameObject>(sourceHierarchyRoots.Count);

            if (IsActive)
            {
                Dictionary <GameObject, Prefab> unityPrefabsToOctavePrefabs = new Dictionary <GameObject, Prefab>();
                foreach (var root in sourceHierarchyRoots)
                {
                    GameObject unityPrefab  = root.GetSourcePrefab();
                    Prefab     octavePrefab = null;

                    if (unityPrefab != null)
                    {
                        if (!unityPrefabsToOctavePrefabs.ContainsKey(unityPrefab))
                        {
                            PrefabCategory prefabCategory = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(unityPrefab);
                            if (prefabCategory != null)
                            {
                                octavePrefab = prefabCategory.GetPrefabByUnityPrefab(unityPrefab);
                                unityPrefabsToOctavePrefabs.Add(unityPrefab, octavePrefab);
                            }
                        }
                        else
                        {
                            octavePrefab = unityPrefabsToOctavePrefabs[unityPrefab];
                        }
                    }

                    GameObject mirroredGameObjectHierarchy = MirrorGameObjectHierarchy(root, octavePrefab);
                    if (mirroredGameObjectHierarchy != null)
                    {
                        mirroredHierarchies.Add(mirroredGameObjectHierarchy);
                    }
                }
            }

            return(mirroredHierarchies);
        }
コード例 #24
0
        protected override void RenderContent()
        {
            _prefabScrollView.PrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;
            RenderShowPrefabCategoryFolderNamesToggle();
            if (ViewData.ShowPrefabCategoryFolderNames)
            {
                RenderMaxNumberOfCategoryFolderNamesToggle();
            }
            RenderActiveCategorySelectionPopup();
            RenderActiveCategoryNameChangeTextField();
            RenderObjectGroupSelectionPopup();

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            RenderPrefabsToActiveCategoryDropOperationSettingsButton();
            RenderCreateNewCategoryControls();
            EditorGUILayout.EndHorizontal();

            Octave3DWorldBuilder.ActiveInstance.ShowGUIHint("Note: When a config is loaded, the tool will use the prefab path to load the prefab back. If the prefab's path has changed (e.g. moved to " +
                                                            "a different folder, or changed the name of a folder inside the folder hierarchy, or changed the name of the prefab asset etc), the prefab will not be loaded.");
            Octave3DWorldBuilder.ActiveInstance.ShowGUIHint("When a config is saved, all prefab categories (together with their prefabs) and prefab tags are saved. When a config is loaded, " +
                                                            "all prefab categories and tags are removed and replaced with the ones which are loaded from the config file. Also, any missing object groups " +
                                                            "referenced by prefab categories, will automatically be created on load.");

            EditorGUILayout.HelpBox("You can right click inside the prefab management window to bring up a context menu that will allow you to manage prefabs and prefab categories (e.g. remove, clear etc).", UnityEditor.MessageType.Warning);

            EditorGUILayout.BeginHorizontal();
            RenderSavePrefabConfigButton();
            RenderLoadPrefabConfigButton();

            var content = new GUIContent();

            content.text    = "Look and feel...";
            content.tooltip = "Opens up a new window which allows you to control the look and feel of the prefab view area.";
            if (GUILayout.Button(content, GUILayout.Width(100.0f)))
            {
                _prefabScrollView.LookAndFeelWindow.ShowOctave3DWindow();
            }
            EditorGUILayout.EndHorizontal();

            _prefabScrollView.Render();
            RenderActionsView();
        }
コード例 #25
0
        protected override void RenderContent()
        {
            _scrollViewPosition = EditorGUILayout.BeginScrollView(_scrollViewPosition);
            RenderContentInScrollView();
            EditorGUILayout.EndScrollView();

            Event currentEvent = Event.current;

            if (currentEvent.type == EventType.MouseDown && currentEvent.button == (int)(MouseButton.Right))
            {
                GenericMenu contextMenu = new GenericMenu();
                contextMenu.AddItem(new GUIContent("Remove/Active category"), false, delegate()
                {
                    UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get());
                    PrefabCategoryDatabase.Get().RemoveAndDestroyPrefabCategory(PrefabCategoryDatabase.Get().ActivePrefabCategory);
                });
                contextMenu.AddItem(new GUIContent("Remove/All categories"), false, delegate()
                {
                    UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get());
                    PrefabCategoryDatabase.Get().RemoveAndDestroyAllPrefabCategories(true);
                });
                contextMenu.AddItem(new GUIContent("Remove/Empty categories"), false, delegate()
                {
                    UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get());
                    PrefabCategoryDatabase.Get().RemoveAndDestroyEmptyPrefabCategories();
                });
                contextMenu.AddItem(new GUIContent("Clear/Active category"), false, delegate()
                {
                    UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get().ActivePrefabCategory);
                    PrefabCategoryDatabase.Get().ActivePrefabCategory.RemoveAndDestroyAllPrefabs();
                });
                contextMenu.AddItem(new GUIContent("Clear/All categories"), false, delegate()
                {
                    var allCategories = PrefabCategoryDatabase.Get().GetAllPrefabCategories();
                    foreach (var prefabCategory in allCategories)
                    {
                        UndoEx.RecordForToolAction(prefabCategory);
                        prefabCategory.RemoveAndDestroyAllPrefabs();
                    }
                });
                contextMenu.ShowAsContext();
            }
        }
コード例 #26
0
        private void RenderActiveCategoryNameChangeTextField()
        {
            PrefabCategoryDatabase prefabCategoryDatabase = PrefabCategoryDatabase.Get();
            PrefabCategory         activeCategory         = prefabCategoryDatabase.ActivePrefabCategory;

            if (prefabCategoryDatabase.CanPrefabCategoryBeRenamed(activeCategory))
            {
                string newString = EditorGUILayoutEx.DelayedTextField(GetContentForActiveCategoryNameChangeField(), activeCategory.Name);
                if (newString != activeCategory.Name)
                {
                    UndoEx.RecordForToolAction(activeCategory);
                    prefabCategoryDatabase.RenamePrefabCategory(activeCategory, newString);
                }
            }
            else
            {
                EditorGUILayoutEx.InformativeLabel("The default category can not be renamed.");
            }
        }
コード例 #27
0
        private static void EnsureGuideUsesActivePrefab()
        {
            PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory;

            if (activePrefabCategory != null)
            {
                Prefab activePrefab = activePrefabCategory.ActivePrefab;
                if (activePrefab != null)
                {
                    if (!ObjectPlacementGuide.ExistsInScene)
                    {
                        ObjectPlacementGuide.CreateFromActivePrefabIfNotExists();
                    }
                    else if (ObjectPlacementGuide.Instance.SourcePrefab != activePrefab)
                    {
                        ObjectPlacement.Get().DestroyPlacementGuide();
                        ObjectPlacementGuide.CreateFromActivePrefabIfNotExists();
                    }
                }
            }
        }
コード例 #28
0
        public void RemoveNullPrefabReferences()
        {
            if (PrefabPreviewTextureCache.Get() == null)
            {
                return;
            }
            if (PrefabCategoryDatabase.Get() == null)
            {
                return;
            }
            if (DecorPaintObjectPlacementBrushDatabase.Get() == null)
            {
                return;
            }
            if (ObjectPlacement.Get() == null)
            {
                return;
            }

            PrefabPreviewTextureCache.Get().DestroyTexturesForNullPrefabEntries();
            PrefabCategoryDatabase.Get().RemoveNullPrefabEntriesInAllCategories();
            DecorPaintObjectPlacementBrushDatabase.Get().RemoveNullPrefabsFromAllBrushElements();
            ObjectPlacement.Get().PathObjectPlacement.PathSettings.TileConnectionSettings.RemoveNullPrefabReferences();
        }
コード例 #29
0
        private void RemoveNullGameObjectReferences()
        {
            ObjectSelection.Get().RemoveNullGameObjectEntries();
            Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase.RemoveGroupsWithNullParents();
            ObjectSnapping.Get().ObjectSnapMask.RemoveInvalidEntries();
            DecorPaintObjectPlacement.Get().DecorPaintMask.RemoveInvalidEntries();

            if (PrefabTagDatabase.Get().ContainsNullEntries())
            {
                Debug.Log("Detected null prefab tag references. This bug has been fixed and should never happen. If you are reading this, please contact me.");

                List <PrefabCategory> allPrefabCategories = PrefabCategoryDatabase.Get().GetAllPrefabCategories();
                foreach (var category in allPrefabCategories)
                {
                    List <Prefab> allPrefabsInCategory = category.GetAllPrefabs();
                    foreach (var prefab in allPrefabsInCategory)
                    {
                        prefab.TagAssociations.RemoveNullEntries();
                    }
                }

                PrefabTagDatabase.Get().RemoveNullEntries();
            }
        }
コード例 #30
0
        public static Prefab CreateFromSelectedObjects(Pivot prefabPivot)
        {
            // Ensure that all necessary data is in place
            ObjectSelectionPrefabCreationSettings prefabCreationSettings = ObjectSelectionPrefabCreationSettings.Get();

            if (string.IsNullOrEmpty(prefabCreationSettings.PrefabName) || string.IsNullOrEmpty(prefabCreationSettings.DestinationFolder))
            {
                return(null);
            }
            if (ObjectSelection.Get().NumberOfSelectedObjects == 0)
            {
                return(null);
            }

            List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();

            if (allSelectedObjects.Count == 0)
            {
                return(null);
            }

            // Check if a prefab with the same name already exists
            bool       shouldPrefabBeCreated = true;
            GameObject prefabWithSameName    = ProjectAssetDatabase.LoadPrefabWithNameInFolder(prefabCreationSettings.PrefabName, prefabCreationSettings.DestinationFolder, false);

            if (prefabWithSameName != null)
            {
                if (EditorUtility.DisplayDialog("Are you sure?", "A prefab with the specified name already exists in the specified folder. Would you like to overwrite it?", "Yes", "No"))
                {
                    // If the user chose 'Yes', we have to remove the existing prefab from its category
                    PrefabCategory categoryWhichContainsSamePrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(prefabWithSameName);
                    if (categoryWhichContainsSamePrefab != null)
                    {
                        categoryWhichContainsSamePrefab.RemoveAndDestroyPrefab(prefabWithSameName);
                    }
                }
                else
                {
                    shouldPrefabBeCreated = false;
                }
            }
            if (!shouldPrefabBeCreated)
            {
                return(null);
            }

            // Create all the objects which will reside in the prefab hierarchy
            GameObject prefabRoot = new GameObject(prefabCreationSettings.PrefabName);
            Box        objectCollectionWorldBox    = Box.GetInvalid();
            var        allObjectsInPrefabHierarchy = new List <GameObject>();

            foreach (GameObject gameObject in allSelectedObjects)
            {
                Transform  gameObjectTransform = gameObject.transform;
                GameObject gameObjectClone     = Octave3DWorldBuilder.Instantiate(gameObject, gameObjectTransform.position, gameObjectTransform.rotation) as GameObject;
                allObjectsInPrefabHierarchy.Add(gameObjectClone);

                Transform cloneTransform = gameObjectClone.transform;
                gameObjectClone.name      = gameObject.name;
                cloneTransform.localScale = gameObjectTransform.lossyScale;

                if (objectCollectionWorldBox.IsValid())
                {
                    objectCollectionWorldBox.Encapsulate(gameObjectClone.GetWorldBox());
                }
                else
                {
                    objectCollectionWorldBox = gameObjectClone.GetWorldBox();
                }
            }

            // Now calculate the root object's position based on the specified pivot point
            Transform prefabRootTransform = prefabRoot.transform;

            if (prefabPivot == Pivot.Center)
            {
                prefabRootTransform.position = objectCollectionWorldBox.Center;
            }
            else if (prefabPivot == Pivot.BottomCenter)
            {
                prefabRootTransform.position = objectCollectionWorldBox.GetBoxFaceCenter(BoxFace.Bottom);
            }

            // Now that the root object's position is in place, attach all objects as children of the root
            foreach (GameObject gameObject in allObjectsInPrefabHierarchy)
            {
                gameObject.transform.parent = prefabRootTransform;
            }

            // Create the prefab and assign it to the chosen category
            GameObject createdUnityPrefab = ProjectAssetDatabase.CreatePrefab(prefabRoot, prefabCreationSettings.PrefabName, prefabCreationSettings.DestinationFolder);

            if (createdUnityPrefab == null)
            {
                return(null);
            }

            UndoEx.RecordForToolAction(prefabCreationSettings.DestinationCategory);
            Prefab createdPrefab = PrefabFactory.Create(createdUnityPrefab);

            prefabCreationSettings.DestinationCategory.AddPrefab(createdPrefab);

            Octave3DWorldBuilder.DestroyImmediate(prefabRoot);
            PrefabManagementWindow.Get().RepaintOctave3DWindow();

            return(createdPrefab);
        }