블로그 이미지
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 00:00

NGUI 를 사용하면서 일반 오브젝트와 UI 오브젝트의 입력(터치)을 어떻게 처리해야 할지 알아본다.



일단, 보통은 게임에서 사용하는 Main Camera와 NGUI > Create UI 를 통해 생성되는 2D Camera(UI Camera) 두개(혹은 그 이상)를 사용할 것이다.


당연히 UICamera에 추가되는 Widget들은 UICamera 의 통제에 의해 OnHover, OnClick 등의 이벤트를 받는다.


하지만 게임오브젝트를 선택하려면? 당신은 여러가지의 고민을 하게된다.

'UI의 이벤트를 받지 않으려면?', '혹은 UI를 클릭했을때 게임오브젝트의 클릭을 무시하려면?' 등등...

하여, 이를 해결하기 위해 Picking Manager 라던지 NGUI의 메시지를 무시하는 플래그를 작성하던지의 시도를 해볼것이다.


NGUI는 이 상황에 대해 다음을 권고한다.


'모든 카메라에 UICamera 컴포넌트를 추가하세요!' 


일단 NGUI:UICamera 의 내용을 보면, UI카메라에 추가되었을경우엔 UI 들에게, Main Camera에 추가하면 인게임 오브젝트들에게 특정 이벤트 메시지를 보낸다고 써져있다. 본문


이벤트는 다음 링크를 참고한다. 이벤트



실제로 테스트 해본 결과,


1. 같은 레이어상의 UI와 non-UI 오브젝트(in-game object)로 테스트 시.

2개의 카메라(Main-Camera, UI-Camera)에 각각 UICamera 컴포넌트를 포함시킨후 실험.

NGUI Widget 툴을 통해 UI-Camera에 바탕 윈도우와 버튼을 하나 추가했다.

테스트를 위해 2개의 큐브를 씬에 추가. 스크립트를 작성하되, void OnClick() 함수를 추가했다.



테스트 결과, 버튼 영역을 클릭했을때, UIButton만 동작되었다.

게임 오브젝트 클릭시 OnClick이벤트가 정상 동작되었으며, 깊이에 따라 먼저 클릭된 게임오브젝트만 동작되었다.

버튼 영역을 제외한 UI윈도우 영역은 클릭테스트에 제외되며, 게임 오브젝트가 하단에 존재하면 게임오브젝트 이벤트가 호출된다.


- UI윈도우도 클릭테스트에 포함시키기 위해서는 Add Component > Physics > Box Collider 를 추가해준다. 추가후에는 윈도우에서 이벤트를 처리하기 때문에 윈도우 영역 클릭시 게임 오브젝트는 이벤트를 받지 않는다.


- 버튼이 isEnable=false; 되어있다면, 이벤트를 받지 않는다.


2. UI 부분을 다른 레이어로 세팅.

- 동일한 레이어일때와 결과가 같다.



즉, 이왕 NGUI를 사용한다면, 모든 카메라에 UICamera 컴포넌트를 추가하고, 입력이 필요한 오브젝트 마다 이벤트 함수를 추가해주자.



출처: http://toymaker.tistory.com/entry/NGUI-UI와-일반-오브젝트의-터치-이벤트-처리 [ToyMaker]

반응형
Posted by blueasa
, |
게임을 만들면 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
, |

아래 둘 중 하나인 듯..


UnityEditor.SceneView.currentDrawingSceneView.camera


or


UnityEditor.SceneView.lastActiveSceneView.camera



참조 : http://forum.unity3d.com/threads/64920-Moving-scene-view-camera-from-editor-script?highlight=scene+view+camera



반응형
Posted by blueasa
, |

You can create a window in your gui with Gui.Windowhttp://unity3d.com/support/documentation/ScriptReference/GUI.Window.html?from=EditorWindow

Have the window you just made contain a RenderTexture.http://unity3d.com/support/documentation/Components/class-RenderTexture.html


http://unity3d.com/support/documentation/ScriptReference/EditorWindow-autoRepaintOnSceneChange




출처 : http://answers.unity3d.com/questions/33858/how-to-create-an-editor-screenview-like-camera-pre.html




반응형
Posted by blueasa
, |

Smooth Follow Camera

Unity3D / 2012. 11. 6. 00:10

SmoothFollow2

Author: Daniel

Improved Version

Author: Vasilis Christopoulos & Daniel Toliaferro

Contents

 [hide

Description

This is designed to make a camera smoothly follow a ship in space.

Usage

Place this script onto a camera.

JavaScript - SmoothFollow2.js

var target : Transform;
var distance = 3.0;
var height = 3.0;
var damping = 5.0;
var smoothRotation = true;
var rotationDamping = 10.0;

function Update () {
	var wantedPosition = target.TransformPoint(0, height, -distance);
	transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);

	if (smoothRotation) {
		var wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
		transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
	}

	else transform.LookAt (target, target.up);
}

C# - SmoothFollow2.cs

using UnityEngine;
using System.Collections;

public class SmoothFollow2 : MonoBehaviour {
	public Transform target;
	public float distance = 3.0f;
	public float height = 3.0f;
	public float damping = 5.0f;
	public bool smoothRotation = true;
	public float rotationDamping = 10.0f;
	
	void Update () {
		Vector3 wantedPosition = target.TransformPoint(0, height, -distance);
		transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);

		if (smoothRotation) {
			Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
			transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
		}
		
		else transform.LookAt (target, target.up);
	}
}

C# - SmoothFollow2.cs (Improved)

using UnityEngine;
using System.Collections;

        public class SmoothFollow2 : MonoBehaviour {
        public Transform target;
        public float distance = 3.0f;
        public float height = 3.0f;
        public float damping = 5.0f;
        public bool smoothRotation = true;
        public bool followBehind = true;
        public float rotationDamping = 10.0f;

        void Update () {
               Vector3 wantedPosition;
               if(followBehind)
                       wantedPosition = target.TransformPoint(0, height, -distance);
               else
                       wantedPosition = target.TransformPoint(0, height, distance);
     
               transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);

               if (smoothRotation) {
                       Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
                       transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
               }
               else transform.LookAt (target, target.up);
         }
}


출처 : http://wiki.unity3d.com/index.php/SmoothFollow2

반응형
Posted by blueasa
, |