Author Topic: Using UI without camera  (Read 3850 times)

pushxtonotdie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Using UI without camera
« on: May 25, 2012, 02:39:08 PM »
I'd like to use the NGUI framework as items within the scene. In my case there is a tooltip in 3d space that would be clickable. I have created a new UI without a camera by selecting 'none' in the UI panel. I can create and display my UI without issue, but items are not clickable. Is it possible to use NGUI without requiring a camera object at the top of the hierarchy?

pushxtonotdie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Using UI without camera
« Reply #1 on: May 25, 2012, 04:13:57 PM »
After looking around it seems that the interaction of the basic UIButton* scripts all require a UICamera. I have made a quick adapter to more easily use these components without a UI Component:

  1.         public void OnMouseEnter(){
  2.                 SendMessage("OnHover", true, SendMessageOptions.DontRequireReceiver);
  3.         }
  4.  
  5.         public void OnMouseExit(){
  6.                 SendMessage("OnHover", false, SendMessageOptions.DontRequireReceiver);
  7.         }
  8.  
  9.         public void OnMouseDown()
  10.         {
  11.                 SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
  12.         }
  13.  
  14.         public void OnMouseUp()
  15.         {
  16.                 SendMessage("OnPress", false, SendMessageOptions.DontRequireReceiver);
  17.         }
  18.  

This seems to work if I put it on a button (or I guess similar control).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UI without camera
« Reply #2 on: May 25, 2012, 05:01:09 PM »
You need the UICamera component on your game camera, or nothing seen by the game camera will be capable of receiving events.

Just attach a UICamera to your game camera.