gree webview 붙이는 과정에서 발생한 좌표 재계산 관련내용을 기록용으로 남깁니다.
ScreenResolution을 변경한경우 최종 디바이스 좌표가 맞지 않습니다.
변경하기 전에 미리 백업해두셔야 스케일 적용해서 재계산 가능합니다
int DeviceWidth = Screen.width;
int DeviceHeight = Screen.height;
ui -> world -> screen
area = transform.Find("WEBVIEW") as RectTransform;
Vector3[] corners = new Vector3[4];
area.GetWorldCorners(corners); // lb, lt, rt, rb
Vector3 leftBottom = corners[0];
Vector3 rightTop = corners[2];
Debug.Log("world " + leftBottom + " " + rightTop);
var leftBottomScreen =
RectTransformUtility.WorldToScreenPoint(UICamera, leftBottom);
var rightTopScreen =
RectTransformUtility.WorldToScreenPoint(UICamera, rightTop);
Debug.Log("screen " + leftBottomScreen + " " + rightTopScreen);
Debug.Log("screen wh " + Screen.width + " x " + Screen.height);
Debug.Log("device wh " + DeviceWidth + " x " + DeviceHeight);
디바이스 좌표로는 저장해둔 원래 화면비율로 재계산해줍니다.
이경우는 상하좌우 마진을 계산하는 코드입니다
int marginLeft = Mathf.FloorToInt(leftBottomScreen.x);
int marginTop = Screen.height - Mathf.CeilToInt(rightTopScreen.y);
int marginRight = Screen.width - Mathf.CeilToInt(rightTopScreen.x);
int marginBottom = Mathf.FloorToInt(leftBottomScreen.y);
Debug.Log(string.Format("screen margins {0} {1} {2} {3} "
, marginLeft, marginTop, marginRight, marginBottom));
marginLeft = marginLeft * DeviceWidth / Screen.width;
marginRight = marginRight * DeviceWidth / Screen.width;
marginTop = marginTop * DeviceHeight / Screen.height;
marginBottom = marginBottom * DeviceHeight / Screen.height;
제경우는 네이티브 1920x1080 에서 1280x720 으로 해상도를 변경했기때문에
마진이 720p 기준으로 잡혀 1080p 기준으로 다시 재계산했습니다.