一、三视角切换
添加数据结构
项目设置添加切Action ChangeView
namespace EGameViewMode {
enum Type
{
First,
Third
};
角色类中切换视角方法
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include"SlAiTypes.h"
#include "SlAiPlayerCharacter.generated.h"
...
public:
...
void ChangeView(EGameViewMode::Type NewGameView);
public:
...
EGameViewMode::Type GameView;
...
};
void ASlAiPlayerCharacter::ChangeView(EGameViewMode::Type NewGameView)
{
GameView = NewGameView;
switch (GameView)
{
case EGameViewMode::First:
FirstCamera->SetActive(true);
ThirdCamera->SetActive(true);
MeshFirst->SetOwnerNoSee(false);
GetMesh()->SetOwnerNoSee(true);
break;
case EGameViewMode::Third:
ThirdCamera->SetActive(true);
FirstCamera->SetActive(true);
GetMesh()->SetOwnerNoSee(false);
MeshFirst->SetOwnerNoSee(true);
break;
default:
break;
}
}
控制类中使用
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include"SlAiTypes.h"
#include "SlAiPlayerController.generated.h"
UCLASS()
class SLAICOURSE_API ASlAiPlayerController : public APlayerController
{
GENERATED_BODY()
public:
ASlAiPlayerController();
virtual void Tick(float DeltaSeconds) override;
virtual void SetupInputComponent() override;
public:
class ASlAiPlayerCharacter* SPCharacter;
protected:
virtual void BeginPlay() override;
private:
void ChangeView();
};
#include "SlAiPlayerController.h"
#include "Player/SlAiPlayerCharacter.h"
...
void ASlAiPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("ChangeView", IE_Pressed, this, &ASlAiPlayerController::ChangeView);
...
void ASlAiPlayerController::ChangeView()
{
switch (SPCharacter->GameView)
{
case EGameViewMode::Third:
SPCharacter->ChangeView(EGameViewMode::First);
break;
case EGameViewMode::First:
SPCharacter->ChangeView(EGameViewMode::Third);
break;
}
}
绑定Montage资源
SlAiPlayerAnim
protected:
class UAnimMontage* PlayerHitMontage;
UAnimMontage* PlayerEatMontage;
UAnimMontage* PlayerFightMontage;
UAnimMontage* PlayerPunchMontage;
UAnimMontage* PlayerPickUpMontage;
SlAiFirstPlayerAnim
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerHitMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/FirstPlayer/Animation/UpperBody/FirstPlayerHitMontage.FirstPlayerHitMontage'"));
PlayerHitMontage = PlayerHitMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerEatMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/FirstPlayer/Animation/UpperBody/FirstPlayerEatMontage.FirstPlayerEatMontage'"));
PlayerEatMontage = PlayerEatMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerFightMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/FirstPlayer/Animation/UpperBody/FirstPlayerFightMontage.FirstPlayerFightMontage'"));
PlayerFightMontage = PlayerFightMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerPunchMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/FirstPlayer/Animation/UpperBody/FirstPlayerPunchMontage.FirstPlayerPunchMontage'"));
PlayerPunchMontage = PlayerPunchMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerPickUpMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/FirstPlayer/Animation/UpperBody/FirstPlayerPickUpMontage.FirstPlayerPickUpMontage'"));
PlayerPickUpMontage = PlayerPickUpMon.Object;
SlAiThirdPlayerAnim
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerHitMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/Player/Animation/UpperBody/PlayerHitMontage.PlayerHitMontage'"));
PlayerHitMontage = PlayerHitMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerEatMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/Player/Animation/UpperBody/PlayerEatMontage.PlayerEatMontage'"));
PlayerEatMontage = PlayerEatMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerFightMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/Player/Animation/UpperBody/PlayerFightMontage.PlayerFightMontage'"));
PlayerFightMontage = PlayerFightMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerPunchMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/Player/Animation/UpperBody/PlayerPunchMontage.PlayerPunchMontage'"));
PlayerPunchMontage = PlayerPunchMon.Object;
static ConstructorHelpers::FObjectFinder<UAnimMontage> PlayerPickUpMon(TEXT("AnimMontage'/Game/Res/PolygonAdventure/Mannequin/Player/Animation/UpperBody/PlayerPickUpMontage.PlayerPickUpMontage'"));
PlayerPickUpMontage = PlayerPickUpMon.Object;
|