-
Notifications
You must be signed in to change notification settings - Fork 89
[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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d144398
Fix the 'Set Double Sided' action in the Editor sample. It couldn't b…
thomas-tu 2888238
Add changelog entry
thomas-tu 9e40c04
Ensure to pass the current status of a MenuAction when there is no op…
thomas-tu cd091e9
Merge branch 'master' into bugfix/sample-menuaction-disabled
thomas-tu 1e9ca3e
Add tests to cover some cases of the contextual menu
thomas-tu b16182d
Merge branch 'bugfix/sample-menuaction-disabled' of github.com:Unity-…
thomas-tu 92c90fb
Update changelog
thomas-tu 7063df0
Clean up
thomas-tu 26f36ac
Merge branch 'master' into bugfix/sample-menuaction-disabled
thomas-tu 52f34e5
Remove unnecessary comment
thomas-tu 2a086c3
Refactor
thomas-tu 49af8d3
Fix changelog after merge
thomas-tu bebb8ac
Clean up documentation in CustomAction.cs
thomas-tu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| 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. | ||
| /// </summary> | ||
| public class ContextualMenuTests | ||
| { | ||
| [ProBuilderMenuAction] | ||
| 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() | ||
| { | ||
| if (m_PBMesh) | ||
| Object.DestroyImmediate(m_PBMesh.gameObject); | ||
| } | ||
|
|
||
| PositionToolContext PrepareToolContext(SelectMode toolSelectMode) | ||
| { | ||
| MeshSelection.SetSelection(m_PBMesh.gameObject); | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| ToolManager.SetActiveContext<PositionToolContext>(); | ||
| Tools.current = Tool.Move; | ||
| ProBuilderEditor.selectMode = toolSelectMode; | ||
| ActiveEditorTracker.sharedTracker.ForceRebuild(); | ||
|
|
||
| PositionToolContext ctx = Resources.FindObjectsOfTypeAll<PositionToolContext>()?[0]; | ||
| Assume.That(ctx, Is.Not.Null); | ||
| return ctx; | ||
| } | ||
|
|
||
| bool CheckDropdownMenuHasItem(string name, DropdownMenuAction.Status status, DropdownMenu menu) | ||
| { | ||
| DropdownMenuAction foundInMenu = null; | ||
| foreach (var t in menu.MenuItems()) | ||
| { | ||
| if (t is not DropdownMenuAction menuAction) | ||
| continue; | ||
|
|
||
| if (menuAction.name == name) | ||
| { | ||
| foundInMenu = menuAction; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return (foundInMenu?.status == status); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(true, ExpectedResult = false)] | ||
| [TestCase(false, ExpectedResult = true)] | ||
| public bool MenuActionWithoutMenuItem_hasFileMenuEntry(bool hasFileMenuEntry) | ||
| { | ||
| var ctx = PrepareToolContext(SelectMode.Face); | ||
|
|
||
| ConfigurableMenuAction.userHasFileMenuEntry = hasFileMenuEntry; | ||
| ConfigurableMenuAction.userSelectMode = SelectMode.Any; | ||
| ConfigurableMenuAction.userEnabled = true; | ||
|
|
||
| DropdownMenu menu = new DropdownMenu(); | ||
| ctx.PopulateMenu(menu); | ||
| menu.PrepareForDisplay(null); | ||
|
|
||
| return CheckDropdownMenuHasItem(ConfigurableMenuAction.actionName, DropdownMenuAction.Status.Normal, menu); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(SelectMode.Edge, ExpectedResult = false)] | ||
| [TestCase(SelectMode.Face, ExpectedResult = true)] | ||
| [TestCase(SelectMode.Vertex, ExpectedResult = false)] | ||
| public bool MenuAction_SelectModeSetToFace_EnabledOnlyForFaceSelection(SelectMode mode) | ||
| { | ||
| var ctx = PrepareToolContext(mode); | ||
|
|
||
| ConfigurableMenuAction.userHasFileMenuEntry = false; | ||
| ConfigurableMenuAction.userSelectMode = SelectMode.Face; | ||
| ConfigurableMenuAction.userEnabled = true; | ||
|
|
||
| DropdownMenu menu = new DropdownMenu(); | ||
| ctx.PopulateMenu(menu); | ||
| menu.PrepareForDisplay(null); | ||
|
|
||
| // MenuAction is expected to be present in the menu only when the mode matches. | ||
| return CheckDropdownMenuHasItem(ConfigurableMenuAction.actionName, DropdownMenuAction.Status.Normal, menu); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(true, ExpectedResult = true)] | ||
| [TestCase(false, ExpectedResult = false)] | ||
| public bool MenuAction_enabledPropertyIsFollowedByMenu(bool enabled) | ||
| { | ||
| var ctx = PrepareToolContext(SelectMode.Face); | ||
|
|
||
| ConfigurableMenuAction.userHasFileMenuEntry = false; | ||
| ConfigurableMenuAction.userSelectMode = SelectMode.Face; | ||
| ConfigurableMenuAction.userEnabled = enabled; | ||
|
|
||
| DropdownMenu menu = new DropdownMenu(); | ||
| ctx.PopulateMenu(menu); | ||
| menu.PrepareForDisplay(null); | ||
|
|
||
| return CheckDropdownMenuHasItem(ConfigurableMenuAction.actionName, DropdownMenuAction.Status.Normal, menu); | ||
| } | ||
| } | ||
thomas-tu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.