블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-20 00:00

NGUI를 이용해서 UI 제작을 하면서 UI 디자이너에게서 리소스와 배치 데이터를 받아서 작업을 하는 데,


유니티 특성상 UI는 트리노드 구조를 가져서 특정 UI의 좌표가 어떤지 알기가 힘들어서 쉽게 보기 위해 대충 만들어 봤다.


당장 그냥 쓰기 위해 위치나 색깔등 대충해서 만들기..


따로 넣기도 귀찮아서 그냥 NGUI 소스인 UIWidget.cs에 추가 했다.


P.s. UI디자이너가 포토샵을 보통 쓰기때문에 NGUI가 데카르트 좌표계를 쓰고 있지만 UI디자이너가 주는 정보와 매칭되게 하기 위해서 스크린좌표계로 변환해서 보여주도록 했음.



public class UIWidget : UIRect
{
    ....
    void OnDrawGizmos ()
    {
        .....
#if UNITY_EDITOR
        // 아래 추가한 함수를 여기서 실행.
            ShowSelectedUICoordinate();
#endif // UNITY_EDITOR
    }

#if UNITY_EDITOR  // 에디터에서만 실행하도록..
    /// 
    /// 선택된 UI의 좌표(X/Y/Width/Height) 보여주는 함수.
    /// 좌표계는 스크린좌표계 기준.
    /// 

void ShowSelectedUICoordinate() { // by blueasa if (UnityEditor.Selection.activeGameObject == gameObject) { // 타겟 해상도(1280x720) 자신이 원하는 해상도에 맞게 변경. float fScreenWidth = 1280f; float fScreenHeight = 720f; Camera cUICamera = UICamera.mainCamera; if (null == cUICamera) { UnityEngine.Debug.LogWarning("Can't find UICamera.."); return; } GUIStyle style = new GUIStyle(); style.normal.textColor = Color.yellow; // UI는 데카르트 좌표계이므로 스크린 좌표계로 변환해서 사용. // X/Y를 Widget 중심으로 사용하기로 해서 수정. 좌측상단 사용하려면 선택하면 될 듯.. #region X/Y Widget 중심(스크린 좌표계) //float fX = cUICamera.WorldToViewportPoint(worldCenter).x * fScreenWidth; //float fY = (1f - cUICamera.WorldToViewportPoint(worldCenter).y) * fScreenHeight; //// X/Y가 Widget의 중심이기때문에 크기가 1/2만 나오므로 원래크기를 만들기 위해 2를 곱함. //float fWidth = ((cUICamera.WorldToViewportPoint(worldCorners[3]).x * fScreenWidth) - fX) * 2f; //float fHeight = (((1f - cUICamera.WorldToViewportPoint(worldCorners[3]).y) * fScreenHeight) - fY) * 2f; #endregion #region X/Y Widget 중심(데카르트 좌표계) float fX = cUICamera.WorldToViewportPoint(worldCenter).x * fScreenWidth; float fY = cUICamera.WorldToViewportPoint(worldCenter).y * fScreenHeight; // X/Y가 Widget의 중심이기때문에 크기가 1/2만 나오므로 원래크기를 만들기 위해 2를 곱함. float fWidth = ((cUICamera.WorldToViewportPoint(worldCorners[2]).x * fScreenWidth) - fX) * 2f; float fHeight = ((cUICamera.WorldToViewportPoint(worldCorners[2]).y * fScreenHeight) - fY) * 2f; #endregion #region X/Y 좌측상단(스크린 좌표계) //float fX = cUICamera.WorldToViewportPoint(worldCorners[1]).x * fScreenWidth; //float fY = (1f - cUICamera.WorldToViewportPoint(worldCorners[1]).y) * fScreenHeight; //float fWidth = (cUICamera.WorldToViewportPoint(worldCorners[3]).x * fScreenWidth) - fX; //float fHeight = ((1f - cUICamera.WorldToViewportPoint(worldCorners[3]).y) * fScreenHeight) - fY; #endregion string strXYWH = string.Format("[X] {0:0.00}, [Y] {1:0.00} [W] {2:0.00}, [H] {3:0.00}", fX, fY, fWidth, fHeight); UnityEditor.Handles.Label(transform.position, strXYWH, style); // 참고.. //Debug.Log("worldCorners[0] " + camera.WorldToViewportPoint(worldCorners[0])); // 좌하(↙) //Debug.Log("worldCorners[1] " + camera.WorldToViewportPoint(worldCorners[1])); // 좌상(↖) //Debug.Log("worldCorners[2] " + camera.WorldToViewportPoint(worldCorners[2])); // 우상(↗) //Debug.Log("worldCorners[3] " + camera.WorldToViewportPoint(worldCorners[3])); // 우하(↘) } } #endif // UNITY_EDITOR }



출처 : Mine


반응형
Posted by blueasa
, |