Unreal C++/C++ Actor2018. 8. 21. 18:57

C++ 클래스를 이용하여 액터를 생성하고 Z 위치를 변경하는 예

https://www.youtube.com/watch?v=K8iSi1oGaBI


C++ 프로젝트 생성

C++ 클래스 생성(Actor 클래스 기반, 클래스이름: CubeActor 등으로 지정)

Content Browser 안에 C++ 클래스가 보이지 않으면 우측 하단의 [뷰옵션] > [C++ 클래스 표시] 선택

VS에 CubeActor.h, CubeActor.cpp 파일이 생성된다


CubeActor.cpp의 Tick 함수에 아래의 적색부분 같이 작성하여 게임 시작시에 큐브가 상승하도록 한다

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


#include "CubeActor.h"



// Sets default values

ACubeActor::ACubeActor()

{

  // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.

PrimaryActorTick.bCanEverTick = true;

}


// Called when the game starts or when spawned

void ACubeActor::BeginPlay()

{

Super::BeginPlay();

}


// Called every frame

void ACubeActor::Tick(float DeltaTime)

{

Super::Tick(DeltaTime);

FVector NewLoc = GetActorLocation();

NewLoc.Z += 5;

SetActorLocation(NewLoc);

}


위와 같이 cpp 파일을 편집하여 VS에서 저장하고 UE4의 툴바에서 [컴파일] 버튼을 누른다

컴파일이 완료되면 컨텐츠 브라우저에서 CubeActor를 드래그하여 뷰포트에 올릴 수 있지만 아무런 형제가 없기에 뷰포트에서 선택할 수도 없는 상태가 된다

이와같이 C++ 액터클래스 드래그하여 뷰포트에서 보여지고 또 마우스로 선택이 가능하도록 하려면 가시적인 컴포넌트 한개는 있어야 한다.


C++액터 클래스에 컴포넌트를 포함시키고자 한다면 다음과 같은 코드를 h, cpp 파일에 추가한다(적색부분 참조)

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


#pragma once


#include "CoreMinimal.h"

#include "GameFramework/Actor.h"

#include "CubeActor.generated.h"


UCLASS()

class CPP_CUBE_API ACubeActor : public AActor

{

GENERATED_BODY()

public:

// Sets default values for this actor's properties

ACubeActor();


protected:

// Called when the game starts or when spawned

virtual void BeginPlay() override;


public:

// Called every frame

virtual void Tick(float DeltaTime) override;


UPROPERTY(EditAnywhere)

UStaticMeshComponent* Mesh;

};



cpp 코드에 다음과 같이 액터에 컴포넌트를 등록하는 부분을 작성한다

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


#include "CubeActor.h"



// Sets default values

ACubeActor::ACubeActor()

{

  // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.

PrimaryActorTick.bCanEverTick = true;

Mesh = CreateDefaultSubobject<UStaticMeshComponent>("MyMesh");

}


// Called when the game starts or when spawned

void ACubeActor::BeginPlay()

{

Super::BeginPlay();

}


// Called every frame

void ACubeActor::Tick(float DeltaTime)

{

Super::Tick(DeltaTime);

FVector NewLoc = GetActorLocation();

NewLoc.Z += 5;

SetActorLocation(NewLoc);

}




위와같이 작성이 되었으면 VS에서 저장하고 UE4에서 [컴파일] 버튼을 누르고 컴파일을 완료한다

이제 컨텐츠 브라우저에서 CubeActor 를 드래그하여 뷰포트에 올리면 뷰포트에 형체는 없지만 방향표시 기즈모가 나타나기 때문에 [디테일] 뷰에서 Mesh 변수에 구체적인 스테틱 메시를 지정해 줄 수 있게 된다




Posted by cwisky

언리얼 엔진에서 C++ 클래스는 Blueprint 클래스 안에서 변수로 선언될 수도 있고 블루프르린트 클래스의 부모 클래스가 될 수 있다. 

아래처럼 UCLASS 매크로를 선언해주면 된다


UCLASS (BlueprintType)     // BP안에 선언되는 변수의 자료형(Type)이 될 수 있도록 선언

UCLASS Blueprintable)      // BP 클래스를 생성할 때 부모 클래스가 될 수 있도록 선언

UCLASS(Blueprintable, BlueprintType)


#include "Object.h"


#include "PlayerClass.generated.h"


UCLASS(BlueprintType)


class PROTOTYPE2_API UPlayerClass : public UObject

{

   GENERATED_BODY()


public:


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Variables")

FString playerName;


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Variables")

FString playerTeam;


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Variables")

FString picPath;


UPlayerClass(const FObjectInitializer& ObjectInitializer);


UFUNCTION(BlueprintCallable, Category = "Import")

virtual void ImportPic(const FString& Path);


};



언리얼 엔진에서는 모든 식별자에 Pascal Case(첫자를 대문자로) 사용


언리얼  클래스 Prefix


U - UObject 하위 클래스 예) UTexture

A - AActor 하위 클래스 예) AGameMode

F - 이외의 모든 클래스와 struct 들 예) FName, FVector

T - 템플릿 예) TArray, TMap

I - 인터페이스 클래스 예) ITransaction

E - Enum 타입 예) ESelectionMode

b - Boolean 변수 예) bEnabled



C++ 변수가 BP의 Set, Get 노드 지원되도록 하려면

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Damage")

int32 TotalDamage;



C++ 클래스를 BP 안에서 인스턴스화하고 함수를 호출하는 예

Blueprint 프로젝트 안에서 Object 클래스를 기반으로 C++클래스를 아래처럼 생성한다


MyObject.h

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


#pragma once


#include "CoreMinimal.h"

#include "UObject/NoExportTypes.h"

#include "MyObject.generated.h"


/**

 * 

 */

UCLASS(BlueprintType)

class CPP_IN_BPPROJ_API UMyObject : public UObject

{

GENERATED_BODY()

public:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Test")

int Score;


UFUNCTION(BlueprintCallable, Category="Test")

int Add(int a, int b);


UFUNCTION(BlueprintCallable, Category = "Test")

static void Create(UClass *ObjectClass, UMyObject* &CreatedObject);

};




MyObject.cpp

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


#include "MyObject.h"


int UMyObject::Add(int a, int b)

{

return a+b;

}


void UMyObject::Create(UClass * ObjectClass, UMyObject *& CreatedObject)

{

CreatedObject = NewObject<UMyObject>((UMyObject*)GetTransientPackage(), ObjectClass);

}



Blueprint 클래스에서 다음과 같이 MyObject 클래스의 인스턴스를 생성하고 사용할 수 있다


Posted by cwisky
Android Screen Mirroring2018. 8. 15. 22:44

Screen Mirroring

동일한 WiFi 네트워크에 연결된 PC와 스마트폰이 있다면 스마트폰에 앱을 설치하여 스마트폰의 화면을 PC 모니터에 표시할 수 있다


PC와 스마트폰 측에서 각각 설정을 해줘야 한다


Windows 10에서 설정하기

시작 > 설정 > 시스템 > PC에 화면표시



안드로이드 폰에서 설정하기


화면 상단 설정 패널을 열고 검색란을 선택한다





검색란에 screen mirroring 라고 입력하고 검색하여 Screen Mirroring Assistant 를 선택하여 설치한다




Screen Mirroring Assistant을 설치한 후에 앱을 실행한다






앱이 실행되면 START 버튼을 누른다





동일한 WiFi 네트워크에 연결된 PC의 이름을 자동으로 찾아 아래처럼 표시해주므로 선택한다




연결대상 PC의 화면 우측하단에 다음과 같은 메시지가 뜨면 [예] 버튼을 누른다. 

잠시후 PC모니터에 스마트폰 화면이 표시된다



Posted by cwisky