Author Topic: [SOLVED]Fixed size pixel adjustment for touch calculations.  (Read 1730 times)

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
[SOLVED]Fixed size pixel adjustment for touch calculations.
« on: November 11, 2014, 02:06:20 AM »
So i have an widget that is about 466 in height as the widget indicates and it is anchored to the bottom, so this to me would indicate it is 466 pixels up the screen yes?

I am then getting the mouse position and finding out how far from the top of the widget it is...wether it is under the height of 466 or more. However the "UICamera.currentTouch.pos" code seems to return a position that is affected by screen scaling where as the height im currently getting from the UIWidget is not...soIi have to scale one or the other by something, and i am not certain what. I have tried "UIRoot.GetPixelSizeAdjustment" but that scaling value is still a bit off it seems. here is my current code.

  1. void CalculateDisplacementFromCrossOver ()
  2. {
  3.     cardHandWidget = objectToBeginScrollingFrom.GetComponent<UIWidget>();
  4.     var docksMaxY = cardHandWidget.localSize.y;
  5.     var touchPointInStandardScreenSpace = UICamera.currentTouch.pos.y;//in pixels
  6.     displacementFromCrossover = touchPointInStandardScreenSpace - docksMaxY;
  7.  
  8.     Debug.Log("pixel size adjustment:"+UIRoot.GetPixelSizeAdjustment(cardHandWidget.gameObject));
  9.     Debug.Log("touch Height:"+touchPointInStandardScreenSpace);
  10. }
  11.  
« Last Edit: November 12, 2014, 01:12:10 AM by Genhain »

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Re: [SOLVED]Fixed size pixel adjustment for touch calculations.
« Reply #1 on: November 12, 2014, 01:15:17 AM »
So the previous code i had, worked for pixel perfect but not fixedSize or constrained...this however works on both for getting the docks top position on screen that scales properly.

  1. void CalculateDisplacementFromCrossOver ()
  2. {
  3.         cardHandWidget = objectToBeginScrollingFrom.GetComponent<UIWidget>();
  4.     Vector3 pos = cardHandWidget.transform.localPosition;
  5.     pos.y += cardHandWidget.localSize.y/2;
  6.  
  7.     var docksMaxY = UICamera.currentCamera.WorldToScreenPoint(cardHandWidget.transform.parent.TransformPoint(pos)).y;
  8.     var touchPointInStandardScreenSpace = UICamera.currentTouch.pos.y;
  9.  
  10.         displacementFromCrossover = touchPointInStandardScreenSpace - docksMaxY;
  11. }
  12.