Author Topic: NGUI using custom mouse position  (Read 6447 times)

sebas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
NGUI using custom mouse position
« on: May 24, 2012, 07:00:15 AM »
Hi,

NGUI camera code uses directly Input.MousePosition to get the mouse position, but what should I do if the cursor position is instead managed by the application?

Let's say I use Screen.lockCursor  and use the delta values to manage the mouse coord on my own. What do you suggest me to use? Thank you very much

loopyllama

  • Guest
Re: NGUI using custom mouse position
« Reply #1 on: May 24, 2012, 07:31:57 AM »
You calculate your "mouse" position in a script. Place the script execution order early so that it is processed first. "publish" the value to a global static variable, let's call it fauxMousePosition in script FauxMouse. You could simply do a find & replace all on Input.MousePosition in the NGUI folder, changing it to FauxMouse.fauxMousePosition. That is the value of having the source code...

I am sure there are other ways. This is the first that comes to mind. It will also be simple to add your changes to newer updates of NGUI (a simple find and replace across all NGUI files each time you update NGUI).

sebas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: NGUI using custom mouse position
« Reply #2 on: May 24, 2012, 07:45:48 AM »
oh yeah, I can surely change NGUI code, but that is what I want absolutely to avoid.

sebas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: NGUI using custom mouse position
« Reply #3 on: May 24, 2012, 08:38:00 AM »
if there is not another solution, I would suggest to use a proxy interface to get the current Input position, so it would be very easy for me to change just the input position provider. Please advise.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI using custom mouse position
« Reply #4 on: May 24, 2012, 10:32:19 AM »
For something fairly specific like this, I suggest just modifying the UICamera to suit your needs and just creating a patch out of that to make future updates painless. Just search-and-replace Input.mousePosition with your own value.

sebas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: NGUI using custom mouse position
« Reply #5 on: May 24, 2012, 10:50:18 AM »
thank you, I do not like changing NGUI at all, it would be a mess to update it.
However I could just thought about the wrong solution to my problem.
I need to be able to let the player rotate the (fps-like) camera continuously and avoid it to stop when the cursor is outside the screen.
In order to do so I used a mix of Screen.lockCursor and Input.GetAxis("Mouse Y").
Now I am not sure what to do when I release the cursor, but my first idea was remember the last position and set it back once the mouse button was released. This solution is not feasible because the Input.mouseposition is readonly.
The other solution is to make the software cursor appear always at the center of the screen, this would solve all the problems, but I am not sure about it could feel like.
Do you have advices about this problem? Thank you.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI using custom mouse position
« Reply #6 on: May 24, 2012, 10:56:05 AM »
Assuming you use the locked cursor to control the character, the unlocked cursor is what will interact with the UI, so I'm not sure why this modification would be needed. If the mouse ends up somewhere else when you unlock it, it's ok, isn't it? It seems you're trying to go around a limitation in Unity here.

sebas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: NGUI using custom mouse position
« Reply #7 on: May 24, 2012, 11:58:30 AM »
if I got it correctly everytime the cursor is locked and unlocked it restarts from the c enter of the view, it does not remember the last position of the cursor before the lock. I wanted to avoid this, but it looks like it is not worth it, unless there is something I am missing.
Thanks for your time though!