게임엔진

[Unity] Job 시스템 정의
단일 작업 인터페이스 IJob Job 시스템이 사용하는 자료구조 NativeContainer Job 대기 핸들 (Handle) 동시에 여러개의 작업 IJobParallelFor 원리 멀티 스레딩 방식의 프로그래밍 기법이지만, 스레드를 별도로 생성하지 않는다. 유니티 내부에는 우리가 익숙하게 작업을 진행하는 메인 스레드와, CPU 코어 개수에 맞춰 월드의 변경사항을 적용하여 렌더링 할 준비를 해주는 작업자 스레드, 렌더링 과정을 처리하는 렌더 스레드가 존재한다. 이 중, 작업자 스레드에 작업을 지시할 수 있게끔 해준다. 장점과 단점 장점 빠르다. 메모리 절약된다. 유니티에서 제공하는 각종 스레드 안전장치를 사용할 수 있다. 유니티의 로직에 맞춰 돌아가므로 비교적 안정적인 프레임을 기대할 수 있다. 유니티가..
[Unity] Job 시스템 이해 4, IJobParallelFor
▶ IJob이 단일 작업자 스레드에서 Execute()가 한번 처리되었다면, IJobParallerFor는 사용 가능한 모든 작업자 스레드에서 Execute()가 실행 횟수 만큼 나뉘어서 실행된다. ▶ IJobParallelFor는 Execute()의 로직은 동일하지만 특정 Index의 매개 변수가 다를 때 사용하면 유용하다. 같은 로직을 여러번 수행할 때 묶음으로 처리함으로써 성능 향상의 도움이 된다. [JobProducerType( typeof( IJobParallelForExtensions.ParallelForJobStruct ) )] public interface IJobParallelFor { // // 요약: // Implement this method to perform work agains..

[Unity] Job 시스템 이해 3, JobHandle
▶ JobHandle은 Job의 Schedule을 실행했을 때 반환되는 값으로, Job을 컨트롤 할 수 있는 기능을 가진다. ▶ Job은 독립적으로 실행될 수도 있지만, 특정한 Job의 경우 선행 Job의 실행이 끝난 뒤에 해당 결과를 바탕으로 자신의 Job을 실행 시켜야하는 경우가 있을 수 있다. 이때 JobHandle을 사용하여 Job의 종속성을 설정할 수 있다. using UnityEngine; using Unity.Jobs; using Unity.Collections; public class JobSample : MonoBehaviour { struct JobSigle : IJob { public int a; public int b; public NativeArray result; public v..

[Unity] SQL 데이터 베이스 연동 SQLite
1. Sqlite dll 다운로드 (1) 다운로드 사이트 : https://www.sqlite.org/download.html (2) Precompiled Binaries for Windows > sqlite-dll-win64-x64-xxxxxxx.zip 파일 다운로드 (3) Project(프로젝트) Assets 폴더 밑에 Plugins를 만든 뒤, sqlite3.def, sqlite3.dll 파일을 넣는다. 3. Mono.Data.xxx.dll 파일 복사. C:\Program Files\Unity\Hub\Editor\2019.x.xxf1\Editor\Data\Mono\lib\mono\2.0에서 Mono.Data.dll, Mono.Data.Sqlite.dll, Mono.Data.SqliteClient.d..
[Unity] 에디터에서만 사용할 수 있는 커스텀 코루틴
모든 코루틴은 이로부터 접근을 해서 호출한다. 예) EditorCoroutines.EditorCoroutines.StartCoroutine(코루틴 명칭, this); EditorCoroutines.EditorCoroutines.StopCoroutine(코루틴 명칭, this); using EditorCoroutine = EditorCoroutines.EditorCoroutines; 맨 위에 추가시 아래와 같이 생략 가능 EditorCoroutine.StartCoroutine(코루틴 명칭, this); EditorCoroutine.StopCoroutine(코루틴 명칭, this); using UnityEngine; using System.Collections; using UnityEditor; using ..
[Unity] Range 어트리뷰트를 단위로 설정할 수 있는 방법
아래는 어트리뷰트를 그려줄 클래스 using UnityEngine; using UnityEditor; using System; [CustomPropertyDrawer(typeof(RangeExAttribute))] internal sealed class RangeExDrawer : PropertyDrawer { private int value; /** * Return exact precision of reel decimal * ex : * 0.01 = 2 digits * 0.02001 = 5 digits * 0.02000 = 2 digits */ private int Precision(float value) { int _precision; if (value == .0f) return 0; _precisi..

[Unity] 화면 위치 > 월드 좌표 치환 RectTransformUtility
public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint); ScreenPoint(스크린좌표)를 RectTransform의 LocalPoint(캔버스좌표)로 변환합니다. Camera의 매개 변수는 ScreenPoint(스크린 좌표)와 연관된 카메라이어야 한다. 캔버스에서 RectTransform이 Screen Space-Overlay 모드로 설정된 경우 cam 매개 변수는 null 이어야 한다. (그래서 EnemyHpBar 구현할 때 없어도 됐던 것이었다.) rect screenPoint를 출력할 Canvas의 RectTransfo..

[Unity] UI 카메라 설정하기 (screen space - camera)
메인 카메라(main camera)의 culling mask에서 UI를 체크해제하고 depth 속성의 값을 0으로 설정하였다. 씬에 새로운 카메라를 추가한다. 카메라의 clear flags에서 depth only를 선택하고 culling mask에서 UI 레이어를 제외하고 체크해제한다. 캔버스와 하위 ui 요소의 레이어를 설정한다(UI) render mode에서 screen space- camera를 선택하고 render camera에 씬에 추가한 카메라를 참조시킨다. 메인 카메라에서 씬의 게임 오브젝트와 스카이박스를 표시하고 두번째 카메라의 UI는 항상 위에 표시된다. 출처 : 유니티에서 UI 카메라 설정하기(screen sapce - camera) (tistory.com)

[Unity] Job 시스템 이해 2, NativeContainer
● NativeContainer ▶ Unity에 Job 시스템은 멀티 스레드 사용 편하게 만들었지만, 일반적으로 Job의 데이터가 메인 스레드에서 접근할 수 없는 메모리에 만들어진다는 단점이 있다. ▶ 메인 스레드에서 Job의 데이터에 접근하기 위해서는 NativeContainer라는 특수한 공유 메모리 타입을 사용해야만 한다. ● NativeContainer Type ▶ NativeArray : Unity에 내장된 기본적인 Job 시스템에서 사용하는 NativeContainer Type으로 Array와 유사하다. ※ 하단의 NativeContainer Type은 ECS에서 제공하는 NativeContainer Type으로 Package Manager를 통해 Collections을 Import해야지만 사..

[Unity] Job 시스템 이해 1, IJob
Unity의 Job 시스템을 이용하기 위해서는 using Unity.Jobs 를 사용해야 한다. 해당 게시글에서는 Unity.Jobs의 코드 확인 및 샘플 프로젝트를 만들어 봄으로써 Job 시스템을 이해하고자 한다. [ Unity.Jobs 의 계층 구조 ] ● Interface IJob ▶ 단일 작업을 하는 Job을 구현 할 때, struct에 상속하는 interface [JobProducerType( typeof( IJobExtensions.JobStruct ) )] public interface IJob { // // 요약: // Implement this method to perform work on a worker thread. void Execute(); } Execute() 함수에 Job에서 ..