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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changes

- [UUM-138261] Fixed an issue where the move handle could create an incorrect displacement of selected elements.
- [UUM-136930] Fixed Arch circumference field not being fully readable in the editor.
- [UUM-132698] Fixed incorrect snapping of the UV Editor MoveTool in the scene.
- [UUM-131032] Added a reset of static variables when entering playmode to allow fast enter playmode compatibility.
Expand Down
21 changes: 12 additions & 9 deletions Editor/EditorCore/VertexManipulationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,28 @@ static void SyncPivotRotation()
{
if (s_PivotRotation != Tools.pivotRotation)
{
s_HandleOrientation.SetValue(Tools.pivotRotation == PivotRotation.Global
? HandleOrientation.World
: HandleOrientation.ActiveObject);
s_HandleOrientation.SetValue(Tools.pivotRotation == PivotRotation.Local

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Have you considered caching Tools.pivotRotation into a local variable at the beginning of SyncPivotRotation()?

Since Tools is a Unity class, accessing Tools.pivotRotation repeatedly (up to 7 times in this method) likely involves native-to-managed bridge transitions. Caching it once makes the code cleaner, guarantees consistency throughout the method execution, and avoids redundant native property lookups.

For example:

static void SyncPivotRotation()
{
    var activePivotRotation = Tools.pivotRotation;
    if (s_PivotRotation != activePivotRotation)
    {
        s_HandleOrientation.SetValue(activePivotRotation == PivotRotation.Local
            ? HandleOrientation.ActiveObject
            : HandleOrientation.World);
        s_PivotRotation = activePivotRotation;
        MeshSelection.InvalidateCaches();
        pivotRotationChanged?.Invoke();
        return;
    }
    // ... use activePivotRotation below
}

🤖 Helpful? 👍/👎 by guardian

? HandleOrientation.ActiveObject
: HandleOrientation.World);
s_PivotRotation = Tools.pivotRotation;
MeshSelection.InvalidateCaches();
pivotRotationChanged?.Invoke();
return;
}

var value = s_HandleOrientation.value;
var unity = value == HandleOrientation.ActiveObject ? PivotRotation.Local : PivotRotation.Global;

if (value != HandleOrientation.ActiveElement)
var customUnityPivotRotation = Tools.pivotRotation != PivotRotation.Global && Tools.pivotRotation != PivotRotation.Local;
// We only sync pivot modes that are compatible with probuilder: Global and Local
if (!customUnityPivotRotation && value != HandleOrientation.ActiveElement)
{
var unity = PivotRotation.Global;
if (value == HandleOrientation.ActiveObject)
unity = PivotRotation.Local;
if (unity != Tools.pivotRotation)
{
s_HandleOrientation.SetValue(Tools.pivotRotation == PivotRotation.Global
? HandleOrientation.World
: HandleOrientation.ActiveObject,
s_HandleOrientation.SetValue(Tools.pivotRotation == PivotRotation.Local
? HandleOrientation.ActiveObject
: HandleOrientation.World,
true);
MeshSelection.InvalidateCaches();
pivotRotationChanged?.Invoke();
Expand Down
72 changes: 72 additions & 0 deletions Tests/Editor/Geometry/VertexManipulationTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
Expand All @@ -12,6 +13,77 @@

class VertexManipulationTests
{
HandleOrientation m_OriginalOrientation;
PivotRotation m_OriginalPivotRotation;

[SetUp]
public void SetUp()
{
m_OriginalOrientation = VertexManipulationTool.handleOrientation;
m_OriginalPivotRotation = Tools.pivotRotation;
}

[TearDown]
public void TearDown()
{
VertexManipulationTool.handleOrientation = m_OriginalOrientation;
Tools.pivotRotation = m_OriginalPivotRotation;
}

#if UNITY_6000_4_OR_NEWER
[Test]
public void SyncPivotRotation_PivotRotationGrid_HandleOrientationIsWorld()
{
Tools.pivotRotation = PivotRotation.Grid;
_ = VertexManipulationTool.handleOrientation; // flush sync

Assert.That(VertexManipulationTool.handleOrientation, Is.EqualTo(HandleOrientation.World));
}
#endif

[Test]
public void SyncPivotRotation_PivotChangesToLocal_HandleOrientationIsActiveObject()
{
Tools.pivotRotation = PivotRotation.Global;
_ = VertexManipulationTool.handleOrientation; // flush sync

Tools.pivotRotation = PivotRotation.Local;
Assert.That(VertexManipulationTool.handleOrientation, Is.EqualTo(HandleOrientation.ActiveObject));
}

[Test]
public void SyncPivotRotation_PivotChangesToGlobal_HandleOrientationIsWorld()
{
Tools.pivotRotation = PivotRotation.Local;
_ = VertexManipulationTool.handleOrientation; // flush sync

Tools.pivotRotation = PivotRotation.Global;
Assert.That(VertexManipulationTool.handleOrientation, Is.EqualTo(HandleOrientation.World));
}

[Test]
public void HandleOrientation_RepeatedAccessWhenInSync_DoesNotFirePivotRotationChangedEvent()
{
VertexManipulationTool.handleOrientation = HandleOrientation.ActiveObject;
Assume.That(Tools.pivotRotation, Is.EqualTo(PivotRotation.Local));

int syncCount = 0;
Action countSync = () => syncCount++;
VertexManipulationTool.pivotRotationChanged += countSync;
try
{
for (int i = 0; i < 20; i++)
_ = VertexManipulationTool.handleOrientation;
}
finally
{
VertexManipulationTool.pivotRotationChanged -= countSync;
}

Assert.That(syncCount, Is.EqualTo(0),
"Accessing handleOrientation in a consistent state must not fire pivotRotationChanged");
}

[UnityTest, Ignore("LINUX_EDITOR")]
public static IEnumerator ExtrudeOrthogonally_OneElementManyTimes_NoYOffsetAccumulates()
{
Expand Down