void FLightmapCustomNodeBuilder::RefreshLightmapItems() { LightmapItems.Empty(); FWorldContext& Context = GEditor->GetEditorWorldContext(); UWorld* World = Context.World(); if ( World ) { TArray<UTexture2D*> LightMapsAndShadowMaps; World->GetLightMapsAndShadowMaps(World->GetCurrentLevel(), LightMapsAndShadowMaps); for ( auto ObjIt = LightMapsAndShadowMaps.CreateConstIterator(); ObjIt; ++ObjIt ) { UTexture2D* CurrentObject = *ObjIt; if (CurrentObject) { FAssetData AssetData = FAssetData(CurrentObject); const uint32 ThumbnailResolution = 64; TSharedPtr<FAssetThumbnail> LightMapThumbnail = MakeShareable( new FAssetThumbnail( AssetData, ThumbnailResolution, ThumbnailResolution, ThumbnailPool ) ); TSharedPtr<FLightmapItem> NewItem = MakeShareable( new FLightmapItem(CurrentObject->GetPathName(), LightMapThumbnail) ); LightmapItems.Add(NewItem); } } } if ( LightmapListView.IsValid() ) { LightmapListView->RequestListRefresh(); } }
bool FPersonaAssetFamily::IsAssetCompatible(const FAssetData& InAssetData) const { UClass* Class = InAssetData.GetClass(); if (Class) { if (Class->IsChildOf<USkeleton>()) { return FAssetData(Skeleton.Get()) == InAssetData; } else if (Class->IsChildOf<UAnimationAsset>() || Class->IsChildOf<USkeletalMesh>()) { const FString* TargetSkeleton = InAssetData.TagsAndValues.Find("Skeleton"); if (TargetSkeleton) { return *TargetSkeleton == FAssetData(Skeleton.Get()).GetExportTextName(); } } else if (Class->IsChildOf<UAnimBlueprint>()) { const FString* TargetSkeleton = InAssetData.TagsAndValues.Find("TargetSkeleton"); if (TargetSkeleton) { return *TargetSkeleton == FAssetData(Skeleton.Get()).GetExportTextName(); } } } return false; }
bool SPropertyEditorAsset::OnAssetDraggedOver( const UObject* InObject ) const { if (CanEdit() && InObject != NULL && InObject->IsA(ObjectClass)) { // Check against custom asset filter if (!OnShouldFilterAsset.IsBound() || !OnShouldFilterAsset.Execute(FAssetData(InObject))) { return CanSetBasedOnCustomClasses( FAssetData(InObject) ); } } return false; }
void USkeleton::CollectAnimationNotifies() { // need to verify if these pose is used by anybody else FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")); // @Todo : remove it when we know the asset registry is updated // meanwhile if you remove this, this will miss the links //AnimationNotifies.Empty(); TArray<FAssetData> AssetList; AssetRegistryModule.Get().GetAssetsByClass(UAnimSequenceBase::StaticClass()->GetFName(), AssetList, true); #if WITH_EDITOR // do not clear AnimationNotifies. We can't remove old ones yet. FString CurrentSkeletonName = FAssetData(this).GetExportTextName(); for (auto Iter = AssetList.CreateConstIterator(); Iter; ++Iter) { const FAssetData& Asset = *Iter; const FString* SkeletonValue = Asset.TagsAndValues.Find(TEXT("Skeleton")); if (SkeletonValue && *SkeletonValue == CurrentSkeletonName) { if (const FString* Value = Asset.TagsAndValues.Find(USkeleton::AnimNotifyTag)) { TArray<FString> NotifyList; Value->ParseIntoArray(&NotifyList, &AnimNotifyTagDelimiter, true); for (auto NotifyIter = NotifyList.CreateConstIterator(); NotifyIter; ++NotifyIter) { FString NotifyName = *NotifyIter; AddNewAnimationNotify(FName(*NotifyName)); } } } } #endif }
AActor* FActorFactoryAssetProxy::AddActorFromSelection( UClass* ActorClass, const FVector* ActorLocation, bool SelectActor, EObjectFlags ObjectFlags, UActorFactory* ActorFactory, const FName Name ) { check( ActorClass != NULL ); if( !ActorFactory ) { // Look for an actor factory capable of creating actors of the actors type. ActorFactory = GEditor->FindActorFactoryForActorClass( ActorClass ); } AActor* Result = NULL; FText ErrorMessage; if ( ActorFactory ) { UObject* TargetObject = GEditor->GetSelectedObjects()->GetTop<UObject>(); if( TargetObject && ActorFactory->CanCreateActorFrom( FAssetData(TargetObject), ErrorMessage ) ) { // Attempt to add the actor Result = PrivateAddActor( TargetObject, ActorFactory, SelectActor, ObjectFlags ); } } return Result; }
void OpenMapAndFocusActor(const TArray<FString>& Args) { if ( Args.Num() < 2 ) { UE_LOG(LogConsoleResponse, Display, TEXT("Automate.OpenMapAndFocusActor failed\n")); return; } FString AssetPath = Args[0]; FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")); TArray<FAssetData> AllAssets; AssetRegistryModule.Get().GetAssetsByPackageName(*AssetPath, AllAssets); if ( AllAssets.Num() > 0 ) { bool bIsWorlAlreadyOpened = false; if ( UWorld* EditorWorld = GEditor->GetEditorWorldContext().World() ) { if ( FAssetData(EditorWorld).PackageName == AllAssets[0].PackageName ) { bIsWorlAlreadyOpened = true; } } if ( !bIsWorlAlreadyOpened ) { UObject* ObjectToEdit = AllAssets[0].GetAsset(); if ( ObjectToEdit ) { GEditor->EditObject(ObjectToEdit); } } } if ( UWorld* EditorWorld = GEditor->GetEditorWorldContext().World() ) { AActor* ActorToFocus = nullptr; for ( int32 LevelIndex=0; LevelIndex < EditorWorld->GetNumLevels(); LevelIndex++ ) { ULevel* Level = EditorWorld->GetLevel(LevelIndex); ActorToFocus = static_cast<AActor*>( FindObjectWithOuter(Level, AActor::StaticClass(), *Args[1]) ); if ( ActorToFocus ) { break; } } if ( ActorToFocus ) { GEditor->SelectNone(/*bNoteSelectionChange=*/ false, false, false); GEditor->SelectActor(ActorToFocus, true, true); GEditor->NoteSelectionChange(); const bool bActiveViewportOnly = false; GEditor->MoveViewportCamerasToActor(*ActorToFocus, bActiveViewportOnly); } } }
FReply SAssetPicker::OnNoneButtonClicked() { OnAssetSelected.ExecuteIfBound(FAssetData()); if (AssetViewPtr.IsValid()) { AssetViewPtr->ClearSelection(true); } return FReply::Handled(); }
static void FindAssets(const USkeleton* InSkeleton, TArray<FAssetData>& OutAssetData, FName SkeletonTag) { FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry"); FARFilter Filter; Filter.bRecursiveClasses = true; Filter.ClassNames.Add(AssetType::StaticClass()->GetFName()); Filter.TagsAndValues.Add(SkeletonTag, FAssetData(InSkeleton).GetExportTextName()); AssetRegistryModule.Get().GetAssets(Filter, OutAssetData); }
void UEdGraphNode_Reference::SetReferenceNodeCollapsed(const FIntPoint& NodeLoc, int32 InNumReferencesExceedingMax) { NodePosX = NodeLoc.X; NodePosY = NodeLoc.Y; PackageNames.Empty(); NodeComment = FText::Format(LOCTEXT("ReferenceNodeCollapsedMessage", "{0} other nodes"), FText::AsNumber(InNumReferencesExceedingMax)).ToString(); NodeTitle = LOCTEXT("ReferenceNodeCollapsedTitle", "Collapsed nodes"); CacheAssetData(FAssetData()); AllocateDefaultPins(); }
static bool CanCreateAnimBlueprint(const FAssetData& Skeleton, UClass const * ParentClass) { if (Skeleton.IsValid() && ParentClass != NULL) { if (UAnimBlueprintGeneratedClass const * GeneratedParent = Cast<const UAnimBlueprintGeneratedClass>(ParentClass)) { if (Skeleton.GetExportTextName() != FAssetData(GeneratedParent->GetTargetSkeleton()).GetExportTextName()) { return false; } } } return true; }
void FContentBrowserSingleton::SyncBrowserToAssets(const TArray<UObject*>& AssetList, bool bAllowLockedBrowsers) { // Convert UObject* array to FAssetData array TArray<FAssetData> AssetDataList; for (int32 AssetIdx = 0; AssetIdx < AssetList.Num(); ++AssetIdx) { if ( AssetList[AssetIdx] ) { AssetDataList.Add( FAssetData(AssetList[AssetIdx]) ); } } SyncBrowserToAssets(AssetDataList, bAllowLockedBrowsers); }
const UClass* FClassIconFinder::GetIconClassForBlueprint(const UBlueprint* InBlueprint) { if ( !InBlueprint ) { return nullptr; } // If we're loaded and have a generated class, just use that if ( const UClass* GeneratedClass = Cast<UClass>(InBlueprint->GeneratedClass) ) { return GeneratedClass; } // We don't have a generated class, so instead try and use the parent class from our meta-data return GetIconClassForAssetData(FAssetData(InBlueprint)); }
void FAssetTypeActions_SoundWave::FillVoiceMenu(FMenuBuilder& MenuBuilder, TArray<TWeakObjectPtr<USoundWave>> Objects) { TArray<const UClass*> AllowedClasses; AllowedClasses.Add(UDialogueVoice::StaticClass()); TSharedRef<SWidget> VoicePicker = PropertyCustomizationHelpers::MakeAssetPickerWithMenu( FAssetData(), false, AllowedClasses, PropertyCustomizationHelpers::GetNewAssetFactoriesForClasses(AllowedClasses), FOnShouldFilterAsset(), FOnAssetSelected::CreateSP(this, &FAssetTypeActions_SoundWave::ExecuteCreateDialogueWave, Objects), FSimpleDelegate()); MenuBuilder.AddWidget(VoicePicker, FText::GetEmpty(), false); }
// Find all related sprites (not including self) void FSpriteEditorViewportClient::UpdateRelatedSpritesList() { UPaperSprite* Sprite = GetSpriteBeingEdited(); UTexture2D* Texture = Sprite->GetSourceTexture(); if (Texture != nullptr) { FARFilter Filter; Filter.ClassNames.Add(UPaperSprite::StaticClass()->GetFName()); const FString TextureString = FAssetData(Texture).GetExportTextName(); const FName SourceTexturePropName(TEXT("SourceTexture")); Filter.TagsAndValues.Add(SourceTexturePropName, TextureString); FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry"); TArray<FAssetData> SpriteAssetData; AssetRegistryModule.Get().GetAssets(Filter, SpriteAssetData); FAssetData CurrentAssetData(Sprite); RelatedSprites.Empty(); for (int32 i = 0; i < SpriteAssetData.Num(); ++i) { FAssetData& SpriteAsset = SpriteAssetData[i]; if (SpriteAsset == Sprite) { continue; } const FString* SourceUVString = SpriteAsset.TagsAndValues.Find("SourceUV"); const FString* SourceDimensionString = SpriteAsset.TagsAndValues.Find("SourceDimension"); FVector2D SourceUV, SourceDimension; if (SourceUVString != nullptr && SourceDimensionString != nullptr) { if (SourceUV.InitFromString(*SourceUVString) && SourceDimension.InitFromString(*SourceDimensionString)) { FRelatedSprite RelatedSprite; RelatedSprite.AssetData = SpriteAsset; RelatedSprite.SourceUV = SourceUV; RelatedSprite.SourceDimension = SourceDimension; RelatedSprites.Add(RelatedSprite); } } } } }
void SPropertyEditorAsset::OnUse() { // Load selected assets FEditorDelegates::LoadSelectedAssetsIfNeeded.Broadcast(); // try to get a selected object of our class UObject* Selection = NULL; if (ObjectClass && ObjectClass->IsChildOf(AActor::StaticClass())) { Selection = GEditor->GetSelectedActors()->GetTop(ObjectClass); } else if (ObjectClass) { // Get the first material selected Selection = GEditor->GetSelectedObjects()->GetTop(ObjectClass); } if (PropertyEditor.IsValid()) { if (Selection && CanAssetBeAssigned(Selection)) { PropertyEditor->GetPropertyHandle()->SetObjectValueFromSelection(); } } else { // Check against custom asset filter if (Selection != NULL && OnShouldFilterAsset.IsBound() && OnShouldFilterAsset.Execute(FAssetData(Selection))) { Selection = NULL; } if( Selection ) { SetValue( Selection ); } } }
void FSkeletonEditor::InitSkeletonEditor(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost>& InitToolkitHost, USkeleton* InSkeleton) { Skeleton = InSkeleton; FPersonaModule& PersonaModule = FModuleManager::LoadModuleChecked<FPersonaModule>("Persona"); PersonaToolkit = PersonaModule.CreatePersonaToolkit(InSkeleton); PersonaToolkit->GetPreviewScene()->SetDefaultAnimationMode(EPreviewSceneDefaultAnimationMode::ReferencePose); TSharedRef<IAssetFamily> AssetFamily = PersonaModule.CreatePersonaAssetFamily(InSkeleton); AssetFamily->RecordAssetOpened(FAssetData(InSkeleton)); FSkeletonTreeArgs SkeletonTreeArgs(OnPostUndo); SkeletonTreeArgs.OnObjectSelected = FOnObjectSelected::CreateSP(this, &FSkeletonEditor::HandleObjectSelected); SkeletonTreeArgs.PreviewScene = PersonaToolkit->GetPreviewScene(); ISkeletonEditorModule& SkeletonEditorModule = FModuleManager::GetModuleChecked<ISkeletonEditorModule>("SkeletonEditor"); SkeletonTree = SkeletonEditorModule.CreateSkeletonTree(PersonaToolkit->GetSkeleton(), PersonaToolkit->GetMesh(), SkeletonTreeArgs); const bool bCreateDefaultStandaloneMenu = true; const bool bCreateDefaultToolbar = true; const TSharedRef<FTabManager::FLayout> DummyLayout = FTabManager::NewLayout("NullLayout")->AddArea(FTabManager::NewPrimaryArea()); FAssetEditorToolkit::InitAssetEditor(Mode, InitToolkitHost, SkeletonEditorAppIdentifier, DummyLayout, bCreateDefaultStandaloneMenu, bCreateDefaultToolbar, InSkeleton); BindCommands(); AddApplicationMode( SkeletonEditorModes::SkeletonEditorMode, MakeShareable(new FSkeletonEditorMode(SharedThis(this), SkeletonTree.ToSharedRef()))); SetCurrentMode(SkeletonEditorModes::SkeletonEditorMode); // set up our editor mode check(AssetEditorModeManager); AssetEditorModeManager->SetDefaultMode(FPersonaEditModes::SkeletonSelection); ExtendMenu(); ExtendToolbar(); RegenerateMenusAndToolbars(); }
void SSpriteList::RebuildWidget(UTexture2D* NewTextureFilter) { FContentBrowserModule& ContentBrowserModule = FModuleManager::Get().LoadModuleChecked<FContentBrowserModule>(TEXT("ContentBrowser")); // Configure filter for asset picker FAssetPickerConfig Config; //Config.Filter.bRecursiveClasses = true; Config.Filter.ClassNames.Add(UPaperSprite::StaticClass()->GetFName()); Config.ThumbnailScale = 0.0f; Config.InitialAssetViewType = EAssetViewType::Tile; Config.SyncToAssetsDelegates.Add(&SyncToAssetsDelegate); if (NewTextureFilter != nullptr) { const FString TextureString = FAssetData(NewTextureFilter).GetExportTextName(); const FName SourceTexturePropName(TEXT("SourceTexture")); //@TODO: Protected: GET_MEMBER_NAME_CHECKED(UPaperSprite, SourceTexture); Config.Filter.TagsAndValues.Add(SourceTexturePropName, TextureString); // Ignore the source texture since we're filtering against it AssetRegistryTagsToIgnore.Add(SourceTexturePropName); } else { AssetRegistryTagsToIgnore.Empty(); } // Configure response to click and double-click Config.OnAssetSelected = FOnAssetSelected::CreateSP(this, &SSpriteList::OnSpriteSelected); Config.OnAssetDoubleClicked = FOnAssetDoubleClicked::CreateSP(this, &SSpriteList::OnSpriteDoubleClicked); //Config.OnGetAssetContextMenu = FOnGetAssetContextMenu::CreateSP(this, &SSpriteList::OnGetAssetContextMenu); Config.OnAssetTagWantsToBeDisplayed = FOnShouldDisplayAssetTag::CreateSP(this, &SSpriteList::CanShowColumnForAssetRegistryTag); Config.bFocusSearchBoxWhenOpened = false; this->ChildSlot [ ContentBrowserModule.Get().CreateAssetPicker(Config) ]; }
void UEdGraphNode_Reference::CacheAssetData(const FAssetData& AssetData) { if ( AssetData.IsValid() ) { bUsesThumbnail = true; CachedAssetData = AssetData; } else { CachedAssetData = FAssetData(); bUsesThumbnail = false; if ( PackageNames.Num() == 1 ) { const FString PackageNameStr = PackageNames[0].ToString(); if ( FPackageName::IsValidLongPackageName(PackageNameStr, true) ) { if ( PackageNameStr.StartsWith(TEXT("/Script")) ) { CachedAssetData.AssetClass = FName(TEXT("Code")); } else { const FString PotentiallyMapFilename = FPackageName::LongPackageNameToFilename(PackageNameStr, FPackageName::GetMapPackageExtension()); const bool bIsMapPackage = FPlatformFileManager::Get().GetPlatformFile().FileExists(*PotentiallyMapFilename); if ( bIsMapPackage ) { CachedAssetData.AssetClass = FName(TEXT("World")); } } } } else { CachedAssetData.AssetClass = FName(TEXT("Multiple Nodes")); } } }
void SPropertyEditorAsset::OnUse() { // Use the property editor path if it is valid and there is no custom filtering required if(PropertyEditor.IsValid() && !OnShouldFilterAsset.IsBound() && CustomClassFilters.Num() == 0) { PropertyEditor->GetPropertyHandle()->SetObjectValueFromSelection(); } else { // Load selected assets FEditorDelegates::LoadSelectedAssetsIfNeeded.Broadcast(); // try to get a selected object of our class UObject* Selection = NULL; if( ObjectClass && ObjectClass->IsChildOf( AActor::StaticClass() ) ) { Selection = GEditor->GetSelectedActors()->GetTop( ObjectClass ); } else if( ObjectClass ) { // Get the first material selected Selection = GEditor->GetSelectedObjects()->GetTop( ObjectClass ); } // Check against custom asset filter if (Selection != NULL && OnShouldFilterAsset.IsBound() && OnShouldFilterAsset.Execute(FAssetData(Selection))) { Selection = NULL; } if( Selection ) { SetValue( Selection ); } } }
void SPropertyEditorAsset::OnPaste() { FString DestPath; FPlatformMisc::ClipboardPaste(DestPath); if(DestPath == TEXT("None")) { SetValue(NULL); } else { UObject* Object = LoadObject<UObject>(NULL, *DestPath); if(Object && Object->IsA(ObjectClass)) { // Check against custom asset filter if (!OnShouldFilterAsset.IsBound() || !OnShouldFilterAsset.Execute(FAssetData(Object))) { SetValue(Object); } } } }
void FPersonaAssetFamily::FindAssetsOfType(UClass* InAssetClass, TArray<FAssetData>& OutAssets) const { if (InAssetClass) { if (InAssetClass->IsChildOf<USkeleton>()) { // we should always have a skeleton here, this asset family is based on it OutAssets.Add(FAssetData(Skeleton.Get())); } else if (InAssetClass->IsChildOf<UAnimationAsset>()) { FindAssets<UAnimationAsset>(Skeleton.Get(), OutAssets, "Skeleton"); } else if (InAssetClass->IsChildOf<USkeletalMesh>()) { FindAssets<USkeletalMesh>(Skeleton.Get(), OutAssets, "Skeleton"); } else if (InAssetClass->IsChildOf<UAnimBlueprint>()) { FindAssets<UAnimBlueprint>(Skeleton.Get(), OutAssets, "TargetSkeleton"); } } }
void SFlipbookKeyframeWidget::OpenSpritePickerMenu(FMenuBuilder& MenuBuilder) { const bool bAllowClear = true; TArray<const UClass*> AllowedClasses; AllowedClasses.Add(UPaperSprite::StaticClass()); FAssetData CurrentAssetData; if (const FPaperFlipbookKeyFrame* KeyFrame = GetKeyFrameData()) { CurrentAssetData = FAssetData(KeyFrame->Sprite); } TSharedRef<SWidget> AssetPickerWidget = PropertyCustomizationHelpers::MakeAssetPickerWithMenu(CurrentAssetData, bAllowClear, AllowedClasses, PropertyCustomizationHelpers::GetNewAssetFactoriesForClasses(AllowedClasses), FOnShouldFilterAsset(), FOnAssetSelected::CreateSP(this, &SFlipbookKeyframeWidget::OnAssetSelected), FSimpleDelegate::CreateSP(this, &SFlipbookKeyframeWidget::CloseMenu)); MenuBuilder.AddWidget(AssetPickerWidget, FText::GetEmpty(), /*bNoIndent=*/ true); }
USkeletalMesh* USkeleton::GetPreviewMesh(bool bFindIfNotSet) { USkeletalMesh* PreviewMesh = PreviewSkeletalMesh.Get(); if(!PreviewMesh) { // if preview mesh isn't loaded, see if we have set FStringAssetReference PreviewMeshStringRef = PreviewSkeletalMesh.ToStringReference(); // load it since now is the time to load if (!PreviewMeshStringRef.ToString().IsEmpty()) { PreviewMesh = Cast<USkeletalMesh>(StaticLoadObject(USkeletalMesh::StaticClass(), NULL, *PreviewMeshStringRef.ToString(), NULL, LOAD_None, NULL)); } // if not existing, and if bFindIfNotExisting is true, then try find one if (!PreviewMesh && bFindIfNotSet) { FARFilter Filter; Filter.ClassNames.Add(USkeletalMesh::StaticClass()->GetFName()); FString SkeletonString = FAssetData(this).GetExportTextName(); Filter.TagsAndValues.Add(GET_MEMBER_NAME_CHECKED(USkeletalMesh, Skeleton), SkeletonString); TArray<FAssetData> AssetList; FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")); AssetRegistryModule.Get().GetAssets(Filter, AssetList); if(AssetList.Num() > 0) { SetPreviewMesh( Cast<USkeletalMesh>(AssetList[0].GetAsset()), false ); // update PreviewMesh PreviewMesh = PreviewSkeletalMesh.Get(); } } } return PreviewMesh; }
void FAnimationTrackEditor::BuildObjectBindingContextMenu(FMenuBuilder& MenuBuilder, const FGuid& ObjectBinding, const UClass* ObjectClass) { if (ObjectClass->IsChildOf(ASkeletalMeshActor::StaticClass())) { const TSharedPtr<ISequencer> ParentSequencer = GetSequencer(); USkeleton* Skeleton = AcquireSkeletonFromObjectGuid(ObjectBinding); if (Skeleton) { // Load the asset registry module FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")); // Collect a full list of assets with the specified class TArray<FAssetData> AssetDataList; AssetRegistryModule.Get().GetAssetsByClass(UAnimSequence::StaticClass()->GetFName(), AssetDataList); for( int32 AssetIndex = 0; AssetIndex < AssetDataList.Num(); ++AssetIndex ) { const FAssetData& PossibleAnimSequence = AssetDataList[AssetIndex]; if( FAssetData(Skeleton).GetExportTextName() == PossibleAnimSequence.TagsAndValues.FindRef("Skeleton") ) { FFormatNamedArguments Args; Args.Add( TEXT("AnimationName"), FText::FromName( PossibleAnimSequence.AssetName ) ); UAnimSequence* AnimSequence = CastChecked<UAnimSequence>(AssetDataList[AssetIndex].GetAsset()); MenuBuilder.AddMenuEntry( FText::Format( NSLOCTEXT("Sequencer", "AddAnimSequence", "Add {AnimationName}"), Args ), FText::Format( NSLOCTEXT("Sequencer", "AddAnimSequenceTooltip", "Adds a {AnimationName} animation to this skeletal mesh."), Args ), FSlateIcon(), FUIAction(FExecuteAction::CreateSP(ParentSequencer.Get(), &ISequencer::AddAnimation, ObjectBinding, AnimSequence)) ); } } } } }
bool UMatineeTrackAnimControlHelper::PreCreateKeyframe( UInterpTrack *Track, float fTime ) const { KeyframeAddAnimSequence = NULL; UInterpTrackAnimControl *AnimTrack = CastChecked<UInterpTrackAnimControl>(Track); UInterpGroup* Group = CastChecked<UInterpGroup>(Track->GetOuter()); AActor * Actor = GetGroupActor(Track); if (!Actor) { // error message UE_LOG(LogSlateMatinee, Warning, TEXT("No Actor is selected. Select actor first.")); return false; } USkeletalMeshComponent * SkelMeshComp = NULL; TArray<USkeletalMeshComponent*> SkeletalMeshComponents; Actor->GetComponents(SkeletalMeshComponents); for (int32 I=0; I<SkeletalMeshComponents.Num(); ++I) { USkeletalMeshComponent * CurSkelMeshComp = SkeletalMeshComponents[I]; // if qualified to play animation, break if (CurSkelMeshComp->SkeletalMesh && CurSkelMeshComp->SkeletalMesh->Skeleton) { SkelMeshComp = CurSkelMeshComp; break; } } if (!SkelMeshComp) { UE_LOG(LogSlateMatinee, Warning, TEXT("SkeletalMeshComponent isn't found in the selected actor or it does not have Mesh/Skeleton set up in order to play animation")); return false; } USkeleton * Skeleton = SkelMeshComp->SkeletalMesh->Skeleton; if ( Skeleton ) { // Show the dialog. FEdModeInterpEdit* Mode = (FEdModeInterpEdit*)GEditorModeTools().GetActiveMode( FBuiltinEditorModes::EM_InterpEdit ); check(Mode != NULL); check(Mode->InterpEd != NULL); TSharedPtr< SWindow > Parent = FSlateApplication::Get().GetActiveTopLevelWindow(); if ( Parent.IsValid() ) { FAssetPickerConfig AssetPickerConfig; AssetPickerConfig.OnAssetSelected = FOnAssetSelected::CreateUObject( this, &UMatineeTrackAnimControlHelper::OnAddKeyTextEntry, Mode->InterpEd, Track ); AssetPickerConfig.bAllowNullSelection = false; AssetPickerConfig.InitialAssetViewType = EAssetViewType::List; AssetPickerConfig.ThumbnailScale = 0.0f; // Filter config AssetPickerConfig.Filter.ClassNames.Add(UAnimSequence::StaticClass()->GetFName()); AssetPickerConfig.Filter.TagsAndValues.Add(TEXT("Skeleton"), FAssetData(Skeleton).GetExportTextName()); FContentBrowserModule& ContentBrowserModule = FModuleManager::Get().LoadModuleChecked<FContentBrowserModule>(TEXT("ContentBrowser")); FMenuBuilder MenuBuilder(true, NULL); MenuBuilder.BeginSection(NAME_None, LOCTEXT("MatineeAnimPicker", "Browse")); { TSharedPtr<SBox> MenuEntry = SNew(SBox) .WidthOverride(300.0f) .HeightOverride(300.f) [ ContentBrowserModule.Get().CreateAssetPicker(AssetPickerConfig) ]; MenuBuilder.AddWidget(MenuEntry.ToSharedRef(), FText::GetEmpty(), true); } MenuBuilder.EndSection(); EntryPopupWindow = FSlateApplication::Get().PushMenu( Parent.ToSharedRef(), MenuBuilder.MakeWidget(), FSlateApplication::Get().GetCursorPos(), FPopupTransitionEffect(FPopupTransitionEffect::TypeInPopup) ); } } else { FMessageDialog::Open( EAppMsgType::Ok, NSLOCTEXT("UnrealEd", "NoAnimSeqsFound", "No AnimSequences Found. Make sure to load AnimSequences.") ); } return false; }
/** Callback for creating a new level sequence asset in the level. */ static void OnCreateActorInLevel() { // Create a new level sequence IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get(); UObject* NewAsset = nullptr; // Attempt to create a new asset for (TObjectIterator<UClass> It ; It ; ++It) { UClass* CurrentClass = *It; if (CurrentClass->IsChildOf(UFactory::StaticClass()) && !(CurrentClass->HasAnyClassFlags(CLASS_Abstract))) { UFactory* Factory = Cast<UFactory>(CurrentClass->GetDefaultObject()); if (Factory->CanCreateNew() && Factory->ImportPriority >= 0 && Factory->SupportedClass == ULevelSequence::StaticClass()) { NewAsset = AssetTools.CreateAsset(ULevelSequence::StaticClass(), Factory); break; } } } if (!NewAsset) { return; } // Spawn an actor at the origin, and either move infront of the camera or focus camera on it (depending on the viewport) and open for edit UActorFactory* ActorFactory = GEditor->FindActorFactoryForActorClass(ALevelSequenceActor::StaticClass()); if (!ensure(ActorFactory)) { return; } ALevelSequenceActor* NewActor = CastChecked<ALevelSequenceActor>(GEditor->UseActorFactory(ActorFactory, FAssetData(NewAsset), &FTransform::Identity)); if (GCurrentLevelEditingViewportClient != nullptr && GCurrentLevelEditingViewportClient->IsPerspective()) { GEditor->MoveActorInFrontOfCamera(*NewActor, GCurrentLevelEditingViewportClient->GetViewLocation(), GCurrentLevelEditingViewportClient->GetViewRotation().Vector()); } else { GEditor->MoveViewportCamerasToActor(*NewActor, false); } FAssetEditorManager::Get().OpenEditorForAsset(NewAsset); }
/** Registers placement mode extensions. */ void RegisterPlacementModeExtensions() { FPlacementCategoryInfo Info( LOCTEXT("CinematicCategoryName", "Cinematic"), "Cinematic", TEXT("PMCinematic"), 25 ); IPlacementModeModule::Get().RegisterPlacementCategory(Info); IPlacementModeModule::Get().RegisterPlaceableItem(Info.UniqueHandle, MakeShareable( new FPlaceableItem(nullptr, FAssetData(ACineCameraActor::StaticClass())) )); IPlacementModeModule::Get().RegisterPlaceableItem(Info.UniqueHandle, MakeShareable( new FPlaceableItem(nullptr, FAssetData(ACameraRig_Crane::StaticClass())) )); IPlacementModeModule::Get().RegisterPlaceableItem(Info.UniqueHandle, MakeShareable( new FPlaceableItem(nullptr, FAssetData(ACameraRig_Rail::StaticClass())) )); }
void FPlacementMode::UpdatePreviewActors( FEditorViewportClient* ViewportClient, FViewport* Viewport, int32 x, int32 y ) { bool AllAssetsValid = false; bool AllAssetsCanBeDropped = false; if ( PlacementsChanged ) { ViewportClient->DestroyDropPreviewActors(); PlacementsChanged = false; CreatedPreviewActors = false; } const bool bAllowPreviewActors = AllowPreviewActors( ViewportClient ); if ( bAllowPreviewActors && AssetsToPlace.Num() > 0 ) { AllAssetsValid = true; TArray< UObject* > Assets; for (int Index = 0; Index < AssetsToPlace.Num(); Index++) { if ( AssetsToPlace[Index].IsValid() ) { Assets.Add( AssetsToPlace[Index].Get() ); } else { ViewportClient->DestroyDropPreviewActors(); AllAssetsValid = false; CreatedPreviewActors = false; break; } } if ( AllAssetsValid ) { AllAssetsCanBeDropped = true; // Determine if we can drop the assets for ( auto AssetIt = Assets.CreateConstIterator(); AssetIt; ++AssetIt ) { UObject* Asset = *AssetIt; FDropQuery DropResult = ViewportClient->CanDropObjectsAtCoordinates( x, y, FAssetData( Asset ) ); if ( !DropResult.bCanDrop ) { // At least one of the assets can't be dropped. ViewportClient->DestroyDropPreviewActors(); AllAssetsCanBeDropped = false; CreatedPreviewActors = false; } } if ( AllAssetsCanBeDropped ) { // Update the currently dragged actor if it exists bool bDroppedObjectsVisible = true; if ( !ViewportClient->UpdateDropPreviewActors(x, y, Assets, bDroppedObjectsVisible, PlacementFactory.Get()) ) { const bool bOnlyDropOnTarget = false; const bool bCreateDropPreview = true; const bool bSelectActors = false; TArray< AActor* > TemporaryActors; CreatedPreviewActors = ViewportClient->DropObjectsAtCoordinates(x, y, Assets, TemporaryActors, bOnlyDropOnTarget, bCreateDropPreview, bSelectActors, PlacementFactory.Get() ); } } else { StopPlacing(); } } } if ( !bAllowPreviewActors || !AllAssetsValid || !AllAssetsCanBeDropped ) { ViewportClient->DestroyDropPreviewActors(); CreatedPreviewActors = false; } }
FPropertyAccess::Result SPropertyEditorAsset::GetValue( FObjectOrAssetData& OutValue ) const { // Potentially accessing the value while garbage collecting or saving the package could trigger a crash. // so we fail to get the value when that is occuring. if ( GIsSavingPackage || IsGarbageCollecting() ) { return FPropertyAccess::Fail; } FPropertyAccess::Result Result = FPropertyAccess::Fail; if( PropertyEditor.IsValid() && PropertyEditor->GetPropertyHandle()->IsValidHandle() ) { UObject* Object = NULL; Result = PropertyEditor->GetPropertyHandle()->GetValue(Object); if (Object == NULL) { // Check to see if it's pointing to an unloaded object FString CurrentObjectPath; PropertyEditor->GetPropertyHandle()->GetValueAsFormattedString( CurrentObjectPath ); if (CurrentObjectPath.Len() > 0 && CurrentObjectPath != TEXT("None")) { if( !CachedAssetData.IsValid() || CachedAssetData.ObjectPath.ToString() != CurrentObjectPath ) { static FName AssetRegistryName("AssetRegistry"); FAssetRegistryModule& AssetRegistryModule = FModuleManager::Get().LoadModuleChecked<FAssetRegistryModule>(AssetRegistryName); CachedAssetData = AssetRegistryModule.Get().GetAssetByObjectPath( *CurrentObjectPath ); } Result = FPropertyAccess::Success; OutValue = FObjectOrAssetData( CachedAssetData ); return Result; } } OutValue = FObjectOrAssetData( Object ); } else { UObject* Object = NULL; if (PropertyHandle.IsValid()) { Result = PropertyHandle->GetValue(Object); } if (Object != NULL) { OutValue = FObjectOrAssetData(Object); } else { const FString CurrentObjectPath = ObjectPath.Get(); Result = FPropertyAccess::Success; if (CurrentObjectPath != TEXT("None") && (!CachedAssetData.IsValid() || CachedAssetData.ObjectPath.ToString() != CurrentObjectPath)) { static FName AssetRegistryName("AssetRegistry"); FAssetRegistryModule& AssetRegistryModule = FModuleManager::Get().LoadModuleChecked<FAssetRegistryModule>(AssetRegistryName); CachedAssetData = AssetRegistryModule.Get().GetAssetByObjectPath(*CurrentObjectPath); if (PropertyHandle.IsValid()) { // No property editor was specified so check if multiple property values are associated with the property handle TArray<FString> ObjectValues; PropertyHandle->GetPerObjectValues(ObjectValues); if (ObjectValues.Num() > 1) { for (int32 ObjectIndex = 1; ObjectIndex < ObjectValues.Num() && Result == FPropertyAccess::Success; ++ObjectIndex) { if (ObjectValues[ObjectIndex] != ObjectValues[0]) { Result = FPropertyAccess::MultipleValues; } } } } } else if (CurrentObjectPath == TEXT("None")) { CachedAssetData = FAssetData(); } OutValue = FObjectOrAssetData(CachedAssetData); } } return Result; }
bool FPlacementMode::HandleClick(FEditorViewportClient* InViewportClient, HHitProxy *HitProxy, const FViewportClick &Click ) { bool Handled = false; if ( IsCurrentlyPlacing() ) { if ( Click.GetKey() == EKeys::LeftMouseButton ) { TArray< UObject* > Assets; for (int Index = 0; Index < AssetsToPlace.Num(); Index++) { if ( AssetsToPlace[Index].IsValid() ) { Assets.Add( AssetsToPlace[Index].Get() ); } } TArray<AActor*> OutNewActors; const bool bCreateDropPreview = false; const bool SelectActor = false; const FViewport* const Viewport = Click.GetViewportClient()->Viewport; bool AllAssetsCanBeDropped = true; // Determine if we can drop the assets for ( auto AssetIt = Assets.CreateConstIterator(); AssetIt; ++AssetIt ) { UObject* Asset = *AssetIt; FDropQuery DropResult = InViewportClient->CanDropObjectsAtCoordinates( Viewport->GetMouseX(), Viewport->GetMouseY(), FAssetData( Asset ) ); if ( !DropResult.bCanDrop ) { // At least one of the assets can't be dropped. InViewportClient->DestroyDropPreviewActors(); AllAssetsCanBeDropped = false; CreatedPreviewActors = false; } } if ( AllAssetsCanBeDropped ) { if ( !Click.IsControlDown() ) { ClearAssetsToPlace(); IPlacementModeModule::Get().BroadcastStoppedPlacing( true ); InViewportClient->SetRequiredCursorOverride( true, EMouseCursor::GrabHand ); } InViewportClient->DropObjectsAtCoordinates( Viewport->GetMouseX(), Viewport->GetMouseY(), Assets, OutNewActors, false, bCreateDropPreview, SelectActor, PlacementFactory.Get() ); for (int Index = 0; Index < OutNewActors.Num(); Index++) { if ( OutNewActors[Index] != NULL ) { PlacedActorsThisTrackingSession = true; PlacedActors.Add( OutNewActors[Index] ); } } if ( !Click.IsControlDown() ) { SelectPlacedActors(); ClearAssetsToPlace(); } Handled = true; } } else { InViewportClient->DestroyDropPreviewActors(); CreatedPreviewActors = false; StopPlacing(); } } if ( !Handled ) { Handled = FEdMode::HandleClick(InViewportClient, HitProxy, Click); } return Handled; }