コード例 #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 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();
        }
コード例 #3
0
        protected override void RenderContent()
        {
            EditorGUILayoutEx.BeginVerticalBox();

            EditorGUILayout.BeginHorizontal();
            const float alignButtonWidth = 72.0f;
            var         content          = new GUIContent();

            content.text    = "Align X";
            content.tooltip = "Aligns the positions of the selected objects to the X axis.";
            if (GUILayout.Button(content, GUILayout.Width(alignButtonWidth)))
            {
                ObjectSelectionActions.AlignSelectionToAxis(Axis.X);
            }

            content.text    = "Align Y";
            content.tooltip = "Aligns the positions of the selected objects to the Y axis.";
            if (GUILayout.Button(content, GUILayout.Width(alignButtonWidth)))
            {
                ObjectSelectionActions.AlignSelectionToAxis(Axis.Y);
            }

            content.text    = "Align Z";
            content.tooltip = "Aligns the positions of the selected objects to the Z axis.";
            if (GUILayout.Button(content, GUILayout.Width(alignButtonWidth)))
            {
                ObjectSelectionActions.AlignSelectionToAxis(Axis.Z);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            RenderMakeSelectionStaticButton();
            RenderMakeSelectionDynamicButton();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            RenderInvertSelectionButton();
            content.text    = "Grab settings...";
            content.tooltip = "Opens up a new window which allows you to modify selection grab settings.";
            if (GUILayout.Button(content, GUILayout.Width(110.0f)))
            {
                Octave3DWorldBuilder.ActiveInstance.EditorWindowPool.SelectionGrabSettingsWindow.ObjectGrabSettings = ObjectSelection.Get().SelectionGrabSettings;
                Octave3DWorldBuilder.ActiveInstance.EditorWindowPool.SelectionGrabSettingsWindow.ShowOctave3DWindow();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            RenderAssignSelectionToLayerButton();
            RenderSelectionAssignmentLayerSelectionPopup();
            EditorGUILayout.EndHorizontal();

            if (ObjectGroupDatabase.Get().NumberOfGroups != 0)
            {
                if (string.IsNullOrEmpty(ViewData.DestObjectGroupName))
                {
                    ViewData.DestObjectGroupName = ObjectGroupDatabase.Get().GetObjectGroupByIndex(0).Name;
                }
                else
                {
                    if (ObjectGroupDatabase.Get().GetObjectGroupByName(ViewData.DestObjectGroupName) == null)
                    {
                        ViewData.DestObjectGroupName = ObjectGroupDatabase.Get().GetObjectGroupByIndex(0).Name;
                    }
                }

                EditorGUILayout.BeginHorizontal();
                content.text    = "Assign to group";
                content.tooltip = "Assigns the object selection to the specified object group.";
                if (GUILayout.Button(content, GUILayout.Width(110.0f)))
                {
                    ObjectGroup destObjectGroup = ObjectGroupDatabase.Get().GetObjectGroupByName(ViewData.DestObjectGroupName);
                    if (destObjectGroup != null)
                    {
                        ObjectActions.AssignObjectsToGroup(ObjectSelection.Get().GetAllSelectedGameObjects(), destObjectGroup);
                    }
                }

                string newGroupName = EditorGUILayoutEx.Popup(new GUIContent(), ViewData.DestObjectGroupName, ObjectGroupDatabase.Get().GetAllObjectGroupNames());
                if (newGroupName != ViewData.DestObjectGroupName)
                {
                    UndoEx.RecordForToolAction(ViewData);
                    ViewData.DestObjectGroupName = newGroupName;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayoutEx.EndVerticalBox();
        }
コード例 #4
0
 public ObjectGroupDatabaseView(ObjectGroupDatabase database)
 {
     _database = database;
 }
コード例 #5
0
        protected override void RenderContent()
        {
            float newFloat; bool newBool; string newString;

            EditorGUILayout.LabelField("Object groups", EditorStyles.boldLabel);
            var content = new GUIContent();

            content.text    = "Attach to object group";
            content.tooltip = "If this is checked, any objects which are created via selection operations will be attached to a group of your choosing.";
            newBool         = EditorGUILayout.ToggleLeft(content, _settings.ObjectGroupSettings.AttachToObjectGroup);
            if (newBool != _settings.ObjectGroupSettings.AttachToObjectGroup)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.ObjectGroupSettings.AttachToObjectGroup = newBool;
            }

            ObjectGroupDatabase objectGroupDatabase = Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase;

            if (objectGroupDatabase.NumberOfGroups == 0)
            {
                EditorGUILayout.HelpBox("No object groups are currently available.", UnityEditor.MessageType.None);
            }
            else
            {
                if (_settings.ObjectGroupSettings.DestinationGroup == null)
                {
                    _settings.ObjectGroupSettings.DestinationGroup = objectGroupDatabase.GetAllObjectGroups()[0];
                }

                content.text    = "Object group";
                content.tooltip = "If \'Attach to object group\' is checked, any objects which are created via selection operations will be attached to this group.";
                newString       = EditorGUILayoutEx.Popup(content, _settings.ObjectGroupSettings.DestinationGroup.Name, objectGroupDatabase.GetAllObjectGroupNames());
                if (newString != _settings.ObjectGroupSettings.DestinationGroup.Name)
                {
                    UndoEx.RecordForToolAction(_settings);
                    _settings.ObjectGroupSettings.DestinationGroup = objectGroupDatabase.GetObjectGroupByName(newString);
                }
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Rotation", EditorStyles.boldLabel);
            content.text    = "X rotation step";
            content.tooltip = "Allows you to specify how much rotation is applied to the selected objects when the X rotation key is pressed.";
            newFloat        = EditorGUILayout.FloatField(content, _settings.XRotationStep);
            if (newFloat != _settings.XRotationStep)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.XRotationStep = newFloat;
            }

            content.text    = "Y rotation step";
            content.tooltip = "Allows you to specify how much rotation is applied to the selected objects when the Y rotation key is pressed.";
            newFloat        = EditorGUILayout.FloatField(content, _settings.YRotationStep);
            if (newFloat != _settings.YRotationStep)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.YRotationStep = newFloat;
            }

            content.text    = "Z rotation step";
            content.tooltip = "Allows you to specify how much rotation is applied to the selected objects when the Z rotation key is pressed.";
            newFloat        = EditorGUILayout.FloatField(content, _settings.ZRotationStep);
            if (newFloat != _settings.ZRotationStep)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.ZRotationStep = newFloat;
            }

            content.text    = "Rotate around selection center";
            content.tooltip = "If this is checked, the rotation will happen around the selection's world center. Otherwise, each object will be rotated around its own center.";
            newBool         = EditorGUILayout.ToggleLeft(content, _settings.RotateAroundSelectionCenter);
            if (newBool != _settings.RotateAroundSelectionCenter)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.RotateAroundSelectionCenter = newBool;
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Object 2 object snap", EditorStyles.boldLabel);
            content.text    = "Snap epsilon";
            content.tooltip = "The selected objects will always snap to nearby objects which are \'epsilon\' units away from the selected objects.";
            newFloat        = EditorGUILayout.FloatField(content, _settings.Object2ObjectSnapSettings.SnapEps);
            if (newFloat != _settings.Object2ObjectSnapSettings.SnapEps)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.Object2ObjectSnapSettings.SnapEps = newFloat;
            }

            content.text    = "Can hover objects";
            content.tooltip = "If this is checked, you will be able to hover other objects during a snap session. Otherwise, you will only be able to hover the grid surface.";
            newBool         = EditorGUILayout.ToggleLeft(content, _settings.Object2ObjectSnapSettings.CanHoverObjects);
            if (newBool != _settings.Object2ObjectSnapSettings.CanHoverObjects)
            {
                UndoEx.RecordForToolAction(_settings);
                _settings.Object2ObjectSnapSettings.CanHoverObjects = newBool;
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Misc", EditorStyles.boldLabel);
            RenderAllowPartialOverlapToggle();
            RenderSelectionShapeTypeSelectionPopup();
            RenderSelectionUpdateModeSelectionPopup();
            RenderSelectionModeSelectionPopup();

            if (_settings.SelectionMode == ObjectSelectionMode.Paint)
            {
                _settings.PaintModeSettings.View.Render();
            }
        }