분류 전체보기

게임 엔진/Unreal

[Unreal] [Example] 인공지능 에이전트 (AISense)

인공지능을 제작할 때, 인공지능의 인지능력을 개발해야하는 상황이 생긴다. 인지능력의 예로는, 주변 객체들을 시각적으로 인지함, 주변 객체의 소리를 인지함, 주변 객체로부터의 공격을 인지함, 등의 상황을 생각해볼 수 있다. AISense를 사용하기 위해서는 필요한 객체들은 다음과 같다. 1. 인공지능이 들어간 객체 (Pawn) 2. 인지능력을 통해 Pawn을 조종할 객체 (AIController) 3. 인지능력들을 관리할 객체 (AIPerception) 4. 추가될 인지능력들 (AISense_Sight, AISense_Damage) Pawn (AAICharacter.cpp) // 공격을 받으면 이 함수를 호출해준다. // ex) Player가 인공지능을 공격 시, Player의 함수에서 이 함수를 호출 b..

게임 엔진/Unreal

[Unreal] 테이블 데이터 이용 방법 (DataTable)

Data Table 대량의 데이터를 table 형태로 관리해야하는 상황도 생길 수 있다. 이런 경우 unreal engine의 data table을 사용하면 유용하다. 소스코드 #include "Engine/DataTable.h" USTRUCT() struct FPhysicsPoseData : public FTableRowBase { GENERATED_USTRUCT_BODY() UPROPERTY(EditAnywhere) float x; UPROPERTY(EditAnywhere) float y; UPROPERTY(EditAnywhere) float z; UPROPERTY(EditAnywhere) float quatX; UPROPERTY(EditAnywhere) float quatY; UPROPERTY(Ed..

게임 엔진/Unreal

[Unreal] [Example] Delegate 사용방법

Delegate언리얼 엔진에서도 delegate을 이용할 수 있다. 먼저 delegate의 시그니쳐를 정의하여한다. 시그니쳐는 언리얼에서 제공하는 메크로를 통해 정의할 수 있는데, 싱글 delegate와 멀티 delegate가 있다. 싱글 delegate에는 함수를 한 개만 bind 가능하지만, 멀티 delegate에는 여러개의 함수를 bind 할 수 있다. 그리고 메크로에 몇개의 파라메터를 넣을 것인지까지 메크로 이름으로 구분되어 있다. 일반 delegate와 달리 다이나믹 delegate가 있는데 이는 블루프린트에서도 이용이 가능한 delegate이다.// 싱글 일반 delegate, 파라메터 x DECLARE_DELEGATE(FDelegateSingleSignature); // 싱글 일반 deleg..

게임 엔진/Unreal

[Unreal] [Example] 타이머 이용 방법 (Timer)

익명 타이머 { FTimerHandle UnusedHandle; float Duration = 0.1f; bool bLoop = false; GetWorldTimerManager().SetTimer( UnusedHandle, this, &ClassName::FunctionName, Duration, bLoop); } 람다를 이용한 등록 { FTimerHandle TimerHandle; FTimerDelegate TimerCallback; TimerCallback.BindLambda( [this, FaceId] { // .. }); World->GetTimerManager().SetTimer(TimerHandle, TimerCallback, 1.0f, false); } 타이머 등록/제거 FTimerHand..

Tool

[Tool] Git 기본 예제

Git 기본 기능 git config git config는 git의 글로벌 설정값들을 조회, 변경할 수 있는 명령어이다. 현재 git config에 등록되어있는 값 모두 조회 (git 사용자 계정도 이 명령어로 확인 가능) git config --global --list git 사용자 계정 변경 git config --global user.name "username" git config --global user.email "mailname@example.com" git clone 원격 레포지토리에 있는 코드를 로컬에 받을 수 있다. git clone https://github.com/username/projectname.git git add 루트 디렉터리(.git파일이 있는 디렉터리) 내부에서 수정된 추..

게임 엔진/Unreal

[Unreal] [Example] C++에서 Blueprint 호출, Blueprint에서 C++ 호출

1. C++에서 Blueprint 함수를 호출하는 방법 UFUNCTION(BlueprintImplementableEvent, Category = "Blueprint") void K2_CreatePickupWidget(AActor* InOwner, TSubclassOf WidgetClass, APickupActor* PickupActor); void CreatePickupWidget(AActor* InOwner, TSubclassOf WidgetClass, APickupActor* PickupActor) { K2_CreatePickupWidget(InOwner, WidgetClass, PickupActor); } 이후 구체적인 구현은 상속된 blueprint 에서 마무리 지어준다. 호출은 c++에서 가능하..

Tool

[Tool] Visual Studio 기능 정리

기타 기능 현재 로드된 dll 파일 리스트를 visual studio에서 보는 방법 디버그 모드로 실행 후 디버그 -> 창 -> 모듈 Visual Studio에서 작업 디렉토리를 변경하는 방법 Open Project > Properties > Configuration Properties > Debugging. 작업 디렉토리는 기본적으로 $(ProjectDir) 로 세팅되어있다. 이 위치를 원하는 디렉토리로 바꿀 수 있다. 실행 파일이 있는 위치와 동일한 디렉토리를 원하는 경우 $(SolutionDir)$(Configuration)\ 로 바꾸면 된다. 빌드 후 이벤트 생성 방법 Open Project > Properties > Configuration Properties > Build Events > Po..

게임 엔진/Unreal

[Unreal] 인공지능 에이전트 개발 방법 (AIController, BehaviorTree, Blackboard, Decorator, Service, Task)

AIController 먼저 AIController를 만든다. AIController는 언리얼 인공지능을 위한 가장 핵심적인 개념이다. Pawn에 의해 소유될 수 있고, 자체적인 로직이나 behavior tree를 이용한 로직을 통해 인공지능을 표현할 수 있다. 그리고 모든 AIController는 server에서만 존재할 수 있다. ShooterAIController.h // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "AIController.h" #include "PhysicsNNAnimationComponent.h" #inc..

게임 엔진/Unreal

[Unreal] 프로퍼티 관련 예제

언리얼 구조체를 Property로 사용하는 방법 USTRUCT(Blueprintable) struct FTestStructData { GENERATED_USTRUCT_BODY() UPROPERTY(EditAnywhere) float x; UPROPERTY(EditAnywhere) float y; UPROPERTY(EditAnywhere) float z; UPROPERTY(EditAnywhere) float quatX; UPROPERTY(EditAnywhere) float quatY; UPROPERTY(EditAnywhere) float quatZ; UPROPERTY(EditAnywhere) float quatW; }; class PHYSICSANIMATION_API TestCharacter : publi..

게임 엔진/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..

AlgorFati
'분류 전체보기' 카테고리의 글 목록 (4 Page)