1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- using System . Collections . Generic ;
5
- using System . Linq ;
6
- using System . Reflection ;
7
4
using UnityEngine ;
8
- using UnityEngine . SceneManagement ;
9
5
10
6
#if UNITY_EDITOR
11
7
using Microsoft . MixedReality . Toolkit . Utilities . Editor ;
12
8
using Microsoft . MixedReality . Toolkit . Editor ;
9
+ using System . Collections . Generic ;
10
+ using System . Linq ;
11
+ using System . Reflection ;
13
12
using UnityEditor ;
14
13
using UnityEditor . SceneManagement ;
15
- #endif
16
-
17
- #if WINDOWS_UWP
18
- using UnityEngine . Assertions ;
14
+ using UnityEngine . SceneManagement ;
19
15
#endif
20
16
21
17
namespace Microsoft . MixedReality . Toolkit . Tests
22
18
{
23
19
public static class TestUtilities
24
20
{
25
- const string primaryTestSceneTemporarySavePath = "Assets/__temp_primary_test_scene.unity" ;
26
- const string additiveTestSceneTemporarySavePath = "Assets/__temp_additive_test_scene_#.unity" ;
21
+ #if UNITY_EDITOR
22
+ private const string PrimaryTestSceneTemporarySavePath = "Assets/__temp_primary_test_scene.unity" ;
23
+ private const string AdditiveTestSceneTemporarySavePath = "Assets/__temp_additive_test_scene_#.unity" ;
24
+
27
25
public static Scene primaryTestScene ;
28
26
public static Scene [ ] additiveTestScenes = System . Array . Empty < Scene > ( ) ;
27
+ #endif // UNITY_EDITOR
29
28
30
29
/// <summary>
31
30
/// Destroys all scene assets that were created over the course of testing.
@@ -37,15 +36,15 @@ public static void EditorTearDownScenes()
37
36
if ( ! EditorApplication . isPlaying )
38
37
{
39
38
// If any of our scenes were saved, tear down the assets
40
- SceneAsset primaryTestSceneAsset = AssetDatabase . LoadAssetAtPath < SceneAsset > ( primaryTestSceneTemporarySavePath ) ;
39
+ SceneAsset primaryTestSceneAsset = AssetDatabase . LoadAssetAtPath < SceneAsset > ( PrimaryTestSceneTemporarySavePath ) ;
41
40
if ( primaryTestSceneAsset != null )
42
41
{
43
- AssetDatabase . DeleteAsset ( primaryTestSceneTemporarySavePath ) ;
42
+ AssetDatabase . DeleteAsset ( PrimaryTestSceneTemporarySavePath ) ;
44
43
}
45
44
46
45
for ( int i = 0 ; i < additiveTestScenes . Length ; i ++ )
47
46
{
48
- string path = additiveTestSceneTemporarySavePath . Replace ( "#" , i . ToString ( ) ) ;
47
+ string path = AdditiveTestSceneTemporarySavePath . Replace ( "#" , i . ToString ( ) ) ;
49
48
SceneAsset additiveTestSceneAsset = AssetDatabase . LoadAssetAtPath < SceneAsset > ( path ) ;
50
49
if ( additiveTestSceneAsset != null )
51
50
{
@@ -54,7 +53,7 @@ public static void EditorTearDownScenes()
54
53
}
55
54
AssetDatabase . Refresh ( ) ;
56
55
}
57
- #endif
56
+ #endif // UNITY_EDITOR
58
57
}
59
58
60
59
/// <summary>
@@ -72,20 +71,17 @@ public static void EditorCreateScenes(int numScenesToCreate = 1)
72
71
73
72
List < Scene > additiveTestScenesList = new List < Scene > ( ) ;
74
73
75
- if ( numScenesToCreate == 1 )
76
- { // No need to save this scene, we're just creating one
77
- primaryTestScene = EditorSceneManager . NewScene ( NewSceneSetup . DefaultGameObjects , NewSceneMode . Single ) ;
78
- }
79
- else
74
+ // Make the first scene single so it blows away previously loaded scenes
75
+ primaryTestScene = EditorSceneManager . NewScene ( NewSceneSetup . DefaultGameObjects , NewSceneMode . Single ) ;
76
+
77
+ if ( numScenesToCreate != 1 )
80
78
{
81
- // Make the first scene single so it blows away previously loaded scenes
82
- primaryTestScene = EditorSceneManager . NewScene ( NewSceneSetup . DefaultGameObjects , NewSceneMode . Single ) ;
83
79
// Save the scene (temporarily) so we can load additively on top of it
84
- EditorSceneManager . SaveScene ( primaryTestScene , primaryTestSceneTemporarySavePath ) ;
80
+ EditorSceneManager . SaveScene ( primaryTestScene , PrimaryTestSceneTemporarySavePath ) ;
85
81
86
82
for ( int i = 1 ; i < numScenesToCreate ; i ++ )
87
83
{
88
- string path = additiveTestSceneTemporarySavePath . Replace ( "#" , additiveTestScenesList . Count . ToString ( ) ) ;
84
+ string path = AdditiveTestSceneTemporarySavePath . Replace ( "#" , additiveTestScenesList . Count . ToString ( ) ) ;
89
85
// Create subsequent scenes additively
90
86
Scene additiveScene = EditorSceneManager . NewScene ( NewSceneSetup . DefaultGameObjects , NewSceneMode . Additive ) ;
91
87
additiveTestScenesList . Add ( additiveScene ) ;
@@ -95,7 +91,7 @@ public static void EditorCreateScenes(int numScenesToCreate = 1)
95
91
}
96
92
97
93
additiveTestScenes = additiveTestScenesList . ToArray ( ) ;
98
- #endif
94
+ #endif // UNITY_EDITOR
99
95
}
100
96
101
97
/// <summary>
@@ -340,25 +336,25 @@ public static T GetDefaultMixedRealityProfile<T>() where T : BaseMixedRealityPro
340
336
public static void AssertAboutEqual ( Vector3 actual , Vector3 expected , string message , float tolerance = 0.01f )
341
337
{
342
338
var dist = ( actual - expected ) . magnitude ;
343
- Debug . Assert ( dist < tolerance , $ "{ message } , expected { expected . ToString ( " 0.000" ) } , was { actual . ToString ( " 0.000" ) } ") ;
339
+ Debug . Assert ( dist < tolerance , $ "{ message } , expected { expected : 0.000} , was { actual : 0.000} ") ;
344
340
}
345
341
346
342
public static void AssertAboutEqual ( Quaternion actual , Quaternion expected , string message , float tolerance = 0.01f )
347
343
{
348
344
var angle = Quaternion . Angle ( actual , expected ) ;
349
- Debug . Assert ( angle < tolerance , $ "{ message } , expected { expected . ToString ( " 0.000" ) } , was { actual . ToString ( " 0.000" ) } ") ;
345
+ Debug . Assert ( angle < tolerance , $ "{ message } , expected { expected : 0.000} , was { actual : 0.000} ") ;
350
346
}
351
347
352
348
public static void AssertNotAboutEqual ( Vector3 val1 , Vector3 val2 , string message , float tolerance = 0.01f )
353
349
{
354
350
var dist = ( val1 - val2 ) . magnitude ;
355
- Debug . Assert ( dist >= tolerance , $ "{ message } , val1 { val1 . ToString ( " 0.000" ) } almost equals val2 { val2 . ToString ( " 0.000" ) } ") ;
351
+ Debug . Assert ( dist >= tolerance , $ "{ message } , val1 { val1 : 0.000} almost equals val2 { val2 : 0.000} ") ;
356
352
}
357
353
358
354
public static void AssertNotAboutEqual ( Quaternion val1 , Quaternion val2 , string message , float tolerance = 0.01f )
359
355
{
360
356
var angle = Quaternion . Angle ( val1 , val2 ) ;
361
- Debug . Assert ( angle >= tolerance , $ "{ message } , val1 { val1 . ToString ( " 0.000" ) } almost equals val2 { val2 . ToString ( " 0.000" ) } ") ;
357
+ Debug . Assert ( angle >= tolerance , $ "{ message } , val1 { val1 : 0.000} almost equals val2 { val2 : 0.000} ") ;
362
358
}
363
359
364
360
/// <summary>
@@ -443,21 +439,21 @@ private static void UpdateTestScriptIcons()
443
439
444
440
MonoScript script = AssetDatabase . LoadAssetAtPath < MonoScript > ( scriptPath ) ;
445
441
446
- Texture2D currentIcon = getIconForObject ? . Invoke ( null , new object [ ] { script } ) as Texture2D ;
442
+ Texture2D currentIcon = GetIconForObject ? . Invoke ( null , new object [ ] { script } ) as Texture2D ;
447
443
if ( currentIcon == null || ! currentIcon . Equals ( icon ) )
448
444
{
449
- setIconForObject ? . Invoke ( null , new object [ ] { script , icon } ) ;
450
- copyMonoScriptIconToImporters ? . Invoke ( null , new object [ ] { script } ) ;
445
+ SetIconForObject ? . Invoke ( null , new object [ ] { script , icon } ) ;
446
+ CopyMonoScriptIconToImporters ? . Invoke ( null , new object [ ] { script } ) ;
451
447
}
452
448
}
453
449
}
454
450
455
451
EditorUtility . ClearProgressBar ( ) ;
456
452
}
457
453
458
- private static readonly MethodInfo getIconForObject = typeof ( EditorGUIUtility ) . GetMethod ( "GetIconForObject" , BindingFlags . Static | BindingFlags . NonPublic ) ;
459
- private static readonly MethodInfo setIconForObject = typeof ( EditorGUIUtility ) . GetMethod ( "SetIconForObject" , BindingFlags . Static | BindingFlags . NonPublic ) ;
460
- private static readonly MethodInfo copyMonoScriptIconToImporters = typeof ( MonoImporter ) . GetMethod ( "CopyMonoScriptIconToImporters" , BindingFlags . Static | BindingFlags . NonPublic ) ;
454
+ private static readonly MethodInfo GetIconForObject = typeof ( EditorGUIUtility ) . GetMethod ( "GetIconForObject" , BindingFlags . Static | BindingFlags . NonPublic ) ;
455
+ private static readonly MethodInfo SetIconForObject = typeof ( EditorGUIUtility ) . GetMethod ( "SetIconForObject" , BindingFlags . Static | BindingFlags . NonPublic ) ;
456
+ private static readonly MethodInfo CopyMonoScriptIconToImporters = typeof ( MonoImporter ) . GetMethod ( "CopyMonoScriptIconToImporters" , BindingFlags . Static | BindingFlags . NonPublic ) ;
461
457
#endif
462
458
}
463
459
}
0 commit comments