Author Topic: Forward Clicks To Render To Texture NGUI  (Read 2957 times)

karljj1

  • Guest
Forward Clicks To Render To Texture NGUI
« on: November 13, 2013, 12:27:17 PM »
Hi,

This is a question I posted on Unity Answers but I think its also worth posting here.
http://answers.unity3d.com/questions/574612/ngui-forward-clicks-to-render-to-texture-ngui.html#comment-574700

I have a GUI created using NGUI. I now want to place the GUI into my environment by rendering the GUI to a texture which works fine. However I can no longer interact with the GUI, what is the best way to forward my clicks to the NGUI widgets? Does NGUI have a script for this?

I was thinking of doing something like this:

Fire ray cast into texture plane. Get normalised position. Convert position to NGUI screen position. Fire ray from NGUI screen position. Send the OnClick message to any hit objects with the correct GUI layer.

Is there a simpler way than this?

Thanks

Karl

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Forward Clicks To Render To Texture NGUI
« Reply #1 on: November 13, 2013, 03:35:19 PM »
You need a UICamera attached to whichever camera can see the UI. If multiple UIs are used, you will need multiple UICameras. If the main camera draws UI elements, you need a UICamera on the main camera as well.

karljj1

  • Guest
Re: Forward Clicks To Render To Texture NGUI
« Reply #2 on: November 14, 2013, 03:56:53 AM »
Hi Aren,

I have 1 camera that renders the UI to a texture. This texture is then part of the environment, e.g an interactive wall. The main game camera needs to be able to interact with the UI through the texture. The actual UI is at the centre of the world and is very small. How can I forward these events to the UI?
Adding a UICamera to my Camera does not work as the items I am clicking on are in a texture, not the actual UI widgets.

Thanks

Karl

Edit:

Is this something I could do in the Raycast function that is part of UICamera?

Edit:

Ok I think I have a solution.
I created a new 3d UI. I disabled the UIRoot object and moved the UI so it was on my wall and the correct scale. I disabled the UI camera and added a UICamera to my world camera. The UI is now drawn in the world like a standard part of scenery and can be interacted with. Is this the correct way to do things?

Thanks

Karl
« Last Edit: November 14, 2013, 04:13:08 AM by karljj1 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Forward Clicks To Render To Texture NGUI
« Reply #3 on: November 14, 2013, 03:17:13 PM »
Yes, an in-game 3D UI is the way to go in your case.