Author Topic: Question about raycasting with ngui interface.  (Read 2651 times)

dRosser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Question about raycasting with ngui interface.
« on: March 11, 2014, 04:40:52 PM »
We are converting an already existing project that uses mouse and touch controls, for pc and mobile devices, to an environment where we have to use a custom pointer that uses screen coordinates. At a glance, it seems like ngui supports raycasting to simulate hits and touches onto ui elements, but i was wondering if there was a better way besides just setting it for raycasting.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question about raycasting with ngui interface.
« Reply #1 on: March 11, 2014, 05:44:05 PM »
Have a look at UICamera.onCustomInput callback.

dRosser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Question about raycasting with ngui interface.
« Reply #2 on: March 11, 2014, 07:11:20 PM »
Okay I have looked at it and I think I have it most of the way worked out. But I might be having a problem with uicamera.notify now. Currently when I have clicked on a ui element with the mouse I can activate it as many times as I want, even though my UICamera.selectedObject is being changed on every raycast.

void Awake()
   {
      UICamera.onCustomInput = NGUIinput;
   }
   
   void NGUIinput()
   {
      if(hintButtonDown)
      {
         print("hit object " + UICamera.selectedObject);
         UICamera.Notify(UICamera.selectedObject, "onKey", KeyCode.Mouse0);
      }
   }

void Update ()
   {
      if(hintButtonDown)
      {

         UICamera.selectedObject = UICamera.Raycast(new Vector3(cursorX, (Screen.height - ursorSystem.Instance.cursorY)), ref cursorHit) ? cursorHit.collider.gameObject : fallThrough;

      
      }
      }

with that trimmed down code and some print statements I can see that i'm accurately raycasting to ngui elements and hitting them, my customInput function won't actually "click" them unless a mouse has clicked them. Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question about raycasting with ngui interface.
« Reply #3 on: March 11, 2014, 11:56:28 PM »
Why are you using UICamera.selectedObject? You said you have a custom pointer... which means you should have your own custom logic that goes with it -- where its position is, which leads to when to raycast, etc. Don't touch UICamera.selectedObject.

Furthermore, Not sure what "onKey" is supposed to be. If you meant "OnKey" (note the capitalization), it's quite limited by what events it sends. Arrow keys, mostly. Have a closer look at what NGUI does inside one of its message processing functions such as UICamera.ProcessFakeTouches.