109 lines
2.2 KiB
C++
109 lines
2.2 KiB
C++
#pragma once
|
|
#include "LuaActorComponent.h"
|
|
#include "BusyPawnMovement.generated.h"
|
|
|
|
UINTERFACE(MinimalAPI, Blueprintable)
|
|
class UBusyMovable : public UInterface
|
|
{
|
|
GENERATED_BODY()
|
|
};
|
|
|
|
class IBusyMovable
|
|
{
|
|
GENERATED_BODY()
|
|
public:
|
|
|
|
UFUNCTION(BlueprintNativeEvent)
|
|
float GetSpeed() const;
|
|
|
|
UFUNCTION(BlueprintNativeEvent, Category = "Movement")
|
|
void OnMoveDirectionChanged(const FVector2D &InDirection);
|
|
|
|
};
|
|
|
|
UENUM(Blueprintable, BlueprintType)
|
|
enum class EBusyMoveState: uint8
|
|
{
|
|
// 静止
|
|
None = 0,
|
|
// 正常移动
|
|
Move = 1,
|
|
// 冲刺
|
|
Sprint = 2,
|
|
// 被击退
|
|
Knockback = 3,
|
|
};
|
|
|
|
|
|
UCLASS()
|
|
class UBusyPawnMovement : public ULuaActorComponent
|
|
{
|
|
GENERATED_BODY()
|
|
public:
|
|
UBusyPawnMovement();
|
|
|
|
public:
|
|
UFUNCTION(BlueprintCallable)
|
|
void MoveTo(const FVector2D& Target);
|
|
|
|
/**
|
|
* 沿着当前角色的朝向,以若干倍的速度冲刺一定距离的长度
|
|
* @param Distance
|
|
* @param SpeedRate
|
|
*/
|
|
UFUNCTION(BlueprintCallable)
|
|
void SprintTo(const float Distance, const float SpeedRate);
|
|
|
|
/**
|
|
* 获取当前移动的方向
|
|
* @return 返回朝向的单位向量,如果没动返回(0,0)
|
|
*/
|
|
UFUNCTION(BlueprintCallable)
|
|
FVector2D GetMoveDirection()const;
|
|
|
|
/**
|
|
* 获取当前朝向
|
|
* @return 返回当前朝向的单位向量,如果没动,返回上一次运动时的朝向
|
|
*/
|
|
UFUNCTION(BlueprintCallable)
|
|
FVector2D GetForwardDirection()const;
|
|
|
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)override;
|
|
|
|
|
|
/**
|
|
* 处理移动的Tick
|
|
* @param DeltaTime 距离上一帧的时间
|
|
*/
|
|
void MoveTick(const float DeltaTime);
|
|
|
|
/**
|
|
* 处理冲刺的Tick
|
|
* @param DeltaTime 距离上一帧的时间
|
|
*/
|
|
void SprintTick(const float DeltaTime);
|
|
|
|
protected:
|
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Movement")
|
|
EBusyMoveState BusyMoveState = EBusyMoveState::None;
|
|
|
|
|
|
protected:
|
|
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
|
FVector2D MoveTargetLocation;
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
|
FVector2D LastMoveDirection;
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
|
FVector2D ForwardDirection;
|
|
|
|
|
|
|
|
protected: // 冲刺相关
|
|
float SprintSpeedRate = 1.f;
|
|
float SprintDistance = 100.f;
|
|
FVector2D SprintStartLocation;
|
|
|
|
};
|