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 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(); }