优化角色生成位置 #2

同时也将地图扩大为128 * 128
This commit is contained in:
2025-10-30 23:11:08 +08:00
parent 239425c47d
commit 39b100acff
18 changed files with 84 additions and 23 deletions

View File

@ -15,7 +15,7 @@ ManualIPAddress=
[/Script/EngineSettings.GameMapsSettings]
GlobalDefaultGameMode=/Game/Blueprint/Bp_BusyGameMode.Bp_BusyGameMode_C
GameInstanceClass=/Script/BusyRabbit.BusyGameInstance
EditorStartupMap=/Game/Level/HomeLand.HomeLand
EditorStartupMap=/Game/Level/FalconPlain.FalconPlain
GameDefaultMap=/Game/Level/FalconPlain.FalconPlain
[/Script/Engine.RendererSettings]

View File

@ -1,3 +1,4 @@
;METADATA=(Diff=true, UseCommands=true)
[/Script/GameplayTags.GameplayTagsSettings]
ImportTagsFromConfig=True
WarnOnInvalidTags=True
@ -57,6 +58,9 @@ NetIndexFirstBitSegment=16
+GameplayTagList=(Tag="Ingredient.Vegetable.Carrot",DevComment="胡萝卜")
+GameplayTagList=(Tag="Recover.Role.Health",DevComment="回复生命值")
+GameplayTagList=(Tag="Recover.Role.Hunger",DevComment="恢复饥饿值")
+GameplayTagList=(Tag="Resource",DevComment="资源")
+GameplayTagList=(Tag="Resource.Building",DevComment="建筑物")
+GameplayTagList=(Tag="Resource.Building.Campsite",DevComment="营地")
+GameplayTagList=(Tag="Status.Role.Invincible",DevComment="不掉血标签")
+GameplayTagList=(Tag="Terrain.Desert",DevComment="荒漠地形")
+GameplayTagList=(Tag="Terrain.Forest",DevComment="森林")

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,7 @@
using UnrealSharp;
using UnrealSharp.Attributes;
using UnrealSharp.BusyRabbit;
using UnrealSharp.CoreUObject;
using UnrealSharp.Engine;
namespace Level.GameSettings;
@ -11,7 +13,17 @@ public class ABusyLevelPlayerState : ALevelPlayerState
{
base.BeginPlay();
APlayerController pc = UGameplayStatics.GetPlayerController(0);
var role = CreateRoleRoster(pc) as APawn;
pc.Possess(role);
UGameplayStatics.GetAllActorsWithTag("Resource.Building.Campsite", out IList<AActor> FoundActors);
FVector SpawnLocation = new FVector(0, 0, 10);
if (FoundActors.Count > 0)
{
SpawnLocation = FoundActors[0].ActorLocation;
}
if(CreateRoleRoster(pc) is APawn Role)
{
pc.Possess(Role);
Role.SetActorLocation(SpawnLocation);
}
}
}

View File

@ -1,6 +1,8 @@
#include "Level/Actor/BusyStaticResource.h"
#include "SpineSkeletonRendererComponent.h"
#include "SpineSkeletonAnimationComponent.h"
#include "BusyGameplayLibrary.h"
#include "Data/BusyResourceConfig.h"
ABusyStaticResource::ABusyStaticResource()
{
@ -21,4 +23,19 @@ void ABusyStaticResource::BeginPlay()
Super::BeginPlay();
SpineAnimationComponent->SetSkin("default");
SpineAnimationComponent->SetAnimation(0, "idle", true);
if (ResourceName.IsNone()) return;
const UDataTable* ResourceTable = UBusyGameplayLibrary::GetGameDataTable("ResourceConfig");
if (!ResourceTable) return;
FBusyResourceConfig* Config = ResourceTable->FindRow<FBusyResourceConfig>(
ResourceName, *FString::Printf(TEXT("ABusyStaticResource::BeginPlay Find Config: %s"), *ResourceName.ToString())
);
if (Config == nullptr) return;
for (const FGameplayTag& Tag : Config->GameplayTags)
{
Tags.AddUnique(Tag.GetTagName());
}
}

View File

@ -113,7 +113,7 @@ void UStaticResourceLayerComponent::GenerateResourcePoints(TArray<FVector2D>& Ou
const IGameMapInterface * MapInterface = Cast<IGameMapInterface>(Owner);
if (!MapInterface) return;
float MapWidth, MapHeight;
int32 MapWidth, MapHeight;
MapInterface->Execute_GetMapSize(Owner, MapWidth, MapHeight);
const UMitchellBestCandidate *PointCreator = NewObject<UMitchellBestCandidate>();

View File

@ -171,11 +171,25 @@ UTerrainLayerComponent::UTerrainLayerComponent()
void UTerrainLayerComponent::BeginPlay()
{
Super::BeginPlay();
AActor* Owner = GetOwner();
if (IGameMapInterface* GameMap = Cast<IGameMapInterface>(Owner))
{
GameMap->Execute_GetMapSize(Owner, MapWidth, MapHeight);
TileSetSize = GameMap->Execute_GetMapFieldSize(Owner);
}
else
{
MapWidth = MapHeight = 32;
TileSetSize = 128;
}
SetupTerrainActors();
TArray<int32> Priority;
TArray<FGameplayTag> TerrainData;
TArray<FGameplayTag> TerrainTypes;
for (auto TileSetConfig : TileSetConfigs)
{
TerrainTypes.Add(TileSetConfig.Key);

View File

@ -11,7 +11,7 @@ AGameMapActor::AGameMapActor()
this->RootComponent = SceneComp;
}
void AGameMapActor::GetMapSize_Implementation(float& OutWidth, float& OutHeight)
void AGameMapActor::GetMapSize_Implementation(int32& OutWidth, int32& OutHeight)
{
OutWidth = MapWidth;
OutHeight = MapHeight;
@ -22,7 +22,7 @@ FGameplayTag AGameMapActor::GetTerrainAt_Implementation(const float X, const flo
return TerrainLayer->GetTerrainAt(X, Y);
}
float AGameMapActor::GetMapFieldSize_Implementation()
int32 AGameMapActor::GetMapFieldSize_Implementation()
{
return MapFieldSize;
}

View File

@ -18,7 +18,7 @@ class BUSYRABBIT_API UBusyGameplayLibrary : public UBlueprintFunctionLibrary
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintPure)
static UDataTable* GetGameDataTable(const FString& TableName);
UFUNCTION(BlueprintCallable)

View File

@ -0,0 +1,15 @@
#pragma once
#include "GameplayTagContainer.h"
#include "BusyResourceConfig.generated.h"
USTRUCT(BlueprintType)
struct FBusyResourceConfig : public FTableRowBase
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, DisplayName="备注")
FString Desc;
UPROPERTY(EditAnywhere, DisplayName="物品标签")
FGameplayTagContainer GameplayTags;
};

View File

@ -29,4 +29,8 @@ public:
TObjectPtr<USpineSkeletonAnimationComponent> SpineAnimationComponent;
/*-------------------------------------------------------------------*/
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
FName ResourceName;
};

View File

@ -62,14 +62,9 @@ protected:
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 MapWidth = 32;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 MapHeight = 32;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 TileSetSize = 128;
int32 MapWidth = 32; // 用Owner的Width覆盖
int32 MapHeight = 32; // 用Owner的Height覆盖
int32 TileSetSize = 128; // 用Owner的Size覆盖
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TMap<FGameplayTag, TObjectPtr<UPaperTileSet>> TileSetConfigs;

View File

@ -18,10 +18,10 @@ class IGameMapInterface
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void GetMapSize(float &OutX, float &OutY);
void GetMapSize(int32 &OutX, int32 &OutY);
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
float GetMapFieldSize();
int32 GetMapFieldSize();
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
FGameplayTag GetTerrainAt(const float X, const float Y);
@ -37,9 +37,9 @@ public:
AGameMapActor();
public:
virtual void GetMapSize_Implementation(float& OutWidth, float& OutHeight) override;
virtual void GetMapSize_Implementation(int32& OutWidth, int32& OutHeight) override;
virtual FGameplayTag GetTerrainAt_Implementation(const float X, const float Y) override;
virtual float GetMapFieldSize_Implementation() override;
virtual int32 GetMapFieldSize_Implementation() override;
public:
virtual void BeginPlay() override;
@ -58,11 +58,11 @@ public:
protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly)
float MapWidth = 32;
int32 MapWidth = 32;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
float MapHeight = 32;
int32 MapHeight = 32;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
float MapFieldSize = 128;
int32 MapFieldSize = 128;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)