93 lines
2.8 KiB
C++
93 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "MCPServer.h"
|
|
#include "MCPHandler.h"
|
|
#include "MCPFetcher.h"
|
|
#include "MCPUtils.h"
|
|
#include "Kismet2/KismetEditorUtilities.h"
|
|
#include "Animation/AnimBlueprint.h"
|
|
#include "AnimStateTransitionNode.h"
|
|
#include "AnimationStateMachineGraph.h"
|
|
#include "StateMachine_SetTransitionRule.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UMCP_StateMachine_SetTransitionRule : public UObject, public IMCPHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Animation Blueprint package path"))
|
|
FString Blueprint;
|
|
|
|
UPROPERTY(meta=(Description="State machine graph name"))
|
|
FString Graph;
|
|
|
|
UPROPERTY(meta=(Description="Name of the source state"))
|
|
FString FromState;
|
|
|
|
UPROPERTY(meta=(Description="Name of the target state"))
|
|
FString ToState;
|
|
|
|
UPROPERTY(meta=(Optional, Description="Crossfade duration in seconds"))
|
|
float CrossfadeDuration = 0.0f;
|
|
|
|
UPROPERTY(meta=(Optional, Description="Blend mode (as integer enum value)"))
|
|
int32 BlendMode = 0;
|
|
|
|
UPROPERTY(meta=(Optional, Description="Transition priority order"))
|
|
int32 PriorityOrder = 0;
|
|
|
|
UPROPERTY(meta=(Optional, Description="Logic type (as integer enum value)"))
|
|
int32 LogicType = 0;
|
|
|
|
UPROPERTY(meta=(Optional, Description="Whether the transition is bidirectional"))
|
|
bool BBidirectional = false;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Update properties on an existing transition between two states in an animation state machine.");
|
|
}
|
|
|
|
virtual void Handle() override
|
|
{
|
|
MCPFetcher F;
|
|
UAnimBlueprint* AnimBP = F.Asset(Blueprint).Cast<UAnimBlueprint>();
|
|
if (!AnimBP) return;
|
|
|
|
UAnimationStateMachineGraph* SMGraph = MCPUtils::FindStateMachineGraph(AnimBP, Graph);
|
|
if (!SMGraph)
|
|
{
|
|
UMCPServer::Printf(TEXT("ERROR: State machine graph '%s' not found in '%s'\n"), *Graph, *MCPUtils::FormatName(AnimBP));
|
|
return;
|
|
}
|
|
|
|
UAnimStateTransitionNode* TransNode = MCPUtils::FindTransition(SMGraph, FromState, ToState);
|
|
if (!TransNode)
|
|
{
|
|
UMCPServer::Printf(TEXT("ERROR: Transition from '%s' to '%s' not found in graph '%s'\n"),
|
|
*FromState, *ToState, *Graph);
|
|
return;
|
|
}
|
|
|
|
// Apply properties
|
|
TransNode->CrossfadeDuration = CrossfadeDuration;
|
|
TransNode->BlendMode = (EAlphaBlendOption)BlendMode;
|
|
TransNode->PriorityOrder = PriorityOrder;
|
|
TransNode->LogicType = (ETransitionLogicType::Type)LogicType;
|
|
TransNode->Bidirectional = BBidirectional;
|
|
|
|
// Compile and save
|
|
FKismetEditorUtilities::CompileBlueprint(AnimBP);
|
|
MCPUtils::SaveBlueprintPackage(AnimBP);
|
|
|
|
UMCPServer::Printf(TEXT("Updated transition %s -> %s: %s\n"),
|
|
*FromState, *ToState, *MCPUtils::FormatName(TransNode));
|
|
}
|
|
};
|