Halfway through with repair of right-click menus
This commit is contained in:
81
Plugins/UEWingman/Deprecated/StateMachine_RemoveState.h
Normal file
81
Plugins/UEWingman/Deprecated/StateMachine_RemoveState.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#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_RemoveState.generated.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UCLASS()
|
||||
class UWing_StateMachine_RemoveState : public UObject, public IWingHandler
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(meta=(Description="Path to the state machine graph, e.g. /Game/MyAnimBP,graph:StateMachine"))
|
||||
FString Graph;
|
||||
|
||||
UPROPERTY(meta=(Description="Name of the state to remove"))
|
||||
FString StateName;
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("Remove a state and its connected transitions from an animation state machine graph.");
|
||||
}
|
||||
|
||||
virtual void Handle() override
|
||||
{
|
||||
// Fetch the state machine graph via WingFetcher
|
||||
WingFetcher F;
|
||||
F.Walk(Graph);
|
||||
if (!F.Ok()) return;
|
||||
|
||||
UAnimationStateMachineGraph* SMGraph = F.Cast<UAnimationStateMachineGraph>();
|
||||
if (!SMGraph) return;
|
||||
|
||||
// Find the owning AnimBlueprint for compile/save
|
||||
UBlueprint* BP = Cast<UBlueprint>(SMGraph->GetOuter()->GetOuter());
|
||||
if (!BP)
|
||||
{
|
||||
UWingServer::Print(TEXT("ERROR: Could not find owning blueprint.\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the state node
|
||||
UAnimStateNode* StateNode = WingUtils::FindStateByName(SMGraph, StateName);
|
||||
if (!StateNode) return;
|
||||
|
||||
// Collect and remove transitions connected to this state
|
||||
int32 RemovedTransitions = 0;
|
||||
for (UEdGraphNode* Node : TArray<UEdGraphNode*>(SMGraph->Nodes))
|
||||
{
|
||||
UAnimStateTransitionNode* TransNode = Cast<UAnimStateTransitionNode>(Node);
|
||||
if (!TransNode) continue;
|
||||
if (TransNode->GetPreviousState() != StateNode && TransNode->GetNextState() != StateNode) continue;
|
||||
TransNode->BreakAllNodeLinks();
|
||||
SMGraph->RemoveNode(TransNode);
|
||||
RemovedTransitions++;
|
||||
}
|
||||
|
||||
// Remove the state
|
||||
StateNode->BreakAllNodeLinks();
|
||||
SMGraph->RemoveNode(StateNode);
|
||||
|
||||
// Compile
|
||||
FKismetEditorUtilities::CompileBlueprint(BP);
|
||||
|
||||
UWingServer::Printf(TEXT("Removed state %s and %d transition(s).\n"),
|
||||
*WingUtils::FormatName(StateNode), RemovedTransitions);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user