private void RenderCreateNewGroupButton()
 {
     if (GUILayout.Button(GetContentForCreateNewGroupButton(), GUILayout.Width(100.0f)))
     {
         UndoEx.RecordForToolAction(_database);
         _database.CreateObjectGroup(ViewData.NameForNewGroup);
     }
 }
Beispiel #2
0
        private static void ReadAllPrefabCategories(XmlNode prefabCategoryDatabaseNodes)
        {
            XmlNodeList prefabCategoryNodes = prefabCategoryDatabaseNodes.ChildNodes;

            if (prefabCategoryNodes.Count == 0)
            {
                return;
            }

            for (int categoryNodeIndex = 0; categoryNodeIndex < prefabCategoryNodes.Count; ++categoryNodeIndex)
            {
                EditorUtility.DisplayProgressBar("Loading prefab categories...", "", (categoryNodeIndex + 1) / (float)prefabCategoryNodes.Count);

                XmlNode categoryNode     = prefabCategoryNodes[categoryNodeIndex];
                XmlNode categoryNameNode = categoryNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabCategoryNameNode);
                if (categoryNameNode == null)
                {
                    continue;
                }
                XmlNode objGroupNameNode      = categoryNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabCategoryAssociatedObjectGroupNameNode);
                XmlNode folderNamesParentNode = categoryNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabCategoryFolderNamesParentNode);

                string categoryName = categoryNameNode.InnerText;
                if (string.IsNullOrEmpty(categoryName))
                {
                    continue;
                }

                PrefabCategory prefabCategory  = null;
                PrefabCategory defaultCategory = PrefabCategoryDatabase.Get().GetDefaultPrefabCategory();
                if (categoryName != defaultCategory.Name)
                {
                    prefabCategory = PrefabCategoryDatabase.Get().CreatePrefabCategory(categoryName);
                    if (prefabCategory == null)
                    {
                        continue;
                    }
                }
                else
                {
                    prefabCategory = defaultCategory;
                }

                // Note: Can't really understand why this is needed, but without it, the tool throws null ref exceptions
                //       when Undo and Redo after config load.
                UndoEx.RecordForToolAction(prefabCategory);
                if (prefabCategory == defaultCategory)
                {
                    prefabCategory.RemoveAndDestroyAllPrefabs();
                }

                ObjectGroupDatabase groupDatabase = Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase;

                // Check if the prefab category has an object group associated. If it does, attempt to either
                // load it from the database or create a new one if it doesn't exist.
                if (objGroupNameNode != null && !string.IsNullOrEmpty(objGroupNameNode.InnerText))
                {
                    ObjectGroup objectGroup = groupDatabase.GetObjectGroupByName(objGroupNameNode.InnerText);
                    if (objectGroup != null)
                    {
                        prefabCategory.SetObjectGroup(objectGroup);
                    }
                    else
                    {
                        ObjectGroup newGroup = groupDatabase.CreateObjectGroup(objGroupNameNode.InnerText);
                        if (newGroup != null)
                        {
                            prefabCategory.SetObjectGroup(newGroup);
                        }
                    }
                }

                if (folderNamesParentNode != null)
                {
                    var           allChildren    = folderNamesParentNode.ChildNodes;
                    List <string> allFolderNames = new List <string>();
                    foreach (XmlNode child in allChildren)
                    {
                        allFolderNames.Add(child.InnerText);
                    }
                    prefabCategory.SetPathFolderNames(allFolderNames);
                }

                ReadAllPrefabsInCategory(prefabCategory, categoryNode.SelectNodes(PrefabConfigXMLInfo.PrefabCategoryPrefabNode));
            }
            EditorUtility.ClearProgressBar();
        }