void UAnimationGraphSchema::SpawnNodeFromAsset(UAnimationAsset* Asset, const FVector2D& GraphPosition, UEdGraph* Graph, UEdGraphPin* PinIfAvailable) { check(Graph); check(Graph->GetSchema()->IsA(UAnimationGraphSchema::StaticClass())); check(Asset); UAnimBlueprint* AnimBlueprint = Cast<UAnimBlueprint>(FBlueprintEditorUtils::FindBlueprintForGraph(Graph)); const bool bSkelMatch = (AnimBlueprint != NULL) && (AnimBlueprint->TargetSkeleton == Asset->GetSkeleton()); const bool bTypeMatch = (PinIfAvailable == NULL) || UAnimationGraphSchema::IsLocalSpacePosePin(PinIfAvailable->PinType); const bool bDirectionMatch = (PinIfAvailable == NULL) || (PinIfAvailable->Direction == EGPD_Input); if (bSkelMatch && bTypeMatch && bDirectionMatch) { FEdGraphSchemaAction_K2NewNode Action; if (UAnimSequence* Sequence = Cast<UAnimSequence>(Asset)) { UAnimGraphNode_SequencePlayer* PlayerNode = NewObject<UAnimGraphNode_SequencePlayer>(); PlayerNode->Node.Sequence = Sequence; Action.NodeTemplate = PlayerNode; } else if (UBlendSpaceBase* BlendSpace = Cast<UBlendSpaceBase>(Asset)) { if (IsAimOffsetBlendSpace(BlendSpace)) { UAnimGraphNode_RotationOffsetBlendSpace* PlayerNode = NewObject<UAnimGraphNode_RotationOffsetBlendSpace>(); PlayerNode->Node.BlendSpace = BlendSpace; Action.NodeTemplate = PlayerNode; } else { UAnimGraphNode_BlendSpacePlayer* PlayerNode = NewObject<UAnimGraphNode_BlendSpacePlayer>(); PlayerNode->Node.BlendSpace = BlendSpace; Action.NodeTemplate = PlayerNode; } } else if (UAnimComposite* Composite = Cast<UAnimComposite>(Asset)) { UAnimGraphNode_SequencePlayer* PlayerNode = NewObject<UAnimGraphNode_SequencePlayer>(); PlayerNode->Node.Sequence = Composite; Action.NodeTemplate = PlayerNode; } else { //unknown type return; } Action.PerformAction(Graph, PinIfAvailable, GraphPosition); } }
FReply FKismetVariableDragDropAction::DroppedOnPin(FVector2D ScreenPosition, FVector2D GraphPosition) { UEdGraphPin* TargetPin = GetHoveredPin(); if (TargetPin != NULL) { if (const UEdGraphSchema_K2* Schema = CastChecked<const UEdGraphSchema_K2>(TargetPin->GetSchema())) { UProperty* VariableProperty = GetVariableProperty(); if(CanVariableBeDropped(VariableProperty, *TargetPin->GetOwningNode()->GetGraph())) { const bool bIsRead = TargetPin->Direction == EGPD_Input; const UBlueprint* Blueprint = FBlueprintEditorUtils::FindBlueprintForNode(TargetPin->GetOwningNode()); const bool bReadOnlyProperty = FBlueprintEditorUtils::IsPropertyReadOnlyInCurrentBlueprint(Blueprint, VariableProperty); const bool bCanWriteIfNeeded = bIsRead || !bReadOnlyProperty; FEdGraphPinType VariablePinType; Schema->ConvertPropertyToPinType(VariableProperty, VariablePinType); const bool bTypeMatch = Schema->ArePinTypesCompatible(VariablePinType, TargetPin->PinType); if (bTypeMatch && bCanWriteIfNeeded) { FEdGraphSchemaAction_K2NewNode Action; UK2Node_Variable* VarNode = bIsRead ? (UK2Node_Variable*)NewObject<UK2Node_VariableGet>() : (UK2Node_Variable*)NewObject<UK2Node_VariableSet>(); Action.NodeTemplate = VarNode; UBlueprint* DropOnBlueprint = FBlueprintEditorUtils::FindBlueprintForGraph(TargetPin->GetOwningNode()->GetGraph()); UEdGraphSchema_K2::ConfigureVarNode(VarNode, VariableName, VariableSource.Get(), DropOnBlueprint); Action.PerformAction(TargetPin->GetOwningNode()->GetGraph(), TargetPin, GraphPosition); } } } } return FReply::Handled(); }