After playing around with the Unity UIToolkit - Introduction To Editor Scripting course, here’s a bodge:
Create a folder called “Editor”. Inside create a new C# script called “SpriteShapeHeightEditor” and replace with the below code. Compile.
This creates a menu in the Unity Editor called “Custom”. Click on the menu item. Change the height to the desired value, click on a sprite shape (so that the game object appears in the inspector), click Change Height.
Tested in 2021.2.1f1 and 2020.3.22f1.
Please save your project though in case it does something wonky.
using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
public class SpriteShapeHeightEditor : EditorWindow
{
FloatField floatField;
[MenuItem("Custom/Edit Sprite Shape Height")]
public static void ShowWindow()
{
SpriteShapeHeightEditor window = GetWindow<SpriteShapeHeightEditor>();
window.titleContent = new GUIContent("Edit Sprite Shape Height");
}
public void CreateGUI()
{
rootVisualElement.Add(new Button(EditHeights) { text = "Change Height"});
floatField = new FloatField("Height");
floatField.value = 1f;
rootVisualElement.Add(floatField);
floatField.RegisterCallback<ChangeEvent<float>>(evt => { floatField.value = Mathf.Clamp(evt.newValue, 0.1f, 4f); });
}
void EditHeights()
{
if (!Selection.activeGameObject.TryGetComponent<UnityEngine.U2D.SpriteShapeController>(out UnityEngine.U2D.SpriteShapeController spriteShape)) return;
Tools.current = Tool.View; // fudge, if in edit spline mode the changes dont seem to apply
Undo.RecordObject(spriteShape, $"Set Sprite Shape Height to {floatField.value}");
for (int i = 0; i < spriteShape.spline.GetPointCount(); i++) spriteShape.spline.SetHeight(i, floatField.value);
EditorUtility.SetDirty(spriteShape);
}
}
2 votes on the Unity Bug Tracker. Don’t think this will be fixed anytime soon!