-
Notifications
You must be signed in to change notification settings - Fork 92
Bugfix/uum 141074 fix create shape gridsnap #671
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
Open
lopezt-unity
wants to merge
5
commits into
master
Choose a base branch
from
bugfix/uum-141074-fix-create-shape-gridsnap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1e25f10
fixed polyshape tool not being able to snap to the grid
lopezt-unity 6f00061
fix pbshape creation not snapping to the grid
lopezt-unity 65db2dd
changelog
lopezt-unity 66143e4
adding tests
lopezt-unity b98b7f9
Updating tests and fixing drawshape tool not deleting tmp gameobject …
lopezt-unity 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
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,112 @@ | ||
| using NUnit.Framework; | ||
| using UnityEditor; | ||
| using UnityEditor.EditorTools; | ||
| using UnityEditor.ProBuilder; | ||
| using UnityEngine; | ||
| using UnityEngine.ProBuilder; | ||
| using ToolManager = UnityEditor.EditorTools.ToolManager; | ||
|
|
||
| public class ShapeToolGridSnapTests | ||
| { | ||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| ToolManager.SetActiveContext<GameObjectToolContext>(); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| ToolManager.RestorePreviousPersistentTool(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void CreateCubeTool_HasGridSnapEnabled() | ||
| { | ||
| ToolManager.SetActiveTool<CreateCubeTool>(); | ||
| var toolType = ToolManager.activeToolType; | ||
|
|
||
| Assert.That(toolType, Is.EqualTo(typeof(CreateCubeTool))); | ||
|
|
||
| // Verify the tool has gridSnapEnabled property set to true | ||
| var tool = DrawShapeTool.instance; | ||
| Assert.That(tool, Is.Not.Null); | ||
| Assert.That(tool.gridSnapEnabled, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void DrawShapeTool_GetPoint_SnapsWhenOnGridAndGridSnapActive() | ||
| { | ||
| ToolManager.SetActiveTool<CreateCubeTool>(); | ||
| var tool = DrawShapeTool.instance; | ||
| Assume.That(tool, Is.Not.Null); | ||
|
|
||
| EditorSnapSettings.gridSnapEnabled = true; | ||
| EditorSnapSettings.snapEnabled = true; | ||
|
|
||
| var previousPivotRotation = Tools.pivotRotation; | ||
| Tools.pivotRotation = PivotRotation.Global; | ||
|
|
||
| // Enable grid mode (this is set by ShapeState_InitShape during hover) | ||
| tool.m_IsOnGrid = true; | ||
|
|
||
| // Only test if grid snapping is currently active in the editor | ||
| if (EditorSnapSettings.gridSnapActive) | ||
| { | ||
| // Test position that should snap to grid | ||
| Vector3 unsnappedPosition = new Vector3(1.23f, 2.34f, 3.45f); | ||
| Vector3 snappedPosition = tool.GetPoint(unsnappedPosition); | ||
|
|
||
| // Position should be snapped (not equal to original) | ||
| Assert.That(snappedPosition, Is.Not.EqualTo(unsnappedPosition)); | ||
| } | ||
| else | ||
| { | ||
| // Skip test if grid snap is not active | ||
| Assert.Ignore("Grid snapping is not active in the editor, skipping snap verification"); | ||
| } | ||
|
|
||
| Tools.pivotRotation = previousPivotRotation; | ||
| } | ||
|
|
||
| [Test] | ||
| public void DrawShapeTool_GetPoint_DoesNotSnapWhenOffGrid() | ||
| { | ||
| ToolManager.SetActiveTool<CreateCubeTool>(); | ||
| var tool = DrawShapeTool.instance; | ||
| Assume.That(tool, Is.Not.Null); | ||
|
|
||
| // Disable grid mode | ||
| tool.m_IsOnGrid = false; | ||
|
|
||
| // Test position should NOT snap regardless of editor snap settings | ||
| Vector3 position = new Vector3(1.23f, 2.34f, 3.45f); | ||
| Vector3 result = tool.GetPoint(position); | ||
|
|
||
| // Position should remain unchanged when m_IsOnGrid is false | ||
| Assert.That(result, Is.EqualTo(position)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void DrawShapeTool_GetPoint_RespectsIncrementalSnap() | ||
| { | ||
| ToolManager.SetActiveTool<CreateCubeTool>(); | ||
| var tool = DrawShapeTool.instance; | ||
| Assume.That(tool, Is.Not.Null); | ||
|
|
||
| // Get current incremental snap value | ||
| Vector3 snapValue = EditorSnapping.incrementalSnapMoveValue; | ||
|
|
||
| // Test with incremental snap enabled | ||
| Vector3 unsnappedPosition = new Vector3(1.23f, 2.34f, 3.45f); | ||
| Vector3 snappedPosition = tool.GetPoint(unsnappedPosition, useIncrementSnap: true); | ||
|
|
||
| // Position should be snapped to incremental snap value | ||
| Assert.That(snappedPosition, Is.Not.EqualTo(unsnappedPosition)); | ||
|
|
||
| // Verify each component is a multiple of snap value (within tolerance) | ||
| Assert.That(snappedPosition.x % snapValue.x, Is.EqualTo(0).Within(0.001f)); | ||
| Assert.That(snappedPosition.y % snapValue.y, Is.EqualTo(0).Within(0.001f)); | ||
| Assert.That(snappedPosition.z % snapValue.z, Is.EqualTo(0).Within(0.001f)); | ||
| } | ||
| } |
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.