Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: DoctorWhy on October 17, 2012, 03:42:15 PM

Title: Using OnGui and NGUI
Post by: DoctorWhy on October 17, 2012, 03:42:15 PM
I am using NGUI with my background and foreground cameras.  This works great.  However, I have a middle ground camera that has an object that uses OnGUI() instead, but it is drawing in front of the Foreground camera.  How can I make it so the foreground camera that is controlled with NGUI appears in front of my OnGUI elements in the middle ground? I have tried changing the GUI.depth to very low (-1000) and very high (1000), and it still appears in front. The reason I am using the OnGUI instead is because it is very simple to do what I need it to do, and NGUI didn't work for it (at least, not easily).
Title: Re: Using OnGui and NGUI
Post by: Nicki on October 17, 2012, 04:12:22 PM
OnGUI is always on top of everything. No way to fix as far as I know. :/

Also, OnGUI is unusable on mobile devices for performance purposes.
Title: Re: Using OnGui and NGUI
Post by: DoctorWhy on October 17, 2012, 04:26:03 PM
I knew OnGUI was inefficient, but I didn't think it was that bad for mobile devices.  In that case, how would I use NGUI in the same way I do this:

  1. float size = 4f;       
  2. GUI.color = color;
  3.                
  4. Vector3 position = MainCamera.WorldToScreenPoint(posable.position);
  5. GUI.DrawTexture(
  6.         new Rect(
  7.         position.x - size,
  8.         Screen.height - position.y - size,
  9.         size * 2,
  10.         size * 2
  11.         ), texture
  12. );
  13.  

When I tried to do something very similar with NGUI, the position was completely off.  I couldn't figure out how to draw it without worrying about Z position, so it always needs to appear the exact same size, even when the middleground camera (this one isn't orthogonal) moves around and zooms in.  It needs to line up with the 3D elements on the middleground camera.
Title: Re: Using OnGui and NGUI
Post by: PhilipC on October 18, 2012, 10:39:59 AM
Take a look at this forum post. It allows for Hud elements to be position relative a object in 3d space drawn by a different camera.

http://www.tasharen.com/forum/index.php?topic=130.msg7998#msg7998