Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: reptilebeats on July 16, 2012, 07:20:35 PM

Title: is it possible to see the cameras clipping edges
Post by: reptilebeats on July 16, 2012, 07:20:35 PM
ok last question i just wanted to know if there was a way to see the outline of the cameras clipping edges when modifing widgets, so basically you get a nice visual outline to know when the camera ends,

doesn't matter if there isn't i could always write a script up, shouldn't be a complicated task. oh i do use alpha clipping for a border, plus i need to use it but its mainly to see the length.
Title: Re: is it possible to see the cameras clipping edges
Post by: reptilebeats on July 29, 2012, 12:07:42 PM
ok just refreshing this question
Title: Re: is it possible to see the cameras clipping edges
Post by: dlewis on July 29, 2012, 07:01:52 PM
I wrote my own custom function to draw gizmos at the edge of the screen and for screen safe area. I hard coded the camera to 720p (since that's our target resolution) but it wouldn't be hard to modify the following code to get the real resolution. The vertical offset is because the UI was in the middle of our game and the UI cameras were picking up game gizmos. I put this script of my UICamera (which was a direct child of UIRoot).

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class DrawScreenSafeArea : MonoBehaviour
  5. {
  6.         public bool drawScreenSafe = false;
  7.     public bool draw720p = false;
  8.         public float screenSafePercentage = 0.1f;
  9.  
  10.     public int vertOffset = -100; // What is the offset of the UI in the world?
  11.        
  12.         void OnDrawGizmos()
  13.         {
  14.         if (drawScreenSafe)
  15.                 {
  16.                         Gizmos.color = Color.green;
  17.  
  18.                         Vector3 parentScale = gameObject.transform.parent.localScale * 0.5f;
  19.                         float xSize = 1280.0f * (1.0f - screenSafePercentage);
  20.                         float ySize = 720.0f * (1.0f - screenSafePercentage);
  21.                        
  22.                         Vector3 topLeft = new Vector3(-xSize * parentScale.x, (ySize * parentScale.y) + vertOffset, 0.0f);
  23.                         Vector3 topRight = new Vector3(xSize * parentScale.x, (ySize * parentScale.y) + vertOffset, 0.0f);
  24.                         Vector3 bottomLeft = new Vector3(-xSize * parentScale.x, (-ySize * parentScale.y) + vertOffset, 0.0f);
  25.                         Vector3 bottomRight = new Vector3(xSize * parentScale.x, (-ySize * parentScale.y) + vertOffset, 0.0f);
  26.                        
  27.                         Gizmos.DrawLine(topLeft, topRight);
  28.                         Gizmos.DrawLine(topRight, bottomRight);
  29.                         Gizmos.DrawLine(bottomRight, bottomLeft);
  30.                         Gizmos.DrawLine(bottomLeft, topLeft);
  31.                        
  32.                         //Vector3 origin = new Vector3(0.0f, 0.0f, 0.0f);
  33.                         //Vector3 lineUp = new Vector3(0.0f * parentScale.x, 720.0f * parentScale.y, 0.0f);
  34.                        
  35.                         //Gizmos.DrawLine(origin, lineUp);
  36.                 }
  37.  
  38.         if (draw720p)
  39.         {
  40.             Gizmos.color = Color.green;
  41.  
  42.             Vector3 parentScale = gameObject.transform.parent.localScale * 0.5f;
  43.  
  44.             Vector3 topLeft = new Vector3(-1280.0f * parentScale.x, (720.0f * parentScale.y) + vertOffset, 0.0f);
  45.             Vector3 topRight = new Vector3(1280.0f * parentScale.x, (720.0f * parentScale.y) + vertOffset, 0.0f);
  46.             Vector3 bottomLeft = new Vector3(-1280.0f * parentScale.x, (-720.0f * parentScale.y) + vertOffset, 0.0f);
  47.             Vector3 bottomRight = new Vector3(1280.0f * parentScale.x, (-720.0f * parentScale.y) + vertOffset, 0.0f);
  48.  
  49.             Gizmos.DrawLine(topLeft, topRight);
  50.             Gizmos.DrawLine(topRight, bottomRight);
  51.             Gizmos.DrawLine(bottomRight, bottomLeft);
  52.             Gizmos.DrawLine(bottomLeft, topLeft);
  53.         }
  54.         }
  55. }
  56.  

Hope this helps.
Title: Re: is it possible to see the cameras clipping edges
Post by: ArenMook on July 29, 2012, 07:34:24 PM
This is already a part of the current NGUI build. I guess I added it after the last update? You'll see it in the next one. The panel's rect will be visible when you have any widget selected (or a parent of a widget for that matter).
Title: Re: is it possible to see the cameras clipping edges
Post by: dlewis on July 29, 2012, 08:01:17 PM
I guess I added it after the last update?

No it's part of the latest build (2.1.2, just tested it). I remember reading that in the release notes but I've been using this script for a few months (and we need to know screen safe area so that has to be custom).
Title: Re: is it possible to see the cameras clipping edges
Post by: reptilebeats on July 31, 2012, 09:08:58 PM
i still can't see the outline if i select a child inside the parent with the camera, is it a script i have to add onto it as i tend to use my own camera without the scripts, and just the UI(Root)Script
Title: Re: is it possible to see the cameras clipping edges
Post by: reptilebeats on July 31, 2012, 09:43:20 PM
this code is pretty close to what i was looking for, just 4 lines around the viewports rect, but will change with camera size and follow camera.