Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed

- [UUM-133861] Fixed "Look rotation viewing vector is zero" log being spammed when holding shift while using a create tool such as Create Sprite.
- [UUM-133530] Fixed the `Set Double Sided` custom action in the Editor Sample, which was previously remaining disabled.
- [UUM-133530] Ensured that the context menu respects the value of `MenuAction.enabled`.
- [UUM-133531] Fixed component icons in Light theme.
- [UUM-133526] Material Editor: fixed a warning (`GUI Error: Invalid GUILayout state in MaterialEditor view.`) that was thrown when deleting an extra material slot.
- Fixed warnings related to obsolete API calls with Unity 6.4 and onwards.
Expand Down
2 changes: 1 addition & 1 deletion Editor/EditorCore/ProBuilderToolsContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override void PopulateMenu(DropdownMenu menu)
menu.AppendAction(title, _ => EditorAction.Start(new MenuActionSettings(action, HasPreview(action))), GetStatus(action));
}
else
menu.AppendAction(GetMenuTitle(action, title), _ => action.PerformAction());
menu.AppendAction(GetMenuTitle(action, title), _ => action.PerformAction(), GetStatus(action));
}
}

Expand Down
6 changes: 3 additions & 3 deletions Samples~/Editor/CustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ public class MakeFacesDoubleSided : MenuAction
/// <summary>
/// Determines if the action should be enabled or grayed out.
/// </summary>
/// <returns></returns>
public override bool enabled
{
get { return MeshSelection.selectedFaceCount > 0; }
get { return base.enabled && MeshSelection.selectedFaceCount > 0; }
}

protected override bool hasFileMenuEntry => false;

/// <summary>
/// This action is applicable in Face selection modes.
/// </summary>
Expand All @@ -52,7 +53,6 @@ public override SelectMode validSelectModes
/// <summary>
/// Return a pb_ActionResult indicating the success/failure of action.
/// </summary>
/// <returns></returns>
protected override ActionResult PerformActionImplementation()
{
var selection = MeshSelection.top.ToArray();
Expand Down
153 changes: 153 additions & 0 deletions Tests/Editor/Actions/ContextualMenuTests.cs
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);
}
}
2 changes: 2 additions & 0 deletions Tests/Editor/Actions/ContextualMenuTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.