-
Notifications
You must be signed in to change notification settings - Fork 88
[UUM-133530] Ensure "Set Double Sided" is enabled when active selection is proper #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
d144398
2888238
9e40c04
cd091e9
1e9ca3e
b16182d
92c90fb
7063df0
26f36ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| using NUnit.Framework; | ||
| using UnityEditor; | ||
| using UnityEditor.EditorTools; | ||
| using UnityEditor.ProBuilder; | ||
| using UnityEngine; | ||
| using UnityEngine.ProBuilder; | ||
| using UnityEngine.UIElements; | ||
|
|
||
| /// <summary> | ||
| /// Test the construction of the contextual menu in the Scene View. | ||
| /// It doesn't cover the cases where a MenuAction has a file menu entry. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand this comment. Aren't you doing a file menu entry test below? |
||
| /// </summary> | ||
| public class ContextualMenuTests | ||
| { | ||
| [ProBuilderMenuAction] | ||
| public class ConfigurableMenuAction : MenuAction | ||
| { | ||
| internal const string actionName = "Action Without File Menu Entry"; | ||
| internal static bool userHasFileMenuEntry { get; set; } | ||
| internal static SelectMode userSelectMode { get; set; } | ||
| internal static bool userEnabled { get; set; } | ||
|
|
||
| public override ToolbarGroup group | ||
| { | ||
| get { return ToolbarGroup.Geometry; } | ||
| } | ||
|
|
||
| public override Texture2D icon => null; | ||
|
|
||
| public override string iconPath => string.Empty; | ||
|
|
||
| public override TooltipContent tooltip => new TooltipContent( | ||
| actionName, | ||
| @"This action should not have a file menu entry." | ||
| ); | ||
|
|
||
| public ConfigurableMenuAction() | ||
| { | ||
| } | ||
|
|
||
| protected override ActionResult PerformActionImplementation() | ||
| { | ||
| return ActionResult.Success; | ||
| } | ||
|
|
||
| public override SelectMode validSelectModes => userSelectMode; | ||
| public override bool enabled => userEnabled; | ||
| protected internal override bool hasFileMenuEntry => userHasFileMenuEntry; | ||
| } | ||
|
|
||
| ProBuilderMesh m_PBMesh; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| m_PBMesh = ShapeFactory.Instantiate(typeof(UnityEngine.ProBuilder.Shapes.Plane)); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this need [Teardown] ? |
||
| { | ||
| if (m_PBMesh) | ||
| Object.DestroyImmediate(m_PBMesh.gameObject); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(true, ExpectedResult = false)] | ||
| [TestCase(false, ExpectedResult = true)] | ||
| public bool MenuActionWithoutMenuItem_hasFileMenuEntry(bool hasFileMenuEntry) | ||
| { | ||
| MeshSelection.SetSelection(m_PBMesh.gameObject); | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| ToolManager.SetActiveContext<PositionToolContext>(); | ||
| Tools.current = Tool.Move; | ||
| ProBuilderEditor.selectMode = SelectMode.Face; | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| ConfigurableMenuAction.userHasFileMenuEntry = hasFileMenuEntry; | ||
| ConfigurableMenuAction.userSelectMode = SelectMode.Any; | ||
| ConfigurableMenuAction.userEnabled = true; | ||
|
|
||
| DropdownMenu menu = new DropdownMenu(); | ||
| PositionToolContext ctx = Resources.FindObjectsOfTypeAll<PositionToolContext>()?[0]; | ||
| Assume.That(ctx, Is.Not.Null); | ||
|
|
||
| ctx.PopulateMenu(menu); | ||
| menu.PrepareForDisplay(null); | ||
| DropdownMenuAction foundInMenu = null; | ||
| foreach (var t in menu.MenuItems()) | ||
| { | ||
| if (t is not DropdownMenuAction menuAction) | ||
| continue; | ||
|
|
||
| if (menuAction.name == ConfigurableMenuAction.actionName) | ||
| { | ||
| foundInMenu = menuAction; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Assert.That(foundInMenu, Is.Not.Null, "MenuAction should be present in the Contextual Menu regardless of hasFileMenuEntry value."); | ||
| return (foundInMenu.status == DropdownMenuAction.Status.Normal); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(SelectMode.Edge, ExpectedResult = false)] | ||
| [TestCase(SelectMode.Face, ExpectedResult = true)] | ||
| [TestCase(SelectMode.Vertex, ExpectedResult = false)] | ||
| public bool MenuAction_SelectModeSetToFace_EnabledOnlyForFaceSelection(SelectMode mode) | ||
| { | ||
| MeshSelection.SetSelection(m_PBMesh.gameObject); | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| ToolManager.SetActiveContext<PositionToolContext>(); | ||
| Tools.current = Tool.Move; | ||
| ProBuilderEditor.selectMode = mode; | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| ConfigurableMenuAction.userHasFileMenuEntry = false; | ||
| ConfigurableMenuAction.userSelectMode = SelectMode.Face; | ||
| ConfigurableMenuAction.userEnabled = true; | ||
|
|
||
| DropdownMenu menu = new DropdownMenu(); | ||
| PositionToolContext ctx = Resources.FindObjectsOfTypeAll<PositionToolContext>()?[0]; | ||
| Assume.That(ctx, Is.Not.Null); | ||
|
|
||
| ctx.PopulateMenu(menu); | ||
| menu.PrepareForDisplay(null); | ||
| DropdownMenuAction foundInMenu = null; | ||
| foreach (var t in menu.MenuItems()) | ||
| { | ||
| if (t is not DropdownMenuAction menuAction) | ||
| continue; | ||
|
|
||
| if (menuAction.name == ConfigurableMenuAction.actionName) | ||
| { | ||
| foundInMenu = menuAction; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // MenuAction is expected to be present in the menu only when the mode matches. | ||
| return (foundInMenu != null); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(true, ExpectedResult = true)] | ||
| [TestCase(false, ExpectedResult = false)] | ||
| public bool MenuAction_enabledPropertyIsFollowedByMenu(bool enabled) | ||
| { | ||
| MeshSelection.SetSelection(m_PBMesh.gameObject); | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| ToolManager.SetActiveContext<PositionToolContext>(); | ||
| Tools.current = Tool.Move; | ||
| ProBuilderEditor.selectMode = SelectMode.Face; | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| ConfigurableMenuAction.userHasFileMenuEntry = false; | ||
| ConfigurableMenuAction.userSelectMode = SelectMode.Face; | ||
| ConfigurableMenuAction.userEnabled = enabled; | ||
|
|
||
| DropdownMenu menu = new DropdownMenu(); | ||
| PositionToolContext ctx = Resources.FindObjectsOfTypeAll<PositionToolContext>()?[0]; | ||
| Assume.That(ctx, Is.Not.Null); | ||
|
|
||
| ctx.PopulateMenu(menu); | ||
| menu.PrepareForDisplay(null); | ||
| DropdownMenuAction foundInMenu = null; | ||
| foreach (var t in menu.MenuItems()) | ||
| { | ||
| if (t is not DropdownMenuAction menuAction) | ||
| continue; | ||
|
|
||
| if (menuAction.name == ConfigurableMenuAction.actionName) | ||
| { | ||
| foundInMenu = menuAction; | ||
| break; | ||
| } | ||
| } | ||
| return (foundInMenu.status == DropdownMenuAction.Status.Normal); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lots of duplicated code, can't we combine this in a single method?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven;t tested yet, but quickly with AI, it proposed this:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and your test becomes |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML documentation tag is empty and is generally used for methods rather than properties. For properties, the
or tags are standard. Consider removing the empty tag to keep the documentation clean.
🤖 Helpful? 👍/👎