Halfway through with repair of right-click menus
This commit is contained in:
98
Plugins/UEWingman/Deprecated/StateMachine_AddTransition.h
Normal file
98
Plugins/UEWingman/Deprecated/StateMachine_AddTransition.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "WingServer.h"
|
||||
#include "WingHandler.h"
|
||||
#include "WingFetcher.h"
|
||||
#include "WingUtils.h"
|
||||
#include "Kismet2/KismetEditorUtilities.h"
|
||||
#include "Animation/AnimBlueprint.h"
|
||||
#include "AnimStateNode.h"
|
||||
#include "AnimStateTransitionNode.h"
|
||||
#include "AnimationStateMachineGraph.h"
|
||||
#include "StateMachine_AddTransition.generated.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UCLASS()
|
||||
class UWing_StateMachine_AddTransition : public UObject, public IWingHandler
|
||||
{
|
||||
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="Transition priority order"))
|
||||
int32 Priority = 0;
|
||||
|
||||
UPROPERTY(meta=(Optional, Description="Whether the transition is bidirectional"))
|
||||
bool BBidirectional = false;
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("Add a transition between two states in an animation state machine graph.");
|
||||
}
|
||||
|
||||
virtual void Handle() override
|
||||
{
|
||||
WingFetcher F;
|
||||
UAnimBlueprint* AnimBP = F.Asset(Blueprint).Cast<UAnimBlueprint>();
|
||||
if (!AnimBP) return;
|
||||
|
||||
UAnimationStateMachineGraph* SMGraph = WingUtils::FindStateMachineGraph(AnimBP, Graph);
|
||||
if (!SMGraph)
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: State machine graph '%s' not found in '%s'\n"), *Graph, *WingUtils::FormatName(AnimBP));
|
||||
return;
|
||||
}
|
||||
|
||||
UAnimStateNode* FromStateNode = WingUtils::FindStateByName(SMGraph, FromState);
|
||||
if (!FromStateNode) return;
|
||||
|
||||
UAnimStateNode* ToStateNode = WingUtils::FindStateByName(SMGraph, ToState);
|
||||
if (!ToStateNode) return;
|
||||
|
||||
// Create transition node
|
||||
UAnimStateTransitionNode* TransNode = NewObject<UAnimStateTransitionNode>(SMGraph);
|
||||
TransNode->CreateNewGuid();
|
||||
TransNode->PostPlacedNewNode();
|
||||
TransNode->AllocateDefaultPins();
|
||||
|
||||
// Position between the two states
|
||||
TransNode->NodePosX = (FromStateNode->NodePosX + ToStateNode->NodePosX) / 2;
|
||||
TransNode->NodePosY = (FromStateNode->NodePosY + ToStateNode->NodePosY) / 2;
|
||||
|
||||
SMGraph->AddNode(TransNode, false, false);
|
||||
TransNode->SetFlags(RF_Transactional);
|
||||
|
||||
// Connect: FromState output -> Transition input, Transition output -> ToState input
|
||||
TransNode->CreateConnections(FromStateNode, ToStateNode);
|
||||
|
||||
// Set optional properties
|
||||
TransNode->CrossfadeDuration = CrossfadeDuration;
|
||||
TransNode->PriorityOrder = Priority;
|
||||
TransNode->Bidirectional = BBidirectional;
|
||||
|
||||
// Compile
|
||||
FKismetEditorUtilities::CompileBlueprint(AnimBP);
|
||||
|
||||
UWingServer::Printf(TEXT("Created transition %s -> %s: %s\n"),
|
||||
*FromState, *ToState, *WingUtils::FormatName(TransNode));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user