게임 프로그래머의 만담, 게임코디 2nd
+5 투표
601 views 만담 (38.9kp) , 601 views

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 기준으로 다시 재계산했습니다.

만담에 대한 답글을 하려면 로그인 또는 가입해야합니다.

게임 프로그래머의 만담 커뮤니티, 게임코디 입니다

온종일 코드와 씨름하는 우리들의 외로움을 삭이고자 합니다