Author Topic: Secondary UIRoot to Display Controls on the Floor Plane  (Read 2667 times)

docgonzzo

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 10
    • View Profile
Secondary UIRoot to Display Controls on the Floor Plane
« on: June 01, 2015, 07:03:44 PM »
Hi

I'm trying to make NGUI show buttons & controls etc on the floor in a 3D game. The floor is a 2D plane, and the main camera has an isometric view of the floor.

I also already have a regular/traditional UIRoot & camera, for all my normal UI buttons etc.

To accomplish this, I attached a secondary UIRoot to the floor plane and made it co-planar to the floor. I also attached a UICamera to the Main Camera (the isometric camera) to receive the NGUI events from the floor's controls.

Furthermore, I set the two UIRoots to be on different layers, so that the Event Mask on the UICamera (the one second one attached to the Main Camera) can be set to only see events on the floor plane UIRoot layer.

It appears to be working correctly, but I'm wondering if this is this the correct or easiest way to accomplish something like this?

Any help is appreciated!
Thanks!

docgonzzo

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Secondary UIRoot to Display Controls on the Floor Plane
« Reply #1 on: June 02, 2015, 05:23:30 PM »
I forgot to mention, I'm also getting the following error when doing this:

Screen position out of view frustum (screen pos 0.000000, 0.000000, 16.381290) (Camera rect 0 0 0 0)
UnityEngine.Camera:ViewportToWorldPoint(Vector3)
NGUITools:GetWorldCorners(Camera, Single, Transform)...


Is this error coming up because part of the UIPanel is out of view of the camera?


Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Secondary UIRoot to Display Controls on the Floor Plane
« Reply #2 on: June 07, 2015, 12:23:53 PM »
The frustom error happens because your camera rect is (0, 0, 0, 0). It's invalid.

To add widgets to your 3D space, simply create a 3D UI, not a 2D one. Or better yet, just add widgets to your 3D world as-is. Just make sure you have a UIPanel to add them to, or it will default to your existing UI. A widget is just like any other game object that you can position in the world. The layer it's on is what determines which camera sees it, and the panel it's under determines which batch of draw calls it will be in.