Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: mbysky on April 09, 2015, 09:11:54 PM

Title: About void ProcessFakeTouches () in UICamers.cs
Post by: mbysky on April 09, 2015, 09:11:54 PM
I develop app in iOS platform, I only use the Touch Event Source of UICamera, and dsiable the Allow Multi Touch.

If I clicked some Collider by mouse in Unity Editor,
UICamera will call void ProcessFakeTouches (),
I fount that "static public MouseOrTouch currentTouch = null;" is not get from "static public MouseOrTouch GetTouch (int id)".(Because currentTouch is get from GetTouch(touchId) in “public void ProcessTouches ()” )
so I can't get position by UICamera.GetTouch(UICamera.currentTouchID), I'm not sure it a bug, but I think it will be better if you modify this problem.

Thanks.
Title: Re: About void ProcessFakeTouches () in UICamers.cs
Post by: ArenMook on April 12, 2015, 04:24:00 PM
You shouldn't be using UICamera.GetTouch at all. You should be checking UICamera.currentTouch. There is also UICamera.activeTouches listing all the currently active touches. Although you probably should change UICamera.ProcessFakeTouches to this:
  1.         void ProcessFakeTouches ()
  2.         {
  3.                 bool pressed = Input.GetMouseButtonDown(0);
  4.                 bool unpressed = Input.GetMouseButtonUp(0);
  5.                 bool held = Input.GetMouseButton(0);
  6.  
  7.                 if (pressed || unpressed || held)
  8.                 {
  9.                         currentTouchID = 1;
  10.                         currentTouch = mMouse[0];
  11.                         currentTouch.touchBegan = pressed;
  12.  
  13.                         if (pressed)
  14.                         {
  15.                                 currentTouch.pressTime = RealTime.time;
  16.                                 activeTouches.Add(mMouse[0]);
  17.                         }
  18.  
  19.                         Vector2 pos = Input.mousePosition;
  20.                         currentTouch.delta = pressed ? Vector2.zero : pos - currentTouch.pos;
  21.                         currentTouch.pos = pos;
  22.  
  23.                         // Raycast into the screen
  24.                         if (!Raycast(currentTouch.pos)) hoveredObject = fallThrough;
  25.                         if (hoveredObject == null) hoveredObject = mGenericHandler;
  26.                         currentTouch.last = currentTouch.current;
  27.                         currentTouch.current = hoveredObject;
  28.                         lastTouchPosition = currentTouch.pos;
  29.  
  30.                         // We don't want to update the last camera while there is a touch happening
  31.                         if (pressed) currentTouch.pressedCam = currentCamera;
  32.                         else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;
  33.  
  34.                         // Process the events from this touch
  35.                         ProcessTouch(pressed, unpressed);
  36.  
  37.                         // If the touch has ended, remove it from the list
  38.                         if (unpressed) activeTouches.Remove(mMouse[0]);
  39.                         currentTouch.last = null;
  40.                         currentTouch = null;
  41.                 }
  42.         }