ShovelingLife
A Game Programmer
ShovelingLife
전체 방문자
오늘
어제
  • 분류 전체보기 (1072)
    • 그래픽스 (57)
      • 공통 (19)
      • 수학 물리 (22)
      • OpenGL & Vulkan (1)
      • DirectX (14)
    • 게임엔진 (183)
      • Unreal (69)
      • Unity (103)
      • Cocos2D-X (3)
      • 개인 플젝 (8)
    • 코딩테스트 (221)
      • 공통 (7)
      • 프로그래머스 (22)
      • 백준 (162)
      • LeetCode (19)
      • HackerRank (2)
      • 코딩테스트 알고리즘 (8)
    • CS (235)
      • 공통 (21)
      • 네트워크 (44)
      • OS & 하드웨어 (55)
      • 자료구조 & 알고리즘 (98)
      • 디자인패턴 (6)
      • UML (4)
      • 데이터베이스 (7)
    • 프로그래밍 언어 (348)
      • C++ (167)
      • C# (90)
      • Java (9)
      • Python (33)
      • SQL (30)
      • JavaScript (8)
      • React (7)
    • 그 외 (9)
      • Math (5)
      • 일상 (5)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • Source Code 좌측 상단에 복사 버튼 추가 완료
  • 언리얼 엔진 C++ 빌드시간 단축 꿀팁
  • 게임 업계 코딩테스트 관련
  • 1인칭 시점으로 써내려가는 글들

인기 글

태그

  • 오블완
  • string
  • 문자열
  • Unity
  • SQL
  • 알고리즘
  • 유니티
  • 백준
  • 파이썬
  • 함수
  • 언리얼
  • 프로그래머스
  • 그래픽스
  • 티스토리챌린지
  • c#
  • C
  • 클래스
  • C++
  • 배열
  • 포인터

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ShovelingLife

A Game Programmer

[Unreal] C++ 인터페이스 (UInterface)
게임엔진/Unreal

[Unreal] C++ 인터페이스 (UInterface)

2022. 8. 14. 20:49

생성 방법은 우클릭 후 > New C++ Class > Unreal Interface

언리얼에선 모든 오브젝트들은 인스턴스화가 되어야 되기 때문에 인터페이스가 단순한 가상함수 (순수 가상 함수 X)이다.

원형은 아래와 같다. UWeaponInterface는 그대로 놔둔다, 리플렉션 전용이기에 절대로 지워서는 안된다.

아래에 있는 I로 시작되는 IWeaponInterface에 구현부를 넣는다.

 

헤더파일

#pragma once

#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "WeaponInterface.generated.h"

// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UWeaponInterface : public UInterface
{
	GENERATED_BODY()
};

/**
 * 
 */
class PUBG_UE4_API IWeaponInterface
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
	// 클릭 이벤트
	virtual void ClickEvent();
};

cpp파일에서도 마찬가지로 선언을 해준다.

// Fill out your copyright notice in the Description page of Project Settings.


#include "WeaponInterface.h"

// Add default functionality here for any IWeaponInterface functions that are not pure virtual.

void IWeaponInterface::ClickEvent()
{
}

이제 헤더파일을 #include 해서 상속받기만 하면된다.

UCLASS()
class PUBG_UE4_API ABaseInteraction : public AActor, public IWeaponInterface
{
	GENERATED_BODY()
    
 public:
 	virtual void ClickEvent() override { };
};

크게 총기 무기 ACoreWeapon, 근접 무기  ACoreMeleeWeapon 그리고 투척류 무기 ACoreThrowableWeapon에 해당 ABaseInteraction 클래스를 상속 받을 것이다, 따라서 아래와 같이 붙여줄거다.

virtual void ClickEvent() final;

저작자표시 (새창열림)

'게임엔진 > Unreal' 카테고리의 다른 글

[Unreal] 클래스 생성시 FObjectInitializer 사용법 (기본 컴포넌트 변경)  (0) 2022.08.17
[Unreal] 캐릭터 이동 관련 컴포넌트 (UCharacter / UPawn MovementComponent*)  (0) 2022.08.15
[Unreal] csv 파일 불러온 후 읽어들이기  (0) 2022.08.05
[Unreal] 자료구조 순회 방법  (0) 2022.08.04
[Unreal] FTimerManager 타이머 설정  (0) 2022.08.02
    '게임엔진/Unreal' 카테고리의 다른 글
    • [Unreal] 클래스 생성시 FObjectInitializer 사용법 (기본 컴포넌트 변경)
    • [Unreal] 캐릭터 이동 관련 컴포넌트 (UCharacter / UPawn MovementComponent*)
    • [Unreal] csv 파일 불러온 후 읽어들이기
    • [Unreal] 자료구조 순회 방법
    ShovelingLife
    ShovelingLife
    Main skill stack => Unity C# / Unreal C++ Studying Front / BackEnd, Java Python

    티스토리툴바