I made this script to add a button to set the pivot the bottom of the mesh.
It works as it should but I also want to call it with a shortcut.
How can I do so? I tried to add a MenuAction but it just won’t show in Unity’s shortcuts manager.
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;
namespace UnityEditor.ProBuilder.Actions
{
[ProBuilderMenuAction]
public class SetPivotLowerCenterAction : MenuAction
{
public const string Name = "Set Pivot @LowerCenter";
public override ToolbarGroup group
{
get { return ToolbarGroup.Object; }
}
public override Texture2D icon
{
get { return null; }
}
public override TooltipContent tooltip
{
get { return k_Tooltip; }
}
internal const char CMD_SUPER = '\u2318';
// What to show in the hover tooltip window. TooltipContent is similar to GUIContent, with the exception
// that it also includes an optional params[] char list in the constructor to define shortcut keys
// (ex, CMD_CONTROL, K).
static readonly TooltipContent k_Tooltip = new TooltipContent(
Name,
Name,
CMD_SUPER, 'K'
);
// Determines if the action should be enabled or shown as disabled in the menu.
public override bool enabled
{
get { return MeshSelection.selectedObjectCount > 0; }
}
[MenuItem("MainMenu/Tools/ProBuilder/Object/" + Name)]
private void Do()
{
// Object[] objects = new Object[MeshSelection.selectedObjectCount * 2];
foreach (var mesh in MeshSelection.top)
{
Undo.RegisterCompleteObjectUndo(mesh, Name);
Undo.RegisterCompleteObjectUndo(mesh.transform, Name);
}
foreach (var mesh in MeshSelection.top)
{
// TransformUtility.UnparentChildren(mesh.transform);
var bounds = mesh.GetComponent<MeshRenderer>().bounds;
var pivotPoint = bounds.center;
pivotPoint.y = bounds.min.y;
mesh.SetPivot(pivotPoint);
mesh.Optimize();
// TransformUtility.ReparentChildren(mesh.transform);
}
ProBuilderEditor.Refresh();
}
public override ActionResult DoAction()
{
if (MeshSelection.selectedObjectCount < 1)
return ActionResult.NoSelection;
// Object[] objects = new Object[MeshSelection.selectedObjectCount * 2];
foreach (var mesh in MeshSelection.top)
{
Undo.RegisterCompleteObjectUndo(mesh, Name);
Undo.RegisterCompleteObjectUndo(mesh.transform, Name);
}
foreach (var mesh in MeshSelection.top)
{
// TransformUtility.UnparentChildren(mesh.transform);
var bounds = mesh.GetComponent<MeshRenderer>().bounds;
var pivotPoint = bounds.center;
pivotPoint.y = bounds.min.y;
mesh.SetPivot(pivotPoint);
mesh.Optimize();
// TransformUtility.ReparentChildren(mesh.transform);
}
ProBuilderEditor.Refresh();
return new ActionResult(ActionResult.Status.Success, Name);
}
}
}

