Unity/Unity 리서치 103

영상(Video Player) 재생

화면 전체 재생 RAW Image에 재생 1. Video Player를 하나 만듦 2. RawImage를 하나 만듦 3. Raw Image의 Texture를 VideoPlayer걸로 바꿈 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; public class VideoHandler : MonoBehaviour { public RawImage mScreen; public VideoPlayer mVideoPlayer; void Start() { if (mScreen != null && mVideoPlayer != null) { Sta..

[Firestore] 커스텀객체(Custom Object) - Dictionary 변환

Firestore에서 자체적으로 기능을 제공 Object 코드 using Firebase.Firestore; [FirestoreData] public class City { [FirestoreProperty] public string Name { get; set; } [FirestoreProperty] public string State { get; set; } [FirestoreProperty] public string Country { get; set; } [FirestoreProperty] public bool Capital { get; set; } [FirestoreProperty] public long Population { get; set; } } Post하는 코드 private Firebas..

Dictionary와 Object 변환

Firebase는 Dictionary이고, 관리의 편의를 위해 객체로 변환하고자 할 때, 상호 변환이 가능한 코드. static으로 선언해서 사용하고, 제네릭으로 구현되어 있음. Code using System.Collections.Generic; using System.Reflection; public static class ObjectExtensions { public static T ToObject(this IDictionary source) where T : class, new() { var someObject = new T(); var someObjectType = someObject.GetType(); foreach (var item in source) { someObjectType .GetP..

유니티 이벤트(UnityEvent)

인수 없는 유니티이벤트 public UnityEvent FirebaseSignInSucessEvent = new UnityEvent(); 인수 있는 유니티이벤트 Generic 형식의 UnityEvent는 추상클래스이며, 사용하려면 클래스를 재정의해야 한다. 호출 firebaseSignInSucessEvent.Invoke(auth.CurrentUser.Email, auth.CurrentUser.UserId); Delegate, Event (2) - UnityEvent UnityEvent UnityEvent는 C# Delegate를 Unity에서 쓰기 좋게 랩핑해 놓은 기능이다. MonoBehaviour를 상속받는 모든 클래스에서 사용할 수 있고, UnityEvent 변수를 선언하면 인스펙터에 표시되고 영구..

오디오(AudioSource, AudioClip)

[유니티 기초] - Audio 적절한 배경음악이나 효과음만으로도 게임의 분위기가 크게 좌우된다. 유니티는 사운드 미들웨어인 FMO... blog.naver.com 유니티 오디오 리스너(Audio Listener) & 오디오 클립(Audio Clip) 1. 오디오 리스너(Audio Listener) 오디오 리스너는 마이크와 같은 장치로 오디오 소스(Audio Source)로 부터 정보를 받아 사운드를 재생하는 역할을 한다. 프로젝트 생성 시 Main Camera에 추가되어 있으며, notyu.tistory.com

Unity 애니매이션

Animation Clip / Animator Controller ① Animation Clip : 해당 오브젝트가 어떻게 움직이는지 ② Animator Controller : 어떤 Animation Clip들이 언제 실행되어야 하는지 관제하는 스테이트머신 Animation Clip 새로운 애니매이션을 추가하거나 변경하고 싶으면 Anmiation탭의 왼쪽 위를 클릭 Loop Time: 계속 반복할 것인지. Loop pose: 맨 처음과 마지막의 이질감을 줄이기 위해 부드럽게 맞춰주는 것(3D에서 많이 씀) Cycle offset: 시작하는 지점. 0~1의 퍼센트. ex) 0.5=50%=중간에서 시작 특정 조건을 설정하려면 Parameters에서 만든 후 Transition에서 condition을 설정. ..

Pinch Zoom (두손가락, 세손가락)

두손가락이 다른 곳에 쓰여야 해서 불가피하게 세손가락 Pinch zoom이 필요. ① 세 손가락이 만드는 삼각형의 넓이 변화를 이용. ② 외적을 이용하여 삼각형 넓이 구함 (다른 방법을 써도 무관) 세손가락 Pinch Zoom private float GetPinchZoomValue() { float deltaMagnitudeDiff = 0f; // 세손가락, 삼각형의 넓이 변화 이용 if (Input.touchCount == 3) { Touch[] touch = new Touch[3]; touch[0] = Input.GetTouch(0); touch[1] = Input.GetTouch(1); touch[2] = Input.GetTouch(2); Vector2[] touchPrevPos = new Vec..

터치 드래그로 카메라 이동 (한손가락, 두손가락)

아래 코드는 이동의 Diff를 Vector3값으로 반환하는 매소드이다. 이 값을 이용하여 Camera의 Transform을 조정하면 된다. 한손가락 private Vector2 nowPos, prePos; private Vector2 movePosDiff; private Vector2 getTouchDragValue() { movePosDiff = Vector3.zero; if(Input.touchCount == 1) { Touch touch = Input.GetTouch (0); if(touch.phase == TouchPhase.Began) { prePos = touch.position - touch.deltaPosition; } else if(touch.phase == TouchPhase.Moved..

Touch.deltaposition

Touch에서 position, deltaPosition은 둘다 Vector2 position 현재 터치 위치. 디바이스의 왼쪽하단이 (0,0) x,y축 방향은 고등학교 수학의 1사분면과 같음. deltaPosition 전 프레임에서의 터치 위치와 이번 프레임에서 터치위치의 차이 말 그대로 dX, dY Touch.deltaPosition Leave feedback public Vector2 deltaPosition; Description The position delta since last change in pixel coordinates. The absolute position of the touch is recorded periodically and available in the position pr..