Guest User

Untitled

a guest
Sep 30th, 2019
219
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ASpineActor * UPAndBEditorUtilityWidget::CreateSpineBlueprint()
  2. {
  3. // Assign stuff that was selected
  4. IContentBrowserSingleton& ContentBrowser = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser").Get();
  5. static TArray <FAssetData> SelectedAssets;
  6. ContentBrowser.GetSelectedAssets(SelectedAssets);
  7.  
  8. FString AssetName = FString("NameNotFound");
  9. FString AssetPath = FString("../../../Poppy and Buddy/Content/");
  10. FString PackagePath = FString("/Game/Poppy and Buddy/SpineActors");
  11.  
  12. USpineSkeletonDataAsset * SpineSkeleton = nullptr;
  13. USpineAtlasAsset * SpineAtlas = nullptr;
  14.  
  15. for (FAssetData Data : SelectedAssets) {
  16. if (Data.GetClass() == USpineSkeletonDataAsset::StaticClass()) {
  17. SpineSkeleton = (USpineSkeletonDataAsset *)Data.GetAsset();
  18. }
  19. if (Data.GetClass() == USpineAtlasAsset::StaticClass()) {
  20. SpineAtlas = (USpineAtlasAsset *)Data.GetAsset();
  21. }
  22.  
  23. FString Left;
  24. FString Right;
  25. Data.AssetName.ToString().Split(TEXT("-"), &Left, &Right, ESearchCase::IgnoreCase, ESearchDir::FromEnd);
  26. AssetName = Left + FString(TEXT("-spine"));
  27. PackagePath = Data.PackageName.ToString(); // +FString(TEXT("-spine"));
  28. Data.PackageName.ToString().Split(TEXT("/"), &Left, &Right, ESearchCase::IgnoreCase, ESearchDir::FromEnd);
  29. AssetPath = Data.PackageName.ToString();
  30. }
  31.  
  32. UE_LOG(LogTemp, Warning, TEXT("[Package] AssetName: %s"), *AssetName);
  33. UE_LOG(LogTemp, Warning, TEXT("[Package] AssetPath: %s"), *AssetPath);
  34. UE_LOG(LogTemp, Warning, TEXT("[Package] PackagePath: %s"), *PackagePath);
  35.  
  36. UPackage *Package = CreatePackage(nullptr, *PackagePath);
  37. ASpineActor * SpineActor = NewObject<ASpineActor>(Package, ASpineActor::StaticClass(), *AssetName, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone);
  38.  
  39. SpineActor->SpineSkeleton = SpineSkeleton;
  40. SpineActor->SpineAtlas = SpineAtlas;
  41.  
  42. FAssetRegistryModule::AssetCreated(SpineActor);
  43. SpineActor->MarkPackageDirty();
  44.  
  45. FString FilePath = FString::Printf(TEXT("%s%s%s"), *AssetPath, *AssetName, *FPackageName::GetAssetPackageExtension());
  46. // bool bSuccess = UPackage::SavePackage(Package, SpineActor, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *FilePath);
  47. return SpineActor;
  48. }
RAW Paste Data