狐狸接入
This commit is contained in:
@ -20,7 +20,7 @@ GameDefaultMap=/Game/Level/HomeLand.HomeLand
|
|||||||
|
|
||||||
[/Script/Engine.RendererSettings]
|
[/Script/Engine.RendererSettings]
|
||||||
r.Mobile.AntiAliasing=0
|
r.Mobile.AntiAliasing=0
|
||||||
r.AntiAliasingMethod=1
|
r.AntiAliasingMethod=4
|
||||||
r.DefaultFeature.MotionBlur=False
|
r.DefaultFeature.MotionBlur=False
|
||||||
|
|
||||||
[CoreRedirects]
|
[CoreRedirects]
|
||||||
|
|||||||
BIN
Content/Blueprint/Level/Actor/Role/BP_Fox.uasset
Normal file
BIN
Content/Blueprint/Level/Actor/Role/BP_Fox.uasset
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Content/Data/Input/Level/IA_SwitchRole.uasset
Normal file
BIN
Content/Data/Input/Level/IA_SwitchRole.uasset
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,47 @@
|
|||||||
local LevelFoxRole = {}
|
local LevelFoxRole = {}
|
||||||
|
local Vector2D = require("Utils.Vector2D")
|
||||||
|
|
||||||
|
function LevelFoxRole:ctor()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function LevelFoxRole:ReceiveBeginPlay()
|
||||||
|
self["SpineAnimationComponent"]:SetAnimation(0, "Idle/Front", true)
|
||||||
|
self.last_animation = "Idle/Front"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function LevelFoxRole:OnMoveDirectionChanged(InDirection)
|
||||||
|
-- 运动组件更新方向响应函数
|
||||||
|
local cur_animation
|
||||||
|
|
||||||
|
if Vector2D.Equals(InDirection, Vector2D.Zero) then -- Idle的情况
|
||||||
|
local forward_direction = self["MovementComponent"]:GetForwardDirection()
|
||||||
|
if(forward_direction.Y >= 0) then
|
||||||
|
cur_animation = "Idle/Front"
|
||||||
|
else
|
||||||
|
cur_animation = "Idle/Back"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if(InDirection.Y >= 0) then
|
||||||
|
cur_animation = "Move/Front"
|
||||||
|
else
|
||||||
|
cur_animation = "Move/Back"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- if cur_animation ~= self.last_animation then
|
||||||
|
print("changed", cur_animation)
|
||||||
|
|
||||||
|
self["SpineAnimationComponent"]:SetAnimation(0, cur_animation, true)
|
||||||
|
self.last_animation = cur_animation
|
||||||
|
-- end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function LevelFoxRole:OnMove(location)
|
||||||
|
-- 控制器移动相应函数
|
||||||
|
self["MovementComponent"]:MoveTo(location)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return Class(nil, nil, LevelFoxRole)
|
return Class(nil, nil, LevelFoxRole)
|
||||||
@ -5,8 +5,8 @@ function LevelRabbitRole:ctor()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function LevelRabbitRole:ReceiveBeginPlay()
|
function LevelRabbitRole:ReceiveBeginPlay()
|
||||||
self["SpineAnimationComponent"]:SetSkin("back/move");
|
-- self["SpineAnimationComponent"]:SetSkin("back/move");
|
||||||
self["SpineAnimationComponent"]:SetAnimation(0, "animation", true);
|
-- self["SpineAnimationComponent"]:SetAnimation(0, "animation", true);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -31,28 +31,28 @@ function LevelRabbitRole:UpdateMoveDirection(InDirection)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function LevelRabbitRole:OnDetachCamera()
|
-- function LevelRabbitRole:OnDetachCamera()
|
||||||
print(self, "LevelRabbitRole.OnDetachCamera")
|
-- print(self, "LevelRabbitRole.OnDetachCamera")
|
||||||
|
|
||||||
-- 禁用弹簧臂的附着
|
-- -- 禁用弹簧臂的附着
|
||||||
self["SpringArmComponent"].bEnableCameraRotationLag = true
|
-- self["SpringArmComponent"].bEnableCameraRotationLag = true
|
||||||
self["SpringArmComponent"].CameraRotationLagSpeed = 0
|
-- self["SpringArmComponent"].CameraRotationLagSpeed = 0
|
||||||
-- 保持当前位置,停止跟随
|
-- -- 保持当前位置,停止跟随
|
||||||
self["SpringArmComponent"].bInheritPitch = true
|
-- self["SpringArmComponent"].bInheritPitch = true
|
||||||
self["SpringArmComponent"].bInheritYaw = true
|
-- self["SpringArmComponent"].bInheritYaw = true
|
||||||
self["SpringArmComponent"].bInheritRoll = true
|
-- self["SpringArmComponent"].bInheritRoll = true
|
||||||
|
|
||||||
-- (Pitch=0.000000,Yaw=-90.000000,Roll=0.000000)
|
-- -- (Pitch=0.000000,Yaw=-90.000000,Roll=0.000000)
|
||||||
end
|
-- end
|
||||||
|
|
||||||
function LevelRabbitRole:OnReattachCamera()
|
-- function LevelRabbitRole:OnReattachCamera()
|
||||||
print(self, "LevelRabbitRole.OnReattachCamera")
|
-- print(self, "LevelRabbitRole.OnReattachCamera")
|
||||||
end
|
-- end
|
||||||
|
|
||||||
|
|
||||||
function LevelRabbitRole:OnMoveCamera(direction)
|
-- function LevelRabbitRole:OnMoveCamera(direction)
|
||||||
print(self, "LevelRabbitRole.OnMoveCamera", direction.X, direction.Y)
|
-- print(self, "LevelRabbitRole.OnMoveCamera", direction.X, direction.Y)
|
||||||
end
|
-- end
|
||||||
|
|
||||||
|
|
||||||
return Class(nil, nil, LevelRabbitRole)
|
return Class(nil, nil, LevelRabbitRole)
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
local Vector2D = {}
|
local Vector2D = {
|
||||||
|
Zero = {X = 0, Y = 0}
|
||||||
|
}
|
||||||
function Vector2D.New(x, y)
|
function Vector2D.New(x, y)
|
||||||
return {X = x or 0, Y = y or 0}
|
return {X = x or 0, Y = y or 0}
|
||||||
end
|
end
|
||||||
@ -46,5 +48,10 @@ function Vector2D.ToUnrealEngine3D(vector, z)
|
|||||||
return new_vector
|
return new_vector
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Vector2D.Equals(a, b, tolerance)
|
||||||
|
local tol = tolerance or 0.001
|
||||||
|
print(tol, a.X-b.X, a.Y-b.Y)
|
||||||
|
return math.abs(a.X - b.X) < tol and math.abs(a.Y - b.Y) < tol
|
||||||
|
end
|
||||||
|
|
||||||
return Vector2D
|
return Vector2D
|
||||||
BIN
Content/Resource/Spine/Role/Fox/Fox.uasset
Normal file
BIN
Content/Resource/Spine/Role/Fox/Fox.uasset
Normal file
Binary file not shown.
BIN
Content/Resource/Spine/Role/Fox/FoxData.uasset
Normal file
BIN
Content/Resource/Spine/Role/Fox/FoxData.uasset
Normal file
Binary file not shown.
BIN
Content/Resource/Spine/Role/Fox/Textures/Fox.uasset
Normal file
BIN
Content/Resource/Spine/Role/Fox/Textures/Fox.uasset
Normal file
Binary file not shown.
@ -31,10 +31,6 @@ void ABusyPawnBase::BeginPlay()
|
|||||||
// SpineAnimationComponent->SetAnimation(0, DefaultAnimationName, true);
|
// SpineAnimationComponent->SetAnimation(0, DefaultAnimationName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABusyPawnBase::UpdateMoveDirection_Implementation(const FVector2D& InDirection)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
float ABusyPawnBase::GetSpeed_Implementation()const
|
float ABusyPawnBase::GetSpeed_Implementation()const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -30,6 +30,11 @@ FVector2D UBusyPawnMovement::GetMoveDirection()const
|
|||||||
return FVector2D();
|
return FVector2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FVector2D UBusyPawnMovement::GetForwardDirection() const
|
||||||
|
{
|
||||||
|
return ForwardDirection;
|
||||||
|
}
|
||||||
|
|
||||||
void UBusyPawnMovement::TickComponent(float DeltaTime, ELevelTick TickType,
|
void UBusyPawnMovement::TickComponent(float DeltaTime, ELevelTick TickType,
|
||||||
FActorComponentTickFunction* ThisTickFunction)
|
FActorComponentTickFunction* ThisTickFunction)
|
||||||
{
|
{
|
||||||
@ -64,6 +69,17 @@ void UBusyPawnMovement::TickComponent(float DeltaTime, ELevelTick TickType,
|
|||||||
{
|
{
|
||||||
Owner->SetActorLocation(NewLocation, true);
|
Owner->SetActorLocation(NewLocation, true);
|
||||||
}
|
}
|
||||||
Movable->Execute_UpdateMoveDirection(Owner, GetMoveDirection());
|
|
||||||
|
FVector2D &&NewDirection=GetMoveDirection();
|
||||||
|
if (!NewDirection.Equals(FVector2D::Zero(), 0.01))
|
||||||
|
{
|
||||||
|
ForwardDirection = NewDirection;
|
||||||
|
}
|
||||||
|
if (!NewDirection.Equals(LastMoveDirection))
|
||||||
|
{
|
||||||
|
Movable->Execute_OnMoveDirectionChanged(Owner, NewDirection);
|
||||||
|
LastMoveDirection = NewDirection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -51,6 +51,7 @@ void ALevelPlayerController::SetupInputComponent()
|
|||||||
BindEnhancedInputAction(EnhancedInput, CameraDetachAction, this, "OnCameraDetach");
|
BindEnhancedInputAction(EnhancedInput, CameraDetachAction, this, "OnCameraDetach");
|
||||||
BindEnhancedInputAction(EnhancedInput, PrimarySkillAction, this, "OnPrimarySkill");
|
BindEnhancedInputAction(EnhancedInput, PrimarySkillAction, this, "OnPrimarySkill");
|
||||||
BindEnhancedInputAction(EnhancedInput, UltimateSkillAction, this, "OnUltimateSkill");
|
BindEnhancedInputAction(EnhancedInput, UltimateSkillAction, this, "OnUltimateSkill");
|
||||||
|
BindEnhancedInputAction(EnhancedInput, SwitchRoleAction, this, "OnSwitchRole");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALevelPlayerController::Tick(float DeltaTime)
|
void ALevelPlayerController::Tick(float DeltaTime)
|
||||||
@ -168,3 +169,13 @@ void ALevelPlayerController::OnCameraDetach(const FInputActionValue& Value)
|
|||||||
SetViewTarget(ControlledRole);
|
SetViewTarget(ControlledRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ALevelPlayerController::OnSwitchRole(const FInputActionValue& Value)
|
||||||
|
{
|
||||||
|
const int32 Index = static_cast<int32>(Value.GetMagnitude() - 1);
|
||||||
|
if (ALevelPlayerState* PS = GetPlayerState<ALevelPlayerState>())
|
||||||
|
{
|
||||||
|
ABusyPlayerRole* ControlledRole = PS->SwitchControlledRole(Index);
|
||||||
|
SwitchControlledRole(ControlledRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -67,6 +67,19 @@ ABusyPlayerRole* ALevelPlayerState::GetControlledRole() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ABusyPlayerRole* ALevelPlayerState::SwitchControlledRole(int32 Index)
|
||||||
|
{
|
||||||
|
if (RoleRoster.IsValidIndex(Index))
|
||||||
|
{
|
||||||
|
ControlledRoleIndex = Index;
|
||||||
|
return RoleRoster[ControlledRoleIndex];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FVector2D ALevelPlayerState::GetSpawnLocation()const
|
FVector2D ALevelPlayerState::GetSpawnLocation()const
|
||||||
{
|
{
|
||||||
return FVector2D::ZeroVector;
|
return FVector2D::ZeroVector;
|
||||||
|
|||||||
@ -54,9 +54,16 @@ inline static IGameMapInterface * GetMapActor(const UActorComponent* Component)
|
|||||||
void UStaticResourceLayerComponent::GenerateResources()
|
void UStaticResourceLayerComponent::GenerateResources()
|
||||||
{
|
{
|
||||||
TArray<FVector2D> ResourcePoints;
|
TArray<FVector2D> ResourcePoints;
|
||||||
|
|
||||||
|
// 生成资源点
|
||||||
GenerateResourcePoints(ResourcePoints);
|
GenerateResourcePoints(ResourcePoints);
|
||||||
|
|
||||||
|
// 生成必定生成的资源
|
||||||
GenerateAlwaysPresentInfo(ResourcePoints);
|
GenerateAlwaysPresentInfo(ResourcePoints);
|
||||||
|
|
||||||
|
// 利用剩下的资源点,根据权重生成资源
|
||||||
|
GenerateResourceByWeight(ResourcePoints);
|
||||||
|
|
||||||
AActor *Owner = GetOwner();
|
AActor *Owner = GetOwner();
|
||||||
UWorld* World = GetWorld();
|
UWorld* World = GetWorld();
|
||||||
|
|
||||||
@ -115,6 +122,34 @@ void UStaticResourceLayerComponent::GetAlwaysPresentResourceList(TMap<FName, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma optimize("",off)
|
||||||
|
bool UStaticResourceLayerComponent::GetCanGenerateResourcesWeight(const FVector2D& Position,
|
||||||
|
TArray<TTuple<FName, int>>& OutResourcesWeight) const
|
||||||
|
{
|
||||||
|
using FTuple = TTuple<FName, int>;
|
||||||
|
|
||||||
|
AActor *Owner;
|
||||||
|
IGameMapInterface * MapInterface;
|
||||||
|
OutResourcesWeight.Empty();
|
||||||
|
|
||||||
|
if (!GetOwnerInfo(Owner, MapInterface)) return false;
|
||||||
|
if (!GenerateConfig) return false;
|
||||||
|
|
||||||
|
FGameplayTag &&Terrain = MapInterface->Execute_GetTerrainAt(Owner, Position.X, Position.Y);
|
||||||
|
if (!Terrain.IsValid()) return false;
|
||||||
|
|
||||||
|
for (const auto& Pair : GenerateConfig->GetRowMap())
|
||||||
|
{
|
||||||
|
const FStaticResourceGenerateConfig* RowData = reinterpret_cast<FStaticResourceGenerateConfig*>(Pair.Value);
|
||||||
|
if (!RowData->TerrainTypes.HasTag(Terrain)) continue;
|
||||||
|
const float *TerrainWeightFindResult = RowData->TerrainWeights.Find(Terrain);
|
||||||
|
float TotalWeight = RowData->GenerateWeight * (TerrainWeightFindResult ? *TerrainWeightFindResult : 1.0);
|
||||||
|
OutResourcesWeight.Add(FTuple(Pair.Key, TotalWeight));
|
||||||
|
}
|
||||||
|
return !OutResourcesWeight.IsEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray<FVector2D>& ResourcePoints)
|
bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray<FVector2D>& ResourcePoints)
|
||||||
{
|
{
|
||||||
AActor *Owner = GetOwner();
|
AActor *Owner = GetOwner();
|
||||||
@ -143,7 +178,8 @@ bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray<FVector2D>&
|
|||||||
|
|
||||||
if (Config->TerrainTypes.HasTag(CurrentTerrain)) // 资源的地形配置包含当前的地形,则添加进生成的列表
|
if (Config->TerrainTypes.HasTag(CurrentTerrain)) // 资源的地形配置包含当前的地形,则添加进生成的列表
|
||||||
{
|
{
|
||||||
GeneratedResourcePoints.Add(TTuple<FName, FVector2D>(CurrentSelected, FVector2D(ResourcePoints[i].X, ResourcePoints[i].Y)));
|
TryPushGenerateResult(CurrentSelected, CurrentPoint);
|
||||||
|
// GeneratedResourcePoints.Add(TTuple<FName, FVector2D>(CurrentSelected, FVector2D(ResourcePoints[i].X, ResourcePoints[i].Y)));
|
||||||
ConsumeOneOfAlwaysPresent(AlwaysPresentResource, CurrentSelected);
|
ConsumeOneOfAlwaysPresent(AlwaysPresentResource, CurrentSelected);
|
||||||
ResourcePoints[i].X = ResourcePoints[i].Y = -1;
|
ResourcePoints[i].X = ResourcePoints[i].Y = -1;
|
||||||
UE_LOG(LogMapGenerate, Log, TEXT("UStaticResourceLayerComponent::GenerateAlwaysPresentInfo Create %s at (%d, %d)"),
|
UE_LOG(LogMapGenerate, Log, TEXT("UStaticResourceLayerComponent::GenerateAlwaysPresentInfo Create %s at (%d, %d)"),
|
||||||
@ -164,3 +200,52 @@ bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray<FVector2D>&
|
|||||||
ResourcePoints.RemoveAll([](const FVector2D Element){ return Element.X < 0 && Element.Y < 0; });
|
ResourcePoints.RemoveAll([](const FVector2D Element){ return Element.X < 0 && Element.Y < 0; });
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UStaticResourceLayerComponent::GenerateResourceByWeight(TArray<FVector2D>& ResourcePoints)
|
||||||
|
{
|
||||||
|
using FTuple = TTuple<FName, int>;
|
||||||
|
TArray<TTuple<FName, int>> ResourceWeightList;
|
||||||
|
for (const FVector2D& Point : ResourcePoints)
|
||||||
|
{
|
||||||
|
ResourceWeightList.Empty();
|
||||||
|
if (!GetCanGenerateResourcesWeight(Point, ResourceWeightList)) continue;
|
||||||
|
|
||||||
|
float Base = 0.f;
|
||||||
|
const float RandNum = static_cast<float>(FMath::Rand()) / static_cast<float>(RAND_MAX);
|
||||||
|
|
||||||
|
const float TotalWeight = Algo::Accumulate(ResourceWeightList, 0.f, [](const float Sum, const FTuple& Element)
|
||||||
|
{
|
||||||
|
return Sum + Element.Value;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (FTuple& Element : ResourceWeightList)
|
||||||
|
{
|
||||||
|
const float RandomBolder = Base + Element.Value / TotalWeight;
|
||||||
|
if (RandNum >= Base && RandNum < RandomBolder)
|
||||||
|
{
|
||||||
|
TryPushGenerateResult(Element.Key, Point);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Base = RandomBolder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma optimize("",on)
|
||||||
|
|
||||||
|
|
||||||
|
void UStaticResourceLayerComponent::TryPushGenerateResult(const FName& ResourceID, const FVector2D& Position)
|
||||||
|
{
|
||||||
|
GeneratedResourcePoints.Add(TTuple<FName, FVector2D>(ResourceID, Position));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UStaticResourceLayerComponent::GetOwnerInfo(AActor*& Owner, IGameMapInterface*& MapInterface) const
|
||||||
|
{
|
||||||
|
AActor *SelfOwner = GetOwner();
|
||||||
|
if (!SelfOwner) return false;
|
||||||
|
IGameMapInterface * OwnerMapInterface = Cast<IGameMapInterface>(SelfOwner);
|
||||||
|
if (!OwnerMapInterface) return false;
|
||||||
|
Owner = SelfOwner;
|
||||||
|
MapInterface = OwnerMapInterface;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@ -21,8 +21,6 @@ public:
|
|||||||
|
|
||||||
virtual void BeginPlay()override;
|
virtual void BeginPlay()override;
|
||||||
|
|
||||||
virtual void UpdateMoveDirection_Implementation(const FVector2D& InDirection) override;
|
|
||||||
|
|
||||||
virtual float GetSpeed_Implementation()const override;
|
virtual float GetSpeed_Implementation()const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@ -17,7 +17,7 @@ public:
|
|||||||
float GetSpeed() const;
|
float GetSpeed() const;
|
||||||
|
|
||||||
UFUNCTION(BlueprintNativeEvent, Category = "Movement")
|
UFUNCTION(BlueprintNativeEvent, Category = "Movement")
|
||||||
void UpdateMoveDirection(const FVector2D &InDirection);
|
void OnMoveDirectionChanged(const FVector2D &InDirection);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,12 +33,30 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void MoveTo(const FVector2D& Target);
|
void MoveTo(const FVector2D& Target);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前移动的方向
|
||||||
|
* @return 返回朝向的单位向量,如果没动返回(0,0)
|
||||||
|
*/
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
FVector2D GetMoveDirection()const;
|
FVector2D GetMoveDirection()const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前朝向
|
||||||
|
* @return 返回当前朝向的单位向量,如果没动,返回上一次运动时的朝向
|
||||||
|
*/
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
FVector2D GetForwardDirection()const;
|
||||||
|
|
||||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)override;
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
||||||
FVector2D MoveTargetLocation;
|
FVector2D MoveTargetLocation;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
||||||
|
FVector2D LastMoveDirection;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly)
|
||||||
|
FVector2D ForwardDirection;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -85,6 +85,8 @@ public: // 输入相关
|
|||||||
UPROPERTY(EditDefaultsOnly, Category = "Input")
|
UPROPERTY(EditDefaultsOnly, Category = "Input")
|
||||||
TObjectPtr<class UInputAction> CameraDetachAction; // 相机脱离
|
TObjectPtr<class UInputAction> CameraDetachAction; // 相机脱离
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, Category = "Input")
|
||||||
|
TObjectPtr<class UInputAction> SwitchRoleAction; // 切换控制的角色
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
@ -99,6 +101,9 @@ public:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnCameraDetach(const FInputActionValue& Value);
|
void OnCameraDetach(const FInputActionValue& Value);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnSwitchRole(const FInputActionValue& Value);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
|
|||||||
@ -26,6 +26,9 @@ public: // 给蓝图的Get接口
|
|||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
ABusyPlayerRole* GetControlledRole() const;
|
ABusyPlayerRole* GetControlledRole() const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
ABusyPlayerRole* SwitchControlledRole(int32 Index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual FVector2D GetSpawnLocation()const;
|
virtual FVector2D GetSpawnLocation()const;
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include "StaticResourceLayerComponent.generated.h"
|
#include "StaticResourceLayerComponent.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
class IGameMapInterface;
|
||||||
|
|
||||||
USTRUCT(BlueprintType, Blueprintable)
|
USTRUCT(BlueprintType, Blueprintable)
|
||||||
struct FStaticResourceGenerateConfig: public FTableRowBase
|
struct FStaticResourceGenerateConfig: public FTableRowBase
|
||||||
@ -17,11 +18,15 @@ struct FStaticResourceGenerateConfig: public FTableRowBase
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成的最少数量")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成的最少数量")
|
||||||
int MinGenerateCount = 0;
|
int MinGenerateCount = 0;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可以在哪些地形生成")
|
||||||
|
FGameplayTagContainer TerrainTypes;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成权重")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成权重")
|
||||||
int GenerateWeight = 1;
|
int GenerateWeight = 1;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可以在哪些地形生成")
|
// 在这种地形上,最终的权重为 [生成权重]*[地形权重系数],若地形权重系数没有配置,默认为1.0
|
||||||
FGameplayTagContainer TerrainTypes;
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="地形权重系数", meta = (ClampMin = "0.0"))
|
||||||
|
TMap<FGameplayTag, float> TerrainWeights;
|
||||||
|
|
||||||
// 用于该资源生成时应该与某些资源保持多远的距离
|
// 用于该资源生成时应该与某些资源保持多远的距离
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成距离规则")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成距离规则")
|
||||||
@ -39,15 +44,28 @@ class UStaticResourceLayerComponent :public UActorComponent
|
|||||||
public:
|
public:
|
||||||
void GenerateResources();
|
void GenerateResources();
|
||||||
|
|
||||||
|
protected: // get
|
||||||
|
void GetAlwaysPresentResourceList(TMap<FName, int32>& OutAlwaysPresentResource)const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某个点所有能生成的资源权重列表
|
||||||
|
* @param Position 给定点的位置
|
||||||
|
* @param[out] OutResourcesWeight 给定点所处的地形能够生成的所有资源列表,包含资源ID和权重
|
||||||
|
*/
|
||||||
|
bool GetCanGenerateResourcesWeight(const FVector2D& Position, TArray<TTuple<FName, int>>& OutResourcesWeight)const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void GenerateResourcePoints(TArray<FVector2D>& OutResourcePoint);
|
virtual void GenerateResourcePoints(TArray<FVector2D>& OutResourcePoint);
|
||||||
|
|
||||||
void GetAlwaysPresentResourceList(TMap<FName, int32>& OutAlwaysPresentResource)const;
|
|
||||||
|
|
||||||
bool GenerateAlwaysPresentInfo(TArray<FVector2D>& ResourcePoints);
|
bool GenerateAlwaysPresentInfo(TArray<FVector2D>& ResourcePoints);
|
||||||
|
|
||||||
|
void GenerateResourceByWeight(TArray<FVector2D>& ResourcePoints);
|
||||||
|
|
||||||
|
void TryPushGenerateResult(const FName& ResourceID, const FVector2D& Position);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
@ -58,6 +76,7 @@ public:
|
|||||||
|
|
||||||
TArray<TTuple<FName, FVector2D>> GeneratedResourcePoints;
|
TArray<TTuple<FName, FVector2D>> GeneratedResourcePoints;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
bool GetOwnerInfo(AActor* &Owner, IGameMapInterface* &MapInterface) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user