Unity 240

RectTransform의 width, height 알아내기

한쪽방향만 Stratch하고, 일정비율을 유지하고 싶을 때 가로에 9/16을 곱해주면 되는데, 가로 값이 제대로 나오지 않음 mScreen.rectTransform.sizeDelta = new Vector2(0, mScreen.rectTransform.rect.width *9/16); Solution RectTransform.rect.width 로 구하는건 맞는데, Start()에서 하면 안되고, 코루틴을 쓰던, Update에서 하던 조금 있다가 해야 한다. 그리는데 시간이 걸림. Get size of stretched RectTransform When working with Unity UI system, sometimes it is useful to know what the size of a given..

영상(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 Callback에서 SetActive 안됨

Problem Firestore의 콜백에서 GameObject의 SetActive()를 하면 먹통이 된다. 여기서 호출한 함수들도 마찬가지. DocumentReference docRef = db.Collection("cities").Document("LA"); docRef.GetSnapshotAsync().ContinueWith((task) => { var snapshot = task.Result; panel.SetActive(true); }); Solution DocumentReference docRef = db.Collection("cities").Document("LA"); docRef.GetSnapshotAsync().ContinueWithOnMainThread((task) => { var sna..

Unity/Unity 이슈 2021.07.11

Timestamp

Timestamp 등록 날짜는 필수, 시간은 입력안하면 0:00 Timestamp 등록 DocumentReference cityRef = db.Collection("cities").Document("new-city-id"); cityRef.UpdateAsync("Timestamp", FieldValue.ServerTimestamp) .ContinueWithOnMainThread(task => { Debug.Log( "Updated the Timestamp field of the new-city-id document in the cities " + "collection."); }); 서버시간을 바로 Timestamp에 대입함. 근데 이건 Update할때이고.. Timestamp??? 시발? 자바는 이렇게 ..

Unity/Firestore 2021.07.10

[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 변수를 선언하면 인스펙터에 표시되고 영구..

[RTS Engine] 초기 카메라의 위치

[추가] 아래 내용들의 근본적인 원인은 CameraController에서 MainCamera의 Transiton을 제한하고 있기 때문 [SerializeField, Header("General"), Tooltip("The main camera in the scene.")] private Camera mainCamera = null; //the main RTS camera public void Init(GameManager gameMgr) { // ... } private void Update() { UpdatePanInput(); UpdateRotationInput(); UpdateZoomInput(); lastMousePosition = Input.mousePosition; } private void ..

Unity/Asset 분석 2021.07.06

오디오(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을 설정. ..