diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 1abe330..a6a41c1 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -20,7 +20,7 @@ GameDefaultMap=/Game/Level/HomeLand.HomeLand [/Script/Engine.RendererSettings] r.Mobile.AntiAliasing=0 -r.AntiAliasingMethod=1 +r.AntiAliasingMethod=4 r.DefaultFeature.MotionBlur=False [CoreRedirects] diff --git a/Content/Blueprint/Level/Actor/Role/BP_Fox.uasset b/Content/Blueprint/Level/Actor/Role/BP_Fox.uasset new file mode 100644 index 0000000..aefdc73 Binary files /dev/null and b/Content/Blueprint/Level/Actor/Role/BP_Fox.uasset differ diff --git a/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset b/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset index 967d378..7f6e2a8 100644 Binary files a/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset and b/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset differ diff --git a/Content/Blueprint/Level/BP_LevelMap.uasset b/Content/Blueprint/Level/BP_LevelMap.uasset index 0ebd6c3..02d5547 100644 Binary files a/Content/Blueprint/Level/BP_LevelMap.uasset and b/Content/Blueprint/Level/BP_LevelMap.uasset differ diff --git a/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerController.uasset b/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerController.uasset index 2783e6c..cf8f75c 100644 Binary files a/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerController.uasset and b/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerController.uasset differ diff --git a/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerState.uasset b/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerState.uasset index d98dc82..492d88b 100644 Binary files a/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerState.uasset and b/Content/Blueprint/Level/GameMode/BP_BusyLevelPlayerState.uasset differ diff --git a/Content/Data/Input/Level/IA_SwitchRole.uasset b/Content/Data/Input/Level/IA_SwitchRole.uasset new file mode 100644 index 0000000..ef43c34 Binary files /dev/null and b/Content/Data/Input/Level/IA_SwitchRole.uasset differ diff --git a/Content/Data/Input/Level/IMC_PlayerInputContext.uasset b/Content/Data/Input/Level/IMC_PlayerInputContext.uasset index a509931..23e1d11 100644 Binary files a/Content/Data/Input/Level/IMC_PlayerInputContext.uasset and b/Content/Data/Input/Level/IMC_PlayerInputContext.uasset differ diff --git a/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset b/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset index 2d95f72..c331ab6 100644 Binary files a/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset and b/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset differ diff --git a/Content/Level/FalconPlain.umap b/Content/Level/FalconPlain.umap index 9c30d3d..48e551f 100644 Binary files a/Content/Level/FalconPlain.umap and b/Content/Level/FalconPlain.umap differ diff --git a/Content/Lua/Level/Actor/LevelFoxRole.lua b/Content/Lua/Level/Actor/LevelFoxRole.lua index d75a09d..640b127 100644 --- a/Content/Lua/Level/Actor/LevelFoxRole.lua +++ b/Content/Lua/Level/Actor/LevelFoxRole.lua @@ -1,4 +1,47 @@ 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) \ No newline at end of file diff --git a/Content/Lua/Level/Actor/LevelRabbitRole.lua b/Content/Lua/Level/Actor/LevelRabbitRole.lua index dca79cd..8ae5416 100644 --- a/Content/Lua/Level/Actor/LevelRabbitRole.lua +++ b/Content/Lua/Level/Actor/LevelRabbitRole.lua @@ -5,8 +5,8 @@ function LevelRabbitRole:ctor() end function LevelRabbitRole:ReceiveBeginPlay() - self["SpineAnimationComponent"]:SetSkin("back/move"); - self["SpineAnimationComponent"]:SetAnimation(0, "animation", true); + -- self["SpineAnimationComponent"]:SetSkin("back/move"); + -- self["SpineAnimationComponent"]:SetAnimation(0, "animation", true); end @@ -31,28 +31,28 @@ function LevelRabbitRole:UpdateMoveDirection(InDirection) end end -function LevelRabbitRole:OnDetachCamera() - print(self, "LevelRabbitRole.OnDetachCamera") +-- function LevelRabbitRole:OnDetachCamera() +-- print(self, "LevelRabbitRole.OnDetachCamera") - -- 禁用弹簧臂的附着 - self["SpringArmComponent"].bEnableCameraRotationLag = true - self["SpringArmComponent"].CameraRotationLagSpeed = 0 - -- 保持当前位置,停止跟随 - self["SpringArmComponent"].bInheritPitch = true - self["SpringArmComponent"].bInheritYaw = true - self["SpringArmComponent"].bInheritRoll = true +-- -- 禁用弹簧臂的附着 +-- self["SpringArmComponent"].bEnableCameraRotationLag = true +-- self["SpringArmComponent"].CameraRotationLagSpeed = 0 +-- -- 保持当前位置,停止跟随 +-- self["SpringArmComponent"].bInheritPitch = true +-- self["SpringArmComponent"].bInheritYaw = true +-- self["SpringArmComponent"].bInheritRoll = true - -- (Pitch=0.000000,Yaw=-90.000000,Roll=0.000000) -end +-- -- (Pitch=0.000000,Yaw=-90.000000,Roll=0.000000) +-- end -function LevelRabbitRole:OnReattachCamera() - print(self, "LevelRabbitRole.OnReattachCamera") -end +-- function LevelRabbitRole:OnReattachCamera() +-- print(self, "LevelRabbitRole.OnReattachCamera") +-- end -function LevelRabbitRole:OnMoveCamera(direction) - print(self, "LevelRabbitRole.OnMoveCamera", direction.X, direction.Y) -end +-- function LevelRabbitRole:OnMoveCamera(direction) +-- print(self, "LevelRabbitRole.OnMoveCamera", direction.X, direction.Y) +-- end return Class(nil, nil, LevelRabbitRole) diff --git a/Content/Lua/Utils/Vector2D.lua b/Content/Lua/Utils/Vector2D.lua index 8626465..a18ba03 100644 --- a/Content/Lua/Utils/Vector2D.lua +++ b/Content/Lua/Utils/Vector2D.lua @@ -1,4 +1,6 @@ -local Vector2D = {} +local Vector2D = { + Zero = {X = 0, Y = 0} +} function Vector2D.New(x, y) return {X = x or 0, Y = y or 0} end @@ -46,5 +48,10 @@ function Vector2D.ToUnrealEngine3D(vector, z) return new_vector 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 \ No newline at end of file diff --git a/Content/Resource/Spine/Role/Fox/Fox.uasset b/Content/Resource/Spine/Role/Fox/Fox.uasset new file mode 100644 index 0000000..e1d4835 Binary files /dev/null and b/Content/Resource/Spine/Role/Fox/Fox.uasset differ diff --git a/Content/Resource/Spine/Role/Fox/FoxData.uasset b/Content/Resource/Spine/Role/Fox/FoxData.uasset new file mode 100644 index 0000000..a795a7d Binary files /dev/null and b/Content/Resource/Spine/Role/Fox/FoxData.uasset differ diff --git a/Content/Resource/Spine/Role/Fox/Textures/Fox.uasset b/Content/Resource/Spine/Role/Fox/Textures/Fox.uasset new file mode 100644 index 0000000..ae63faf Binary files /dev/null and b/Content/Resource/Spine/Role/Fox/Textures/Fox.uasset differ diff --git a/Source/BusyRabbit/Private/Level/Actor/BusyPawnBase.cpp b/Source/BusyRabbit/Private/Level/Actor/BusyPawnBase.cpp index 890874a..5147ba5 100644 --- a/Source/BusyRabbit/Private/Level/Actor/BusyPawnBase.cpp +++ b/Source/BusyRabbit/Private/Level/Actor/BusyPawnBase.cpp @@ -31,10 +31,6 @@ void ABusyPawnBase::BeginPlay() // SpineAnimationComponent->SetAnimation(0, DefaultAnimationName, true); } -void ABusyPawnBase::UpdateMoveDirection_Implementation(const FVector2D& InDirection) -{ - -} float ABusyPawnBase::GetSpeed_Implementation()const { diff --git a/Source/BusyRabbit/Private/Level/Actor/Components/BusyPawnMovement.cpp b/Source/BusyRabbit/Private/Level/Actor/Components/BusyPawnMovement.cpp index f64d99d..e223690 100644 --- a/Source/BusyRabbit/Private/Level/Actor/Components/BusyPawnMovement.cpp +++ b/Source/BusyRabbit/Private/Level/Actor/Components/BusyPawnMovement.cpp @@ -30,8 +30,13 @@ FVector2D UBusyPawnMovement::GetMoveDirection()const return FVector2D(); } +FVector2D UBusyPawnMovement::GetForwardDirection() const +{ + return ForwardDirection; +} + void UBusyPawnMovement::TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) + FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); @@ -64,6 +69,17 @@ void UBusyPawnMovement::TickComponent(float DeltaTime, ELevelTick TickType, { 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; + } } + diff --git a/Source/BusyRabbit/Private/Level/LevelPlayerController.cpp b/Source/BusyRabbit/Private/Level/LevelPlayerController.cpp index 46dc5d9..25b9b41 100644 --- a/Source/BusyRabbit/Private/Level/LevelPlayerController.cpp +++ b/Source/BusyRabbit/Private/Level/LevelPlayerController.cpp @@ -51,6 +51,7 @@ void ALevelPlayerController::SetupInputComponent() BindEnhancedInputAction(EnhancedInput, CameraDetachAction, this, "OnCameraDetach"); BindEnhancedInputAction(EnhancedInput, PrimarySkillAction, this, "OnPrimarySkill"); BindEnhancedInputAction(EnhancedInput, UltimateSkillAction, this, "OnUltimateSkill"); + BindEnhancedInputAction(EnhancedInput, SwitchRoleAction, this, "OnSwitchRole"); } void ALevelPlayerController::Tick(float DeltaTime) @@ -168,3 +169,13 @@ void ALevelPlayerController::OnCameraDetach(const FInputActionValue& Value) SetViewTarget(ControlledRole); } } + +void ALevelPlayerController::OnSwitchRole(const FInputActionValue& Value) +{ + const int32 Index = static_cast(Value.GetMagnitude() - 1); + if (ALevelPlayerState* PS = GetPlayerState()) + { + ABusyPlayerRole* ControlledRole = PS->SwitchControlledRole(Index); + SwitchControlledRole(ControlledRole); + } +} diff --git a/Source/BusyRabbit/Private/Level/LevelPlayerState.cpp b/Source/BusyRabbit/Private/Level/LevelPlayerState.cpp index bbc2687..3cfa3dd 100644 --- a/Source/BusyRabbit/Private/Level/LevelPlayerState.cpp +++ b/Source/BusyRabbit/Private/Level/LevelPlayerState.cpp @@ -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 { return FVector2D::ZeroVector; diff --git a/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp index 35d622e..28dc271 100644 --- a/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp +++ b/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp @@ -54,9 +54,16 @@ inline static IGameMapInterface * GetMapActor(const UActorComponent* Component) void UStaticResourceLayerComponent::GenerateResources() { TArray ResourcePoints; + + // 生成资源点 GenerateResourcePoints(ResourcePoints); + + // 生成必定生成的资源 GenerateAlwaysPresentInfo(ResourcePoints); + // 利用剩下的资源点,根据权重生成资源 + GenerateResourceByWeight(ResourcePoints); + AActor *Owner = GetOwner(); UWorld* World = GetWorld(); @@ -115,6 +122,34 @@ void UStaticResourceLayerComponent::GetAlwaysPresentResourceList(TMap>& OutResourcesWeight) const +{ + using FTuple = TTuple; + + 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(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& ResourcePoints) { AActor *Owner = GetOwner(); @@ -143,7 +178,8 @@ bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray& if (Config->TerrainTypes.HasTag(CurrentTerrain)) // 资源的地形配置包含当前的地形,则添加进生成的列表 { - GeneratedResourcePoints.Add(TTuple(CurrentSelected, FVector2D(ResourcePoints[i].X, ResourcePoints[i].Y))); + TryPushGenerateResult(CurrentSelected, CurrentPoint); + // GeneratedResourcePoints.Add(TTuple(CurrentSelected, FVector2D(ResourcePoints[i].X, ResourcePoints[i].Y))); ConsumeOneOfAlwaysPresent(AlwaysPresentResource, CurrentSelected); ResourcePoints[i].X = ResourcePoints[i].Y = -1; UE_LOG(LogMapGenerate, Log, TEXT("UStaticResourceLayerComponent::GenerateAlwaysPresentInfo Create %s at (%d, %d)"), @@ -164,3 +200,52 @@ bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray& ResourcePoints.RemoveAll([](const FVector2D Element){ return Element.X < 0 && Element.Y < 0; }); return true; } + +void UStaticResourceLayerComponent::GenerateResourceByWeight(TArray& ResourcePoints) +{ + using FTuple = TTuple; + TArray> ResourceWeightList; + for (const FVector2D& Point : ResourcePoints) + { + ResourceWeightList.Empty(); + if (!GetCanGenerateResourcesWeight(Point, ResourceWeightList)) continue; + + float Base = 0.f; + const float RandNum = static_cast(FMath::Rand()) / static_cast(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(ResourceID, Position)); +} + +bool UStaticResourceLayerComponent::GetOwnerInfo(AActor*& Owner, IGameMapInterface*& MapInterface) const +{ + AActor *SelfOwner = GetOwner(); + if (!SelfOwner) return false; + IGameMapInterface * OwnerMapInterface = Cast(SelfOwner); + if (!OwnerMapInterface) return false; + Owner = SelfOwner; + MapInterface = OwnerMapInterface; + return true; +} diff --git a/Source/BusyRabbit/Public/Level/Actor/BusyPawnBase.h b/Source/BusyRabbit/Public/Level/Actor/BusyPawnBase.h index 836f6be..cd5fc78 100644 --- a/Source/BusyRabbit/Public/Level/Actor/BusyPawnBase.h +++ b/Source/BusyRabbit/Public/Level/Actor/BusyPawnBase.h @@ -21,8 +21,6 @@ public: virtual void BeginPlay()override; - virtual void UpdateMoveDirection_Implementation(const FVector2D& InDirection) override; - virtual float GetSpeed_Implementation()const override; protected: diff --git a/Source/BusyRabbit/Public/Level/Actor/Components/BusyPawnMovement.h b/Source/BusyRabbit/Public/Level/Actor/Components/BusyPawnMovement.h index fb79272..b3ae449 100644 --- a/Source/BusyRabbit/Public/Level/Actor/Components/BusyPawnMovement.h +++ b/Source/BusyRabbit/Public/Level/Actor/Components/BusyPawnMovement.h @@ -15,9 +15,9 @@ public: UFUNCTION(BlueprintNativeEvent) float GetSpeed() const; - + UFUNCTION(BlueprintNativeEvent, Category = "Movement") - void UpdateMoveDirection(const FVector2D &InDirection); + void OnMoveDirectionChanged(const FVector2D &InDirection); }; @@ -33,12 +33,30 @@ public: UFUNCTION(BlueprintCallable) void MoveTo(const FVector2D& Target); + /** + * 获取当前移动的方向 + * @return 返回朝向的单位向量,如果没动返回(0,0) + */ UFUNCTION(BlueprintCallable) FVector2D GetMoveDirection()const; + /** + * 获取当前朝向 + * @return 返回当前朝向的单位向量,如果没动,返回上一次运动时的朝向 + */ + UFUNCTION(BlueprintCallable) + FVector2D GetForwardDirection()const; + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)override; protected: UPROPERTY(EditAnywhere, BlueprintReadOnly) FVector2D MoveTargetLocation; + + UPROPERTY(EditAnywhere, BlueprintReadOnly) + FVector2D LastMoveDirection; + + UPROPERTY(EditAnywhere, BlueprintReadOnly) + FVector2D ForwardDirection; + }; diff --git a/Source/BusyRabbit/Public/Level/LevelPlayerController.h b/Source/BusyRabbit/Public/Level/LevelPlayerController.h index 6c7ba84..e805fe4 100644 --- a/Source/BusyRabbit/Public/Level/LevelPlayerController.h +++ b/Source/BusyRabbit/Public/Level/LevelPlayerController.h @@ -85,6 +85,8 @@ public: // 输入相关 UPROPERTY(EditDefaultsOnly, Category = "Input") TObjectPtr CameraDetachAction; // 相机脱离 + UPROPERTY(EditDefaultsOnly, Category = "Input") + TObjectPtr SwitchRoleAction; // 切换控制的角色 public: UFUNCTION() @@ -99,6 +101,9 @@ public: UFUNCTION() void OnCameraDetach(const FInputActionValue& Value); + UFUNCTION() + void OnSwitchRole(const FInputActionValue& Value); + protected: UPROPERTY() diff --git a/Source/BusyRabbit/Public/Level/LevelPlayerState.h b/Source/BusyRabbit/Public/Level/LevelPlayerState.h index cf9bb9e..1eaa690 100644 --- a/Source/BusyRabbit/Public/Level/LevelPlayerState.h +++ b/Source/BusyRabbit/Public/Level/LevelPlayerState.h @@ -26,6 +26,9 @@ public: // 给蓝图的Get接口 UFUNCTION(BlueprintCallable) ABusyPlayerRole* GetControlledRole() const; +public: + UFUNCTION(BlueprintCallable) + ABusyPlayerRole* SwitchControlledRole(int32 Index); protected: virtual FVector2D GetSpawnLocation()const; diff --git a/Source/BusyRabbit/Public/Level/Map/Components/StaticResourceLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/Components/StaticResourceLayerComponent.h index 4cd996c..c062823 100644 --- a/Source/BusyRabbit/Public/Level/Map/Components/StaticResourceLayerComponent.h +++ b/Source/BusyRabbit/Public/Level/Map/Components/StaticResourceLayerComponent.h @@ -5,6 +5,7 @@ #include "StaticResourceLayerComponent.generated.h" +class IGameMapInterface; USTRUCT(BlueprintType, Blueprintable) struct FStaticResourceGenerateConfig: public FTableRowBase @@ -17,11 +18,15 @@ struct FStaticResourceGenerateConfig: public FTableRowBase UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成的最少数量") int MinGenerateCount = 0; + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可以在哪些地形生成") + FGameplayTagContainer TerrainTypes; + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成权重") int GenerateWeight = 1; - UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可以在哪些地形生成") - FGameplayTagContainer TerrainTypes; + // 在这种地形上,最终的权重为 [生成权重]*[地形权重系数],若地形权重系数没有配置,默认为1.0 + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="地形权重系数", meta = (ClampMin = "0.0")) + TMap TerrainWeights; // 用于该资源生成时应该与某些资源保持多远的距离 UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成距离规则") @@ -39,14 +44,27 @@ class UStaticResourceLayerComponent :public UActorComponent public: void GenerateResources(); +protected: // get + void GetAlwaysPresentResourceList(TMap& OutAlwaysPresentResource)const; + + /** + * 获取某个点所有能生成的资源权重列表 + * @param Position 给定点的位置 + * @param[out] OutResourcesWeight 给定点所处的地形能够生成的所有资源列表,包含资源ID和权重 + */ + bool GetCanGenerateResourcesWeight(const FVector2D& Position, TArray>& OutResourcesWeight)const; + protected: virtual void GenerateResourcePoints(TArray& OutResourcePoint); - void GetAlwaysPresentResourceList(TMap& OutAlwaysPresentResource)const; bool GenerateAlwaysPresentInfo(TArray& ResourcePoints); + + void GenerateResourceByWeight(TArray& ResourcePoints); + + void TryPushGenerateResult(const FName& ResourceID, const FVector2D& Position); public: @@ -58,6 +76,7 @@ public: TArray> GeneratedResourcePoints; -protected: +private: + bool GetOwnerInfo(AActor* &Owner, IGameMapInterface* &MapInterface) const; };