게임 엔진

게임 엔진/Unreal

[Unreal] Interface 이용 방법

언리얼 Interface 이용 방법 Unreal engine에서도 interface를 사용할 수 있다. 먼저 기본적인 C++ 인터페이스에 대해 이해하기 위해 다음 글을 참고하면 좋다. https://algorfati.tistory.com/205 [C++] C++에서 Interface 구현 방법 인터페이스란? Java나 C#과 같은 언어들을 보면 Interface라는 강력한 개념이 존재한다. 인터페이스는 객체에 대한 명세서만 나타내고 구체적인 구현은 각 파생 객체에서 작업하도록 한다. 명세서에 algorfati.tistory.com Interface를 TSharedPtr의 형태로 이용하는 예제를 만들어보자. class IInterfaceA { public: virtual ~IInterfaceA() {} v..

게임 엔진/Unreal

[Unreal] [Example] Animation에서 Physics Velocity 계산

Animation 데이터의 delta transform을 계산하여 각 body에 대한 물리 선형속도, 각속도를 만들어보는 예제이다. TestUtils.h // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" class UWorld; class USkinnedMeshComponent; class USkeletalMeshComponent; class PHYSICSANIMATIONCPP_API TestUtils { public: TestUtils(); ~TestUtils(); public: static const TArray BoneNames; static..

게임 엔진/Unreal

[Unreal] [Example] Transform

언리얼 Transform 관련 예제이다 // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "TestActor.generated.h" UCLASS() class PHYSICSANIMATIONCPP_API ATestActor : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties ATestActor(); protected: // Called when the game ..

게임 엔진/Unity

[Unity] [Example] 평면 연산 방법 (Plane)

Plane 유니티 Plane 예제이다. GameObject의 위치를 기준으로 4방에 평면 4개를 배치하고, 8방향으로 각 평면에 Raycast를 하여 거리를 재는 예제이다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class SnakeAgent : MonoBehaviour { private static readonly Vector3Int Forward = new Vector3Int(0, 0, 1); private static readonly Vector3Int Back = new Vector3Int(0, 0, -1); private static readonly Vector3Int Left = ..

게임 엔진/Unity

[Unity] [Example] Mesh

Mesh Unity Mesh 관련 예제이다. MeshDataPrinter.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeshDataPrinter : MonoBehaviour { [SerializeField] private MeshFilter _targetMesh; // Start is called before the first frame update void Start() { PrintMeshData(_targetMesh.mesh); } public static void PrintMeshData(Mesh mesh) { Debug.Log("vertices"); foreach (va..

게임 엔진/Unity

[Unity] [Example] Singleton

Singleton 모든 영역에서 접근가능한 데이터를 만들어야하는 상황이 생길 수 있다. 예를 들면, 에셋을 미리 로드해서 관리하는 에셋 관리자 객체나, 데이터 테이블을 미리 생성해놓는 데이터 테이블 관리자 객체와 같은 것들이 이에 해당된다. 이처럼 어떤 위치에서도 참조가 가능하도록 해당 객체 설계하는 방법을 싱글턴 디자인 패턴이라 부른다. 하지만 유니티에서는 객체가 GameObject를 갖고 있는 경우도 있기 때문에, 싱글턴 객체를 만들기 위해서 일반적인 방법보다는 조금 더 신경써야할 부분들이 있다. Singleton.cs 다음과 같이 Singleton 객체를 만든다. using System.Collections; using System.Collections.Generic; using UnityEngin..

게임 엔진/Unity

[Unity] Hp Bar 만들기

Hp Bar 유니티 Hp Bar 제작 방법이다. https://www.youtube.com/watch?v=BLfNP4Sc_iA&t=1118s HpBar.cs using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HpBar : MonoBehaviour { [SerializeField] private Slider _slider; public void SetValue(float value) { _slider.value = value; } } BillBoard.cs using System.Collections; using System.Collections.Gene..

게임 엔진/Unity

[Unity] 글로벌 이벤트 관리 방법

글로벌 이벤트 관리 방법 이벤트를 관리하는 시스템을 하나 만듦으로서 굉장히 편하게 게임 개발을 진행할 수 있다. 게임오브젝트간의 상호작용이 필요한 상황에서는 필연적으로 종속성이 생길 수 밖에 없다. 하지만 이 종속성을 Event Manager라는 하나의 오브젝트로 모으도록 할 수 있다. 내 캐릭터가 어떤 영역에 들어갔을 때, 문이 열리는 상황을 가정해 보자. 문이 열리는 행동을 어떤 영역이 이벤트를 발생시켜서 수행해야 하는데, 객체 간 서로 상호참조를 통해 코드를 구현하면 코드가 너무 지저분해진다. 그러므로 먼저 EventManager 클래스를 생성하자. EventManager.cs EventManager는 게임 내 모든 오브젝트 간 상호작용 이벤트를 다루는 클래스이다. 싱글턴 클래스로 설계하여 어떤 오..

게임 엔진/Unity

[Unity] 전략게임 카메라 제작 방법

Strategy Camera Unity에서 전략 시뮬레이션을 위한 카메라를 제작해야하는 경우가 있다. 먼저 Camera Rig로 사용할 GameObject를 하나 생성하고, 그 하위에 MainCamera를 놓는다. 그 후 MainCamera의 값을 다음과 같이 설정한다. StrategyCameraController.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class StrategyCameraController : MonoBehaviour { public Transform followTransform; public Transform cameraTransform; public float no..

게임 엔진/Unity

[Unity] 동적타임에 NavMesh 생성하기

동적타임에 NavMesh 생성하기 NavMesh를 런타임에 생성해야 하는 상황이 생길 수 있다. 맵 자체를 제작하는 크래프트류의 게임들은 게임 중에 갑자기 새로운 맵이 생성될 수 있고, 그에 따라 NavMesh로 새로 생성되어야 할 수 있다. Unity 엔진 내부에서 이런 상황을 위해 제공해주는 기능은 없지만, 유니티에서 오픈소스로 제공해주는 코드가 있다. https://github.com/Unity-Technologies/NavMeshComponents Unity-Technologies/NavMeshComponents High Level API Components for Runtime NavMesh Building - Unity-Technologies/NavMeshComponents github.com..

게임 엔진/Unity

[Unity] 커스텀 에디터 제작 방법 (Editor Customize)

Editor Customize 유니티에서 에디터를 커스터마이징 하는 방법이다. 에디터 커스터마이징은 개발자로 하여금 유니티 에디터 자체에 특정 기능을 추가하는 방법이다. 예를 들면 인스펙터의 스크립트에 어떤 버튼을 누르면 자동으로 에셋들을 로드해준다거나, 자동으로 맵을 생성해준다거나 등등 잘 활용한다면 개발하는데 굉장한 편의성을 갖출 수 있다. (이전에 근무하던 팀에서는 따로 에디터만 작업하는 개발자들도 있었다.) 유니티 에디터 커스터마이징을 하기에 앞서 몇가지 알아두어야 하는 개념들이 있다. 먼저 유니티의 에디터 코드가 동작하는 레벨에 대해 알아두어야 한다. 우리가 일반적으로 이용하는 C# 스크립트들은 모든 레벨에서 이용된다. 즉 에디터에서도 동작하고, 빌드된 디바이스에서도 동작한다. 하지만 에디터 코..

게임 엔진/Unity

[Unity] 길찾기 시스템을 통한 이동과 애니메이션 컨트롤러

Pathfinder with Animation Movement 기본적으로 Unity에서는 NavMeshAgent를 지원한다. 이 컴포넌트를 이용한다면 굉장히 쉽게 길찾기(Pathfinding)가 가능한 오브젝트를 제작할 수 있다. 하지만, NavMeshAgent의 SetDestination함수를 이용하면 타겟 위치를 주었을 때 해당 위치까지 이동시키는 기능을 쉽게 구현할 수 있다. 하지만 이 함수는 GameObject의 Transform을 엔진 코드 내에서 직접 수정하도록 설계되어 있고, 이동 관련 로직이 숨겨져 있어서 커스텀 이동을 사용하는 경우 문제가 생길 수 있다. 예를 들면 애니메이션 자체에 루트 모션이 포함되어 있는 경우 루트 모션을 활용하여 길찾기 로직을 구현하고 싶을 수 있겠지만 (보폭에 맞..

게임 엔진/Unreal

[Unreal] [Editor] Slate를 이용한 커스텀 에디터 List View 제작

Slate List View Slate ListView 예제이다. 다음과 같은 ui를 제작 할 수 있다. SMyListViewWidget.h #pragma once #include "CoreMinimal.h" #include "SlateFwd.h" #include "SlateBasics.h" #include "Widgets/DeclarativeSyntaxSupport.h" #include "Input/Reply.h" #include "Widgets/SWidget.h" #include "Widgets/SCompoundWidget.h" #include "Widgets/Views/STableViewBase.h" #include "Widgets/Views/STableRow.h" #include "Widgets/..

게임 엔진/Unreal

[Unreal] [Editor] 프로퍼티 에디터 제작 방법

Detail Editor Customization 언리얼 커스텀 에디터를 제작함에 있어서 가장 중요한 부분인 custom property editor를 제작하는 내용이다. Property editor란 다음과 같이 사용자가 정의한 어떤 데이터의 프로퍼티를 언리얼 ui상에 표시하고, 또 수정할 수 있도록 해주는 editor이다. Modules 다음 모듈들을 미리 추가해두자. PrivateDependencyModuleNames.AddRange( new string[] { "Projects", "InputCore", "UnrealEd", "LevelEditor", "CoreUObject", "Engine", "Slate", "SlateCore", "EditorScriptingUtilities", "Editor..

게임 엔진/Unreal

[Unreal] [Example] 객체 직렬화 방법

Serialization (Memory Archive) 언리얼에서 제공하는 기본적인 메모리 직렬화 객체 FMemoryArchive를 활용한 예제이다. 언리얼에서는 메모리 읽기, 쓰기 기능을 지원하기 위해 FMemoryArchive를 상속하여 FMemoryReader, FMemoryWriter 형태로 제공한다. #include "Serialization/MemoryWriter.h" #include "Serialization/MemoryReader.h" void SerializationExamples::BaseExample() { UE_LOG(LogTemp, Log, TEXT("BaseExample Begin")); // write data to memory TArray BufferArray; FMemory..

게임 엔진/Unreal

[Unreal] [Editor] Slate를 이용한 에셋 경로 설정 다이얼로그 제작

Asset Path Pick Dialog 예제 다음 코드로 에셋의 경로를 가져오는 다이얼로그를 띄울 수 있다. if문 내부에서 다이얼로그가 닫히고, 가져온 경로를 사용할 수 있다. FString NewNameSuggestion = FString(TEXT("Suggestion")); FString PackageNameSuggestion = FString(TEXT("/Game/")) + NewNameSuggestion; FString Name; TSharedPtr PickAssetPathWidget = SNew(SDlgPickAssetPath) .Title(LOCTEXT("MyTitleName", "Choose Your Location")) .DefaultAssetPath(FText::FromString(P..

게임 엔진/Unreal

[Unreal] [Editor] [Example] Slate 예제 1

Custom Slate Class 만들기 Slate를 이용한 커스텀 클래스 ui 제작 예제이다. 참고 영상 https://www.youtube.com/watch?v=jeK6DPB5weA MyPlugin.Build.cs ... PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); ... SMainMenuWidget.h // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "SlateBasics.h" #include "SlateExtras.h" class MENU_API SMainMenuWidget..

게임 엔진/Unreal

[Unreal] [Editor] [Example] Slate 예제 2

Slate Samples Unreal editor ui framework인 slate에 대한 예제이다. SButton #include "Widgets/Input/SButton.h" TSharedPtr FMyPluginModule::Create() { return SNew(SButton) .Text(WidgetText) .OnClicked(FOnClicked::CreateRaw(this, &FMyPluginModule::OnClickButton)); } FReply FMyPluginModule::OnClickButton() { UE_LOG(LogTemp, Warning, TEXT("OnClickButton")); return FReply::Handled(); } SAssetSearchBox // "Edit..

게임 엔진/Unreal

[Unreal] [Editor] Unreal Plugin 제작 방법

Plugin Start Unreal plugin 시작방법 예제이다. 1. 메뉴바 -> 편집 -> 플러그인 2. 오른쪽 하단 새 플러그인 클릭 3. 에디터 툴바를 사용하는 "에디터 툴바 버튼"으로 플러그인 생성 (MyPlugin) 4. 프로젝트 재시작 시 에디터 툴바에 MyPlugin을 확인할 수 있음 5. 플러그인 소스는 visual studio 프로젝트에서 수정할 수 있음 모듈 기본 코드 Header #pragma once #include "CoreMinimal.h" #include "Modules/ModuleManager.h" class FToolBarBuilder; class FMenuBuilder; class FMyPluginModule : public IModuleInterface { publi..

게임 엔진/Unreal

[Unreal] Animation Notify를 이용한 충돌처리 (AnimNotify, Collision)

Collision by Animation Notify 애니메이션 notify를 통해 캐릭터 객체의 공격 궤적에 따른 충돌처리 예제이다. Header // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "MyCharacter.generated.h" class UStaticMeshComponent; UCLASS() class ANIMATIONRETARGET_API AMyCharacter : public ACharacter { GENERATED_BODY() public: /..

게임 엔진/Unreal

[Unreal] Physics Body의 기하 정보를 이용한 충돌처리

Physics Collision with AggregateGeom Shapes 캐릭터가 공격할때 오른손 캡슐에 의한 충돌판정을 위한 예제이다. Physics Asset 먼저 충돌판정에 사용할 BodyInstance이다. 이후 코드를 통해 이 BodyInstance의 궤적에 따른 충돌을 판정할 것이다. Header #pragma once #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "MyCharacter.generated.h" class UStaticMeshComponent; UCLASS() class ANIMATIONRETARGET_API AMyCharacter : public ACharacter { GENERATED_BO..

게임 엔진/Unreal

[Unreal] [Example] 콘솔 커맨드 제작 방법 (Console Command)

Console Command Unreal 콘솔 커맨드 관련 예제이다. Source #include "HAL/IConsoleManager.h" ... // call this from start - ex) gamemode being void Utility::InitConsoleCommand() { FConsoleCommandWithArgsDelegate Delegate; Delegate.BindStatic(&Utility::ConsoleCommand); IConsoleManager::Get().RegisterConsoleCommand( TEXT("insooneelifeCmd"), TEXT("insooneelife test cmd"), Delegate); } // this is static function v..

게임 엔진/Unreal

[Unreal] 디버깅용 드로워 이용 방법 (Draw Debug)

Debug Draw Unreal engine 개발 과정에서 화면상에 원하는 도형을 그려서, 디버깅을 수월하게 도와주는 함수들에 대한 예제이다. Draw Debug #include "DrawDebugHelpers.h" ... void Examples::DebugDrawExample(UWorld* World) { FVector StartOffset = FVector(0, 0, 200); FVector LocationOne = FVector(0, 0, 600) + StartOffset; FVector LocationTwo = FVector(0, -600, 600) + StartOffset; FVector LocationThree = FVector(0, 600, 600) + StartOffset; FVector..

게임 엔진/Unreal

[Unreal] 코드 단위 프로파일링 (Profile)

Profile In Code 언리얼 개발 과정중 소스코드 단위로 프로일링이 필요한 상황이 올 수 있다. 이를 대비하여 언리얼 엔진에서 지원해주는 기능이 있다. 프로파일링을 위한 그룹 선언 먼저 프로파일링 그룹을 선언한다. DECLARE_STATS_GROUP(TEXT("Sample"), STATGROUP_Sample, STATCAT_Advanced); 프로파일링 영역 설정을 위한 개체 선언 코드 영역에 적용하기 전에 영역 개체를 정의한다. DECLARE_CYCLE_STAT(TEXT("Agent [Tick]"), STAT_AgentTick, STATGROUP_Sample); 프로파일링 대상 영역에 적용 이제 프로파일링 대상 영역에 적용한다. void ACharacterAgent::Tick(float Delt..

AlgorFati
'게임 엔진' 카테고리의 글 목록 (2 Page)