2025-11-17 15:11:34 +08:00
|
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "DialogueAsset.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "UObject/ObjectSaveContext.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UDialogueConditions::IsConditionMet_Implementation()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDialogueAsset::BeginDialogue()
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentNode = NodeDatas[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FText UDialogueAsset::GetNextNodeText()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CurrentNode->OutputPins.Num() > 0 && CurrentNode->OutputPins[0]->Connections.Num() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
UDialogueRuntimePin* Connection = CurrentNode->OutputPins[0]->Connections[0];
|
|
|
|
|
|
UDialogueRuntimeNode* ConnectionParent = Connection->Parent;
|
|
|
|
|
|
|
|
|
|
|
|
if (ConnectionParent->NodeType == EDialogueNodeType::NPC)
|
|
|
|
|
|
{
|
|
|
|
|
|
//处理下一个对话是npc的情况
|
|
|
|
|
|
for (auto Pin: CurrentNode->OutputPins[0]->Connections)
|
|
|
|
|
|
{
|
|
|
|
|
|
UDialogueRuntimeNode* ConnectionNode = Pin->Parent;
|
|
|
|
|
|
if (ConnectionNode->NodeData->Conditionses.Num() != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
//判断是否符合条件
|
|
|
|
|
|
bool ConditionMet = false;
|
|
|
|
|
|
for (auto Condition: ConnectionNode->NodeData->Conditionses)
|
|
|
|
|
|
{
|
|
|
|
|
|
ConditionMet = ConditionMet || Condition->IsConditionMet();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ConditionMet)
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentNode = ConnectionNode;
|
|
|
|
|
|
return ConnectionNode->NodeData->Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentNode = ConnectionNode;
|
|
|
|
|
|
return ConnectionNode->NodeData->Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (ConnectionParent->NodeType == EDialogueNodeType::Player)
|
|
|
|
|
|
{
|
|
|
|
|
|
//处理下一个对话是玩家选项的情况
|
|
|
|
|
|
TArray<FText> Options;
|
|
|
|
|
|
for (UDialogueRuntimePin* Pin : CurrentNode->OutputPins[0]->Connections)
|
|
|
|
|
|
{
|
|
|
|
|
|
Options.Add(Pin->Parent->NodeData->Text);
|
|
|
|
|
|
}
|
|
|
|
|
|
OnNeedPlayerSelect.Broadcast(Options);
|
|
|
|
|
|
//返回值不变
|
|
|
|
|
|
return CurrentNode->NodeData->Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-11-24 10:58:30 +08:00
|
|
|
|
OnDialogueComplete.Broadcast();
|
2025-11-17 15:11:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
return FText::FromString(TEXT(""));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDialogueAsset::PlayerSelect(int32 index)
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentNode = CurrentNode->OutputPins[0]->Connections[index]->Parent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDialogueAsset::PreSave(FObjectPreSaveContext saveContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OnPreSaveListener)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnPreSaveListener();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|