1- using System . Collections ;
2- using System . Collections . Generic ;
3- using System . Linq ;
1+ using System ;
42using NUnit . Framework ;
53using UnityEngine ;
6- using UnityEngine . Rendering ;
74using UnityEngine . Rendering . PostProcessing ;
8- using UnityEngine . TestTools ;
9- using UnityEngine . SceneManagement ;
105
11- #if UNITY_EDITOR
12- using UnityEditor ;
13- #endif
14-
15- class PostProcessingTests : IPrebuildSetup
6+ class PostProcessingTests
167{
17- const float k_Epsilon = 1e-4f ;
18-
19- static List < string > s_Scenes ;
8+ [ Test ]
9+ public void Profile_AddSettings ( )
10+ {
11+ var profile = NewProfile ( ) ;
2012
21- CommandBuffer m_DummyCmd ;
13+ var bloom = profile . AddSettings < Bloom > ( ) ;
14+ Assert . IsNotNull ( bloom ) ;
2215
23- static PostProcessingTests ( )
24- {
25- s_Scenes = new List < string >
26- {
27- "Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0010_Volumes.unity" ,
28- "Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0011_Weight.unity" ,
29- "Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0012_Intersect.unity" ,
30- "Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0013_Priority.unity" ,
31- } ;
16+ Destroy ( profile ) ;
3217 }
3318
34- public void Setup ( )
19+ [ Test ]
20+ public void Profile_HasSettings ( )
3521 {
36- #if UNITY_EDITOR
37- Debug . Log ( "Adding scenes to build settings..." ) ;
38-
39- var scenes = EditorBuildSettings . scenes . ToList ( ) ;
22+ var profile = NewProfile ( typeof ( Bloom ) ) ;
4023
41- for ( int i = 0 ; i < s_Scenes . Count ; i ++ )
42- {
43- if ( ! scenes . Exists ( x => x . path == s_Scenes [ i ] ) )
44- scenes . Add ( new EditorBuildSettingsScene ( s_Scenes [ i ] , true ) ) ;
45- }
24+ Assert . IsTrue ( profile . HasSettings < Bloom > ( ) ) ;
25+ Assert . IsFalse ( profile . HasSettings < ChromaticAberration > ( ) ) ;
4626
47- EditorBuildSettings . scenes = scenes . ToArray ( ) ;
48- #endif
27+ Destroy ( profile ) ;
4928 }
5029
51- [ SetUp ]
52- public void Init ( )
30+ [ Test ]
31+ public void Profile_GetSettings ( )
5332 {
54- m_DummyCmd = new CommandBuffer ( ) ;
55- }
33+ var profile = NewProfile ( typeof ( Bloom ) ) ;
5634
57- [ TearDown ]
58- public void Cleanup ( )
59- {
60- m_DummyCmd . Release ( ) ;
61- m_DummyCmd = null ;
62- }
35+ Assert . IsNotNull ( profile . GetSetting < Bloom > ( ) ) ;
36+ Assert . IsNull ( profile . GetSetting < ChromaticAberration > ( ) ) ;
6337
64- static PostProcessLayer GrabPostProcessLayer ( )
65- {
66- var layer = Object . FindObjectOfType < PostProcessLayer > ( ) ;
67- Assert . IsNotNull ( layer , "Couldn't find PostProcessLayer" ) ;
68- return layer ;
38+ Destroy ( profile ) ;
6939 }
7040
7141 [ Test ]
72- public void SettingsManagement ( )
42+ public void Profile_TryGetSettings ( )
7343 {
74- var profile = ScriptableObject . CreateInstance < PostProcessProfile > ( ) ;
75-
76- var bloom = profile . AddSettings < Bloom > ( ) ;
77- Assert . IsNotNull ( bloom ) ;
44+ var profile = NewProfile ( typeof ( Bloom ) ) ;
7845
7946 Bloom outBloom ;
8047 var exists = profile . TryGetSettings ( out outBloom ) ;
@@ -86,126 +53,32 @@ public void SettingsManagement()
8653 Assert . IsFalse ( exists ) ;
8754 Assert . IsNull ( outChroma ) ;
8855
89- Assert . IsTrue ( profile . HasSettings < Bloom > ( ) ) ;
90- Assert . IsFalse ( profile . HasSettings < ChromaticAberration > ( ) ) ;
91-
92- Assert . IsNotNull ( profile . GetSetting < Bloom > ( ) ) ;
93- Assert . IsNull ( profile . GetSetting < ChromaticAberration > ( ) ) ;
94-
95- profile . RemoveSettings < Bloom > ( ) ;
96- Assert . IsFalse ( profile . HasSettings < Bloom > ( ) ) ;
97-
98- Object . DestroyImmediate ( profile ) ;
99- }
100-
101- [ UnityTest ]
102- public IEnumerator GlobalVolumeSingleLayer ( )
103- {
104- SceneManager . LoadScene ( s_Scenes [ 0 ] ) ;
105-
106- yield return null ; // Skip a frame
107-
108- var ppLayer = GrabPostProcessLayer ( ) ;
109- ppLayer . volumeLayer = LayerMask . GetMask ( "Default" ) ;
110-
111- yield return null ; // Skip a frame
112-
113- ppLayer . UpdateVolumeSystem ( ppLayer . GetComponent < Camera > ( ) , m_DummyCmd ) ;
114-
115- var vignette = ppLayer . GetSettings < Vignette > ( ) ;
116- Assert . AreEqual ( 1f , vignette . intensity . value , k_Epsilon ) ;
117- Assert . IsTrue ( vignette . rounded . value ) ;
118- }
119-
120- [ UnityTest ]
121- public IEnumerator LocalVolumeMultiLayer ( )
122- {
123- SceneManager . LoadScene ( s_Scenes [ 0 ] ) ;
124-
125- yield return null ; // Skip a frame
126-
127- var ppLayer = GrabPostProcessLayer ( ) ;
128- ppLayer . volumeLayer = - 1 ;
129-
130- yield return null ; // Skip a frame
131-
132- ppLayer . UpdateVolumeSystem ( ppLayer . GetComponent < Camera > ( ) , m_DummyCmd ) ;
133-
134- var vignette = ppLayer . GetSettings < Vignette > ( ) ;
135- Assert . AreEqual ( Color . red , vignette . color . value ) ;
56+ Destroy ( profile ) ;
13657 }
13758
138- [ UnityTest ]
139- public IEnumerator LocalVolumeWeight ( )
140- {
141- SceneManager . LoadScene ( s_Scenes [ 1 ] ) ;
142-
143- yield return null ; // Skip a frame
144-
145- var ppLayer = GrabPostProcessLayer ( ) ;
146- ppLayer . volumeLayer = - 1 ;
147-
148- yield return null ; // Skip a frame
149-
150- ppLayer . UpdateVolumeSystem ( ppLayer . GetComponent < Camera > ( ) , m_DummyCmd ) ;
151-
152- var vignette = ppLayer . GetSettings < Vignette > ( ) ;
153- Assert . AreEqual ( 0.5f , vignette . color . value . r , k_Epsilon ) ;
154- }
155-
156- [ UnityTest ]
157- public IEnumerator LocalVolumeIntersect ( )
59+ [ Test ]
60+ public void Profile_RemoveSettings ( )
15861 {
159- SceneManager . LoadScene ( s_Scenes [ 2 ] ) ;
160-
161- yield return null ; // Skip a frame
162-
163- var ppLayer = GrabPostProcessLayer ( ) ;
164- ppLayer . volumeLayer = - 1 ;
62+ var profile = NewProfile ( typeof ( Bloom ) ) ;
16563
166- yield return null ; // Skip a frame
167-
168- ppLayer . UpdateVolumeSystem ( ppLayer . GetComponent < Camera > ( ) , m_DummyCmd ) ;
64+ profile . RemoveSettings < Bloom > ( ) ;
65+ Assert . IsFalse ( profile . HasSettings < Bloom > ( ) ) ;
16966
170- var vignette = ppLayer . GetSettings < Vignette > ( ) ;
171- Assert . AreEqual ( 0.75f , vignette . color . value . r , k_Epsilon ) ;
67+ Destroy ( profile ) ;
17268 }
17369
174- [ UnityTest ]
175- public IEnumerator GetHighestPriority ( )
70+ static PostProcessProfile NewProfile ( params Type [ ] types )
17671 {
177- SceneManager . LoadScene ( s_Scenes [ 3 ] ) ;
178-
179- yield return null ; // Skip a frame
180-
181- var ppLayer = GrabPostProcessLayer ( ) ;
182- ppLayer . volumeLayer = - 1 ;
183-
184- yield return null ; // Skip a frame
72+ var profile = ScriptableObject . CreateInstance < PostProcessProfile > ( ) ;
18573
186- ppLayer . UpdateVolumeSystem ( ppLayer . GetComponent < Camera > ( ) , m_DummyCmd ) ;
74+ foreach ( var t in types )
75+ profile . AddSettings ( t ) ;
18776
188- var volume = PostProcessManager . instance . GetHighestPriorityVolume ( ppLayer ) ;
189- Assert . IsNotNull ( volume ) ;
190- Assert . AreEqual ( 10000 , volume . priority , k_Epsilon ) ;
77+ return profile ;
19178 }
19279
193- [ UnityTest ]
194- public IEnumerator GetActiveVolumes ( )
80+ static void Destroy ( PostProcessProfile profile )
19581 {
196- SceneManager . LoadScene ( s_Scenes [ 3 ] ) ;
197-
198- yield return null ; // Skip a frame
199-
200- var ppLayer = GrabPostProcessLayer ( ) ;
201- ppLayer . volumeLayer = - 1 ;
202-
203- yield return null ; // Skip a frame
204-
205- ppLayer . UpdateVolumeSystem ( ppLayer . GetComponent < Camera > ( ) , m_DummyCmd ) ;
206-
207- var results = new List < PostProcessVolume > ( ) ;
208- PostProcessManager . instance . GetActiveVolumes ( ppLayer , results , true , true ) ;
209- Assert . AreEqual ( 3 , results . Count , k_Epsilon ) ;
82+ UnityEngine . Object . DestroyImmediate ( profile ) ;
21083 }
21184}
0 commit comments