-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from nowsprinting/feature/gizmos
Add GizmosShowOnGameViewAttribute
- Loading branch information
Showing
9 changed files
with
242 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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,46 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System; | ||
using System.Collections; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Interfaces; | ||
using TestHelper.RuntimeInternals; | ||
using UnityEngine.TestTools; | ||
|
||
namespace TestHelper.Attributes | ||
{ | ||
/// <summary> | ||
/// Show/ hide Gizmos on <c>GameView</c> during the test running. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class GizmosShowOnGameViewAttribute : NUnitAttribute, IOuterUnityTestAction | ||
{ | ||
private readonly bool _show; | ||
private readonly bool _beforeShow; | ||
|
||
/// <summary> | ||
/// Show/ hide Gizmos on <c>GameView</c> during the test running. | ||
/// </summary> | ||
/// <param name="show">True: show Gizmos, False: hide Gizmos.</param> | ||
public GizmosShowOnGameViewAttribute(bool show = true) | ||
{ | ||
_show = show; | ||
_beforeShow = GameViewControlHelper.GetGizmos(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IEnumerator BeforeTest(ITest test) | ||
{ | ||
GameViewControlHelper.SetGizmos(_show); | ||
yield return null; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IEnumerator AfterTest(ITest test) | ||
{ | ||
GameViewControlHelper.SetGizmos(_beforeShow); | ||
yield return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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
71 changes: 71 additions & 0 deletions
71
Tests/Runtime/Attributes/GizmosShowOnGameViewAttributeTest.cs
This file contains 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,71 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using TestHelper.Utils; | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
|
||
namespace TestHelper.Attributes | ||
{ | ||
[TestFixture] | ||
public class GizmosShowOnGameViewAttributeTest | ||
{ | ||
private class GizmoDemo : MonoBehaviour | ||
{ | ||
private void OnDrawGizmos() | ||
{ | ||
Gizmos.color = Color.red; | ||
Gizmos.DrawSphere(transform.position, 0.2f); | ||
} | ||
} | ||
|
||
[UnitySetUp] | ||
public IEnumerator UnitySetUp() | ||
{ | ||
var gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); | ||
gameObject.AddComponent<GizmoDemo>(); | ||
yield return null; | ||
} | ||
|
||
[UnityTearDown] | ||
public IEnumerator UnityTearDown() | ||
{ | ||
yield return ScreenshotHelper.TakeScreenshot(); // Take screenshot before hide Gizmos. | ||
} | ||
|
||
[Test] | ||
[CreateScene(camera: true, light: true)] | ||
[GizmosShowOnGameView] | ||
public void Attach_True_ShowGizmos() | ||
{ | ||
// verify screenshot. | ||
} | ||
|
||
[Test] | ||
[CreateScene(camera: true, light: true)] | ||
[GizmosShowOnGameView(false)] | ||
public void Attach_False_HideGizmos() | ||
{ | ||
// verify screenshot. | ||
} | ||
|
||
[Test] | ||
[CreateScene(camera: true, light: true)] | ||
[GizmosShowOnGameView()] | ||
public async Task AttachToAsyncTest_ShowGizmos() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[UnityTest] | ||
[CreateScene(camera: true, light: true)] | ||
[GizmosShowOnGameView()] | ||
public IEnumerator AttachToUnityTest_ShowGizmos() | ||
{ | ||
yield return null; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Tests/Runtime/Attributes/GizmosShowOnGameViewAttributeTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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