66using TMPro ;
77
88
9-
10-
11- // Immersion Theater 6816 x 2240 / 3.04:1
12- // Game Lab 4800 x 1080 / 4.44:1
13- // Visualization Studio (estimated) 27053 x 2160 / 12.52:1
14-
15-
16-
17-
189/**
1910 * Manage game "resolution" - runs in play mode AND editor
2011 */
2112
22- [ ExecuteAlways ]
23- public class ResolutionManager : MonoBehaviour {
24-
25-
26-
2713
14+ //[ExecuteAlways]
15+ public class ResolutionManager : MonoBehaviour {
2816
2917
3018
@@ -41,8 +29,7 @@ public class ResolutionManager : MonoBehaviour {
4129 [ Tooltip ( "Canvas resolution" ) ]
4230 public Vector2 canvasResolution ;
4331
44- [ Tooltip ( "The grid of anchors" ) ]
45- public Vector2 [ ] ninePointGrid ;
32+
4633
4734
4835
@@ -105,20 +92,14 @@ public class ResolutionManager : MonoBehaviour {
10592
10693 public TMP_Text resolutionReportText ;
10794
108- public GameObject [ ] resolutionMarkers ;
10995
11096
11197
11298
113- public GameObject CeilingLight ;
114- public GameObject BasementLight ;
115- public GameObject CornerLightTopLeft ;
99+ //[SerializeField]
100+ //private int framesSinceSizeUpdated = 0;
116101
117-
118- [ SerializeField ]
119- private int framesSinceSizeUpdated = 0 ;
120-
121- bool updateWorld = true ;
102+ //bool updateWorld = true;
122103
123104
124105 private void Awake ( )
@@ -134,16 +115,19 @@ private void Awake ()
134115
135116 private void Update ( )
136117 {
137- // if not playing
138- if ( ! Application . IsPlaying ( gameObject ) ) {
139- // if player resolution has changed
118+ // if application is playing
119+ if ( Application . IsPlaying ( gameObject ) ) {
120+ // and if player resolution has changed
140121 if ( playerResolution . x != Screen . width || playerResolution . y != Screen . height ) {
141122 // update the parameters
142123 UpdateResolutionParams ( ) ;
143124 // update collider
144125 UpdateColliderSize ( ) ;
145- // update object positions
146- UpdateGameObjectPositions ( ) ;
126+
127+
128+ // trigger data updated event
129+ EventManager . TriggerEvent ( "ResolutionUpdated" ) ;
130+
147131 }
148132 }
149133
@@ -186,9 +170,6 @@ private void Update ()
186170 //if (updateWorld) {
187171 // UpdateReport ();
188172 // UpdateColliderSize ();
189- // //UpdateBoundsDisplay ();
190- // //DrawBounds (worldContainer.bounds);
191- // //UpdateGameObjectPositions ();
192173
193174
194175 // // reset counter
@@ -201,10 +182,23 @@ private void Update ()
201182 }
202183
203184
185+ void UpdateColliderSize ( )
186+ {
187+ // make sure there isn't a negative number
188+ if ( playerViewSize . x > 0 && playerViewSize . y > 0 ) {
189+ worldContainerCollider . size = new Vector3 ( playerViewSize . x , playerViewSize . y , worldContainerCollider . size . z ) ;
190+
204191
192+ // debugging
193+ Debug . Log ( "ResolutionManager.UpdateColliderSize() playerViewSize = " + playerViewSize . ToString ( ) ) ;
194+ Debug . Log ( "ResolutionManager.UpdateColliderSize() worldContainerCollider.size = " + worldContainerCollider . size . ToString ( ) ) ;
195+ Debug . Log ( "ResolutionManager.UpdateColliderSize() worldContainerCollider.bounds = " + worldContainerCollider . bounds . ToString ( ) ) ;
196+ }
197+
198+ }
205199
206200 /**
207- * Update all the details on the resolution parameters
201+ * Update all the resolution parameters
208202 */
209203 public void UpdateResolutionParams ( )
210204 {
@@ -226,6 +220,35 @@ public void UpdateResolutionParams ()
226220 deviceAspectRatio = deviceResolution . x / deviceResolution . y ;
227221 }
228222
223+ /**
224+ * Return the player viewing volume size (in Unity units)
225+ */
226+ public static Vector3 GetPlayerViewSize ( )
227+ {
228+ // The orthographicSize is half of the vertical viewing volume size
229+ float height = Camera . main . orthographicSize * 2 ;
230+ // The horizontal size of the viewing volume depends on the aspect ratio so...
231+ // width = height * screen resolution aspect ratio
232+ float width = height * Screen . width / Screen . height ;
233+ // return both
234+ return new Vector2 ( width , height ) ;
235+ }
236+
237+ /**
238+ * Return the editor Game View window size - works in editor
239+ */
240+ public static Vector2 GetMainGameViewSize ( )
241+ {
242+ System . Type T = System . Type . GetType ( "UnityEditor.GameView,UnityEditor" ) ;
243+ System . Reflection . MethodInfo GetSizeOfMainGameView = T . GetMethod ( "GetSizeOfMainGameView" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Static ) ;
244+ System . Object Res = GetSizeOfMainGameView . Invoke ( null , null ) ;
245+ return ( Vector2 ) Res ;
246+ }
247+
248+
249+ /**
250+ * Update the text in the UI
251+ */
229252 void UpdateReport ( )
230253 {
231254 // update text in control panel
@@ -241,141 +264,20 @@ void UpdateReport ()
241264 }
242265
243266
244- void UpdateColliderSize ( )
245- {
246- // make sure there isn't a negative number
247- if ( playerViewSize . x > 0 && playerViewSize . y > 0 ) {
248- worldContainerCollider . size = new Vector3 ( playerViewSize . x , playerViewSize . y , worldContainerCollider . size . z ) ;
249-
250-
251- // debugging
252- Debug . Log ( "ResolutionManager.UpdateColliderSize() playerViewSize = " + playerViewSize . ToString ( ) ) ;
253- Debug . Log ( "ResolutionManager.UpdateColliderSize() worldContainerCollider.size = " + worldContainerCollider . size . ToString ( ) ) ;
254- Debug . Log ( "ResolutionManager.UpdateColliderSize() worldContainerCollider.bounds = " + worldContainerCollider . bounds . ToString ( ) ) ;
255- }
256-
257- }
258-
259-
260267
261268
262- void UpdateGameObjectPositions ( )
263- {
264- // display the nine point grid
265- ninePointGrid = GetPlanePointGrid ( worldContainerCollider . bounds ) ;
266- for ( int i = 0 ; i < ninePointGrid . Length ; i ++ ) {
267- resolutionMarkers [ i ] . transform . localPosition = new Vector3 ( ninePointGrid [ i ] . x , ninePointGrid [ i ] . y , resolutionMarkers [ 0 ] . transform . localPosition . z ) ;
268- }
269269
270270
271271
272272
273- //Debug.Log (worldContainer.bounds.ToString ());
274- }
275273
276274
277- /**
278- * Get 9 points on a plane
279- */
280- public Vector2 [ ] GetPlanePointGrid ( Bounds b )
281- {
282- Vector2 [ ] p = new Vector2 [ 9 ] ;
283-
284- p [ 0 ] = new Vector2 ( b . min . x , b . max . y ) ; // top left
285- p [ 1 ] = new Vector2 ( b . center . x , b . max . y ) ; // top center
286- p [ 2 ] = new Vector2 ( b . max . x , b . max . y ) ; // top right
287-
288- p [ 3 ] = new Vector2 ( b . min . x , b . center . y ) ; // center left
289- p [ 4 ] = new Vector2 ( b . center . x , b . center . y ) ; // center center
290- p [ 5 ] = new Vector2 ( b . max . x , b . center . y ) ; // center right
291-
292- p [ 6 ] = new Vector2 ( b . min . x , b . min . y ) ; // bottom left
293- p [ 7 ] = new Vector2 ( b . center . x , b . min . y ) ; // bottom center
294- p [ 8 ] = new Vector2 ( b . max . x , b . min . y ) ; // bottom right
295-
296- return p ;
297- }
298275
299276
300277
301278
302279
303280
304-
305- void DrawBounds ( Bounds b , float delay = 0 )
306- {
307- // bottom
308- var p1 = new Vector3 ( b . min . x , b . min . y , b . min . z ) ;
309- var p2 = new Vector3 ( b . max . x , b . min . y , b . min . z ) ;
310- var p3 = new Vector3 ( b . max . x , b . min . y , b . max . z ) ;
311- var p4 = new Vector3 ( b . min . x , b . min . y , b . max . z ) ;
312-
313- Debug . DrawLine ( p1 , p2 , Color . blue , delay ) ;
314- Debug . DrawLine ( p2 , p3 , Color . red , delay ) ;
315- Debug . DrawLine ( p3 , p4 , Color . yellow , delay ) ;
316- Debug . DrawLine ( p4 , p1 , Color . magenta , delay ) ;
317-
318- // top
319- var p5 = new Vector3 ( b . min . x , b . max . y , b . min . z ) ;
320- var p6 = new Vector3 ( b . max . x , b . max . y , b . min . z ) ;
321- var p7 = new Vector3 ( b . max . x , b . max . y , b . max . z ) ;
322- var p8 = new Vector3 ( b . min . x , b . max . y , b . max . z ) ;
323-
324- Debug . DrawLine ( p5 , p6 , Color . blue , delay ) ;
325- Debug . DrawLine ( p6 , p7 , Color . red , delay ) ;
326- Debug . DrawLine ( p7 , p8 , Color . yellow , delay ) ;
327- Debug . DrawLine ( p8 , p5 , Color . magenta , delay ) ;
328-
329- // sides
330- Debug . DrawLine ( p1 , p5 , Color . white , delay ) ;
331- Debug . DrawLine ( p2 , p6 , Color . gray , delay ) ;
332- Debug . DrawLine ( p3 , p7 , Color . green , delay ) ;
333- Debug . DrawLine ( p4 , p8 , Color . cyan , delay ) ;
334- }
335-
336-
337- //public void UpdateBoundsDisplay ()
338- //{
339- // Bounds bounds = worldContainer.bounds;
340- // Debug.DrawLine (new Vector3 (bounds.min.x, bounds.min.y, bounds.min.z), new Vector3 (bounds.max.x, bounds.min.y, bounds.min.z), Color.red);
341- // Debug.DrawLine (new Vector3 (bounds.max.x, bounds.min.y, bounds.min.z), new Vector3 (bounds.max.x, bounds.max.y, bounds.min.z), Color.red);
342- // Debug.DrawLine (new Vector3 (bounds.max.x, bounds.max.y, bounds.min.z), new Vector3 (bounds.min.x, bounds.max.y, bounds.min.z), Color.red);
343- // Debug.DrawLine (new Vector3 (bounds.min.x, bounds.max.y, bounds.min.z), new Vector3 (bounds.min.x, bounds.min.y, bounds.min.z), Color.red);
344- // Debug.DrawLine (bounds.min, bounds.max, Color.red);
345- //}
346-
347-
348-
349-
350-
351-
352- /**
353- * Return the player viewing volume size (in Unity units)
354- */
355- public static Vector3 GetPlayerViewSize ( )
356- {
357- // The orthographicSize is half of the vertical viewing volume size
358- float height = Camera . main . orthographicSize * 2 ;
359- // The horizontal size of the viewing volume depends on the aspect ratio so...
360- // width = height * screen resolution aspect ratio
361- float width = height * Screen . width / Screen . height ;
362- // return both
363- return new Vector2 ( width , height ) ;
364- }
365-
366-
367-
368- // get size (in editor window only?)
369- public static Vector2 GetMainGameViewSize ( )
370- {
371- System . Type T = System . Type . GetType ( "UnityEditor.GameView,UnityEditor" ) ;
372- System . Reflection . MethodInfo GetSizeOfMainGameView = T . GetMethod ( "GetSizeOfMainGameView" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Static ) ;
373- System . Object Res = GetSizeOfMainGameView . Invoke ( null , null ) ;
374- return ( Vector2 ) Res ;
375- }
376-
377-
378-
379281}
380282
381283
0 commit comments