Playerの作成
行動の遷移処理(Action)の定義
行動(Action)の遷移処理の定義をします。 定義する行動は3つです。
- 初期状態
- 待機と移動
- 攻撃
CppPlayerController.hの修正
CppPlayerController.hに行動を定義します。
また、これらを遷移するための処理を追加します。
まずは全文。
CppPlayerController.h
/**
* @file CppPlayerController.h
* @brief プレイヤーコントローラー
* @author inuvatico
* @date 2020/10/17
* @version 1.0
* @copyright 2020 inuvatico
* Released under the MIT license.
* see https://opensource.org/licenses/MIT
* @par (new/Add/Change : 2020/10/17)
*
*/
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "../../../uty/IvPadInput.h" //Key入力の取得
#include "../../../uty/AnmStateComponent.h" //アニメーション状態コンポーネント
#include "CppPlayerController.generated.h"
//クラスの前方宣言
class UArmCamera;
class ACppPlyBase;
//========================================================================
/// プレイヤーコントローラー
//========================================================================
UCLASS()
class ACppPlayerController : public APlayerController
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
public:
ACppPlayerController();
virtual void Tick(float DeltaTime) override;
protected:
void PadMove(void);
protected:
ACppPlyBase* MyActor; //!< 操作対象のActor
UArmCamera *ArmCamera = nullptr; //!< アームカメラ
IvPadInput PadInput; //!< Key入力
public:
/// Actionのタイミング
enum class CallType {
INIT,//!< 開始
ACT, //!< 行動中
TERM, //!< 終了
MAX
};
//-------------------------------------------------------------
/// Actionの定義
//-------------------------------------------------------------
enum class ActType : int {
Init,
IdleRun,
Attack1,
MAX,
};
//-------------------------------------------------------------
/// Actionメンバーの定義
//-------------------------------------------------------------
void ActInit(CallType type);
void ActIdleRun(CallType type);
void ActAttack1(CallType type);
//-------------------------------------------------------------
/// Actionの切り替え
//-------------------------------------------------------------
void SetAction(ActType actionID) {
using fnc = void (ACppPlayerController::*)(CallType type);
static const fnc fncList[ActType::MAX] = {
&ACppPlayerController::ActInit
,&ACppPlayerController::ActIdleRun
,&ACppPlayerController::ActAttack1
};
if (CurrentAction) {
(this->*CurrentAction)(CallType::TERM);//Actionの終了
}
fnc NewAction = fncList[(int)actionID];
CurrentAction = NewAction;
(this->*CurrentAction)(CallType::INIT);//Actionの開始
}
private:
void (ACppPlayerController::*CurrentAction)(CallType type) = nullptr;
};
enum class CallType
Actionのタイミングを表します
enum class ActType : int {
Init,
IdleRun,
Attack1,
MAX,
};
行動の定義
行動用のenumと対応するメソッドを定義しています。
//-------------------------------------------------------------
/// Actionの定義
//-------------------------------------------------------------
enum class ActType : int {
Init,
IdleRun,
Attack1,
MAX,
};
//-------------------------------------------------------------
/// Actionメンバーの定義
//-------------------------------------------------------------
void ActInit(CallType type);
void ActIdleRun(CallType type);
void ActAttack1(CallType type);
行動の切り替え
行動の切り替えにはSetAction()
を使います。
パラメータのactionIDはActionメンバー関数の取得に使用します。
//-------------------------------------------------------------
/// Actionの定義
//-------------------------------------------------------------
enum class ActType : int {
Init,
IdleRun,
Attack1,
MAX,
};
//-------------------------------------------------------------
/// Actionメンバーの定義
//-------------------------------------------------------------
void ActInit(CallType type);
void ActIdleRun(CallType type);
void ActAttack1(CallType type);
//-------------------------------------------------------------
/// Actionの切り替え
//-------------------------------------------------------------
void SetAction(ActType actionID) {
using fnc = void (ACppPlayerController::*)(CallType type);
static const fnc fncList[ActType::MAX] = {
&ACppPlayerController::ActInit
,&ACppPlayerController::ActIdleRun
,&ACppPlayerController::ActAttack1
};
if (CurrentAction) {
(this->*CurrentAction)(CallType::TERM);//Actionの終了
}
fnc NewAction = fncList[(int)actionID];
CurrentAction = NewAction;
(this->*CurrentAction)(CallType::INIT);//Actionの開始
}
private:
void (ACppPlayerController::*CurrentAction)(CallType type) = nullptr;
次は、CppPlayerController.cppに実装です。