Skip to content
Open
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
45 changes: 27 additions & 18 deletions Tests/Editor/Picking/EdgePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ public IEnumerator EdgePicker_PicksVisibleEdge()

yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Edge,
m_PickerPreferences);

using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Edge,
m_PickerPreferences);
}

yield return null;

Expand All @@ -130,12 +131,13 @@ public IEnumerator EdgePicker_DoesntPickHiddenEdge()

yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Edge,
m_PickerPreferences);

}

yield return null;

Expand All @@ -153,11 +155,13 @@ public IEnumerator EdgePicker_DoesNotPickWhenNotHovering()
{
Vector2 mousePos = new Vector2(Screen.width / 2f, Screen.height / 2f + 500f);

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Edge,
m_PickerPreferences);
}

yield return null;

Expand Down Expand Up @@ -191,11 +195,13 @@ public IEnumerator EdgePicker_PicksCorrectEdgeWithMultipleOverlapping()

Vector2 mousePos = UnityEditor.HandleUtility.WorldToGUIPoint(center1_world);

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Edge,
m_PickerPreferences);
}

yield return null;

Expand Down Expand Up @@ -229,11 +235,13 @@ public IEnumerator EdgePicker_PicksClippedEdge_OnePointBehindCamera()
Vector3 centerOfEdge_world = (pA_world + pB_world) / 2f;
Vector2 mousePos = UnityEditor.HandleUtility.WorldToGUIPoint(centerOfEdge_world);

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Edge,
m_PickerPreferences);
}

yield return null;

Expand Down Expand Up @@ -270,12 +278,13 @@ public IEnumerator EdgePicker_DoesNotPickEdge_BothPointsBehindCamera()

yield return null;

UnityEngine.TestTools.LogAssert.Expect("Handles.GetClosestPickingID called outside an editor OnGUI");
UnityEngine.TestTools.LogAssert.Expect("Assertion failed on expression: 'device.IsInsideFrame()'");
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Edge,
m_PickerPreferences);
}

yield return null;

Expand Down
116 changes: 77 additions & 39 deletions Tests/Editor/Picking/FacePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ public IEnumerator FacePicker_PicksVisibleFace()

yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true; // Ignore logs due to not executing OnGUI loop
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face, // Select faces
m_PickerPreferences);

}
yield return null;

SceneSelection currentSelection = EditorSceneViewPicker.selection;
Expand All @@ -124,12 +125,13 @@ public IEnumerator FacePicker_DoesNotPickWhenNotHovering()

yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);

}
yield return null;

SceneSelection currentSelection = EditorSceneViewPicker.selection;
Expand Down Expand Up @@ -161,12 +163,13 @@ public IEnumerator FacePicker_PicksClosestFaceWithMultipleOverlappingProBuilderM

yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);

}
yield return null;

SceneSelection currentSelection = EditorSceneViewPicker.selection;
Expand Down Expand Up @@ -194,14 +197,16 @@ public IEnumerator FacePicker_PicksProBuilderFaceOverlappingNonProBuilderGameObj


yield return null;
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
using (new IgnoreAssertScope())
{

// As per the provided EditorSceneViewPicker.cs (second version),
// ProBuilder faces are prioritized if any are hit.
EditorSceneViewPicker.DoMouseClick(
// As per the provided EditorSceneViewPicker.cs (second version),
// ProBuilder faces are prioritized if any are hit.
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);
}

yield return null;

Expand Down Expand Up @@ -261,13 +266,14 @@ public IEnumerator FacePicker_CyclesThroughOverlappingProBuilderFacesOnRepeatedC

yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;

// --- First click: Should pick the front mesh (mesh3)
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);
}

yield return null;

Expand All @@ -277,11 +283,13 @@ public IEnumerator FacePicker_CyclesThroughOverlappingProBuilderFacesOnRepeatedC
Assert.AreEqual(face3, currentSelection.faces.First(), "First click: The front face should be picked.");

// --- Second click: Should pick the middle mesh due to deep cycling
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);

}
yield return null;

currentSelection = EditorSceneViewPicker.selection;
Expand All @@ -290,11 +298,13 @@ public IEnumerator FacePicker_CyclesThroughOverlappingProBuilderFacesOnRepeatedC
Assert.AreEqual(face1, currentSelection.faces.First(), "Second click: The middle face should be picked.");

// --- Third click: Should pick the back mesh due to deep cycling
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);

}
yield return null;

currentSelection = EditorSceneViewPicker.selection;
Expand All @@ -303,10 +313,13 @@ public IEnumerator FacePicker_CyclesThroughOverlappingProBuilderFacesOnRepeatedC
Assert.AreEqual(face2, currentSelection.faces.First(), "Second click: The middle face should be picked.");

// --- Fourth click: Should cycle back to the front mesh (mesh3)
EditorSceneViewPicker.DoMouseClick(
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);
}
yield return null;

currentSelection = EditorSceneViewPicker.selection;
Expand Down Expand Up @@ -334,11 +347,13 @@ public IEnumerator FacePicker_DoesNotPickFace_BehindCamera()
Vector2 mousePos = UnityEditor.HandleUtility.WorldToGUIPoint(centerOfFace_world);
yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(
CreateMouseEvent(mousePos, EventType.MouseDown, EventModifiers.None),
SelectMode.Face,
m_PickerPreferences);
}
yield return null;

SceneSelection currentSelection = EditorSceneViewPicker.selection;
Expand Down Expand Up @@ -379,34 +394,44 @@ public IEnumerator FacePicker_CyclesThroughOffsetOverlappingProBuilderFaces()
Vector2 mousePos = UnityEditor.HandleUtility.WorldToGUIPoint(baseCenterWorld);
yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;

// --- First click: front mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
SceneSelection selection = EditorSceneViewPicker.selection;
Assert.AreEqual(frontMesh, selection.mesh, "First click: Front offset ProBuilder mesh should be picked.");
Assert.AreEqual(1, selection.faces.Count, "First click: Exactly one face should be selected.");
Assert.AreEqual(frontMesh.facesInternal[4], selection.faces.First(), "First click: The front offset face should be picked.");

// --- Second click: middle mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
selection = EditorSceneViewPicker.selection;
Assert.AreEqual(m_Mesh, selection.mesh, "Second click: Middle ProBuilder mesh should be picked.");
Assert.AreEqual(1, selection.faces.Count, "Second click: Exactly one face should be selected.");
Assert.AreEqual(m_Mesh.facesInternal[4], selection.faces.First(), "Second click: The middle face should be picked.");

// --- Third click: back mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
selection = EditorSceneViewPicker.selection;
Assert.AreEqual(backMesh, selection.mesh, "Third click: Back offset ProBuilder mesh should be picked.");
Assert.AreEqual(1, selection.faces.Count, "Third click: Exactly one face should be selected.");
Assert.AreEqual(backMesh.facesInternal[4], selection.faces.First(), "Third click: The back offset face should be picked.");

// --- Fourth click: front mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
selection = EditorSceneViewPicker.selection;
Assert.AreEqual(frontMesh, selection.mesh, "Fourth click: Front offset ProBuilder mesh should be picked.");
Expand Down Expand Up @@ -448,18 +473,22 @@ public IEnumerator FacePicker_CycleResetsWhenMouseMovesAndClickOutsideSelectedFa
Vector2 mousePos = UnityEditor.HandleUtility.WorldToGUIPoint(GetFaceCenterWorld(m_Mesh, baseFace));
yield return null;

UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;

// --- First click: front mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
SceneSelection selection = EditorSceneViewPicker.selection;
Assert.AreEqual(frontMesh, selection.mesh, "First click: Front ProBuilder mesh should be picked.");
Assert.AreEqual(1, selection.faces.Count, "First click: Exactly one face should be selected.");
Assert.AreEqual(frontMesh.facesInternal[4], selection.faces.First(), "First click: The front face should be picked.");

// --- Second click: middle mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
selection = EditorSceneViewPicker.selection;
Assert.AreEqual(m_Mesh, selection.mesh, "Second click: Middle ProBuilder mesh should be picked.");
Expand All @@ -470,7 +499,10 @@ public IEnumerator FacePicker_CycleResetsWhenMouseMovesAndClickOutsideSelectedFa
Vector2 farMousePos = mousePos + new Vector2(1000, 1000);

// Perform a click at the far position (no object hit) to trigger cycle reset
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(farMousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(farMousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null; // Let the frame advance

selection = EditorSceneViewPicker.selection;
Expand All @@ -479,15 +511,21 @@ public IEnumerator FacePicker_CycleResetsWhenMouseMovesAndClickOutsideSelectedFa
Assert.IsNull(selection.gameObject, "Cycle reset: No GameObject should be selected.");

// --- Click again on original position: cycle should restart from front mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
selection = EditorSceneViewPicker.selection;
Assert.AreEqual(frontMesh, selection.mesh, "Cycle restart: Front ProBuilder mesh should be picked again.");
Assert.AreEqual(1, selection.faces.Count, "Cycle restart: Exactly one face should be selected.");
Assert.AreEqual(frontMesh.facesInternal[4], selection.faces.First(), "Cycle restart: The front face should be picked again.");

// --- Second click after reset: should pick middle mesh again, NOT back mesh
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
using (new IgnoreAssertScope())
{
EditorSceneViewPicker.DoMouseClick(CreateMouseEvent(mousePos), SelectMode.Face, m_PickerPreferences);
}
yield return null;
selection = EditorSceneViewPicker.selection;
Assert.AreEqual(m_Mesh, selection.mesh, "After reset second click: Middle ProBuilder mesh should be picked.");
Expand Down
16 changes: 16 additions & 0 deletions Tests/Framework/TestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ public IEnumerator GetEnumerator()
}
}

class IgnoreAssertScope : IDisposable
{
bool m_SavedState;

public IgnoreAssertScope()
{
m_SavedState = UnityEngine.TestTools.LogAssert.ignoreFailingMessages;
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true; // Ignore logs due to not executing OnGUI loop
}

public void Dispose()
{
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = m_SavedState;
}
}

/// <summary>
/// Convert a full path to one relative to the project directory.
/// </summary>
Expand Down