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

카테고리

분류 전체보기 (2731)
Unity3D (814)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
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
03-29 07:22
게임을 만들면 UICamera와 MainCamera 두 개를 보통 쓰는 데,

UI를 클릭하고 싶어서 클릭했더니 MainCamera쪽도 체크돼서 두 곳 다 실행되는 경우가 생기는데..

우연한 기회에 답을 주신 분이 있어서 적어놓는다.


NGUI 기준..

UICamera 클래스를 보면 

static public GameObject hoveredObject;

가 있다.

hover(UI 오브젝트 위에 있는 상태) 된 오브젝트가 들어가 있는 곳인가보다..


hoveredObject가 null이면 UI위에 있는 상태가 아니니, 다시 말해 터치된 곳에 UI가 없는 상태니 MainCamera쪽을 실행하면 되겠다.


if(null == UICamera.hoveredObject)

{

    // 게임쪽 클릭 처리

}




출처 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=37658&sca=&sfl=wr_subject%7C%7Cwr_content&stx=%EC%B9%B4%EB%A9%94%EB%9D%BC&sop=and&currentId=44

반응형
Posted by blueasa
, |

나(me)같은 초보를 위해 사용법(?) 추가..;


1. C# 스크립트 생성.

2. 생성한 스크립트에 아래 소스 추가/저장.

3. 생성한 스크립트를 Main Camera에 드래그&드랍..

4. Scene창의 Gizmos에 보면 추가한 스크립트가 추가된 게 보이고, 토글이 가능하다.

------------------------------------------------------------------------------------------

NGUI(무료버전) 레이아웃 작업 중....


현재 화면에서 GUI배치하기가 너무 어려워서 현재 화면 크기를 카메라를 선택하지 않아도 계속 유지하고 싶었다.


역시나 나 같은 생각을 가진 사람이 있었다. 아래 링크를 참고하자.

http://answers.unity3d.com/questions/291467/scene-view-stretches-camera-frustum-gizmo.html


링크를 가고 싶지 않은 사람은 아래 코드를 가져다가 쓰면 된다.


    public static Vector2 GetMainGameViewSize()

{ System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor"); System.Reflection.MethodInfo GetSizeOfMainGameView = T.GetMethod("GetSizeOfMainGameView",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); System.Object Res = GetSizeOfMainGameView.Invoke(null,null); return (Vector2)Res; } void OnDrawGizmos() { Camera cam = this.camera; // Top left Vector3 tlN = cam.ScreenToWorldPoint(new Vector3(Screen.width*0, Screen.height, cam.nearClipPlane)); Vector3 tlF = cam.ScreenToWorldPoint(new Vector3(Screen.width*0, Screen.height, cam.farClipPlane)); // Top right Vector3 trN = cam.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, cam.nearClipPlane)); Vector3 trF = cam.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, cam.farClipPlane)); // Bottom left Vector3 blN = cam.ScreenToWorldPoint(new Vector3(0.0f, 0.0f, cam.nearClipPlane)); Vector3 blF = cam.ScreenToWorldPoint(new Vector3(0.0f, 0.0f, cam.farClipPlane)); // Bottom right Vector3 brN = cam.ScreenToWorldPoint(new Vector3(Screen.width, 0.0f, cam.nearClipPlane)); Vector3 brF = cam.ScreenToWorldPoint(new Vector3(Screen.width, 0.0f, cam.farClipPlane)); // Scale for aspect ratio Vector2 gameViewsize = GetMainGameViewSize(); // float gameViewAspect = gameViewsize.x / gameViewsize.y;

 // 화면 비율에 맞추기 위해서 수정[blueasa]

float gameViewAspect = Screen.width / Screen.height; float s = gameViewAspect / cam.aspect; tlN.x *= s; tlF.x *= s; trN.x *= s; trF.x *= s; blN.x *= s; blF.x *= s; brN.x *= s; brF.x *= s; Gizmos.color = Color.white; // Near Gizmos.DrawLine(tlN, trN); Gizmos.DrawLine(trN, brN); Gizmos.DrawLine(brN, blN); Gizmos.DrawLine(blN, tlN); // Far Gizmos.DrawLine(tlF, trF); Gizmos.DrawLine(trF, brF); Gizmos.DrawLine(brF, blF); Gizmos.DrawLine(blF, tlF); // Sides Gizmos.DrawLine(tlN, tlF); Gizmos.DrawLine(trN, trF); Gizmos.DrawLine(brN, brF); Gizmos.DrawLine(blN, blF); }


[출처] 유니티. Gizmos로 카메라 프러스텀 보이게 하기.|작성자 괴발자

반응형

'Unity3D' 카테고리의 다른 글

유니티 관련  (0) 2012.10.17
Transform Custom Editor  (0) 2012.10.15
유니티에 툴바 만들기..  (0) 2012.10.15
유니티에서 툴 만들기  (0) 2012.10.12
[링크] 유니티 관련 사이트  (0) 2012.10.12
Posted by blueasa
, |