Download LyraStarterGame/Source/LyraEditor/LyraEditor.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraEditor/LyraEditor.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Source/LyraEditor/LyraEditor.cpp
-
curl -L -o LyraEditor.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraEditor/LyraEditor.cpp
10.5 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| class SWidget; | |
| DEFINE_LOG_CATEGORY(LogLyraEditor); | |
| // This function tells the GameplayCue editor what classes to expose when creating new notifies. | |
| static void GetGameplayCueDefaultClasses(TArray<UClass*>& Classes) | |
| { | |
| Classes.Empty(); | |
| Classes.Add(UGameplayCueNotify_Burst::StaticClass()); | |
| Classes.Add(AGameplayCueNotify_BurstLatent::StaticClass()); | |
| Classes.Add(AGameplayCueNotify_Looping::StaticClass()); | |
| } | |
| // This function tells the GameplayCue editor what classes to search for GameplayCue events. | |
| static void GetGameplayCueInterfaceClasses(TArray<UClass*>& Classes) | |
| { | |
| Classes.Empty(); | |
| for (UClass* Class : TObjectRange<UClass>()) | |
| { | |
| if (Class->IsChildOf<AActor>() && Class->ImplementsInterface(UGameplayCueInterface::StaticClass())) | |
| { | |
| Classes.Add(Class); | |
| } | |
| } | |
| } | |
| // This function tells the GameplayCue editor where to create the GameplayCue notifies based on their tag. | |
| static FString GetGameplayCuePath(FString GameplayCueTag) | |
| { | |
| FString Path = FString(TEXT("/Game")); | |
| //@TODO: Try plugins (e.g., GameplayCue.ShooterGame.Foo should be in ShooterCore or something) | |
| // Default path to the first entry in the UAbilitySystemGlobals::GameplayCueNotifyPaths. | |
| if (IGameplayAbilitiesModule::IsAvailable()) | |
| { | |
| IGameplayAbilitiesModule& GameplayAbilitiesModule = IGameplayAbilitiesModule::Get(); | |
| if (GameplayAbilitiesModule.IsAbilitySystemGlobalsAvailable()) | |
| { | |
| UAbilitySystemGlobals* AbilitySystemGlobals = GameplayAbilitiesModule.GetAbilitySystemGlobals(); | |
| check(AbilitySystemGlobals); | |
| TArray<FString> GetGameplayCueNotifyPaths = AbilitySystemGlobals->GetGameplayCueNotifyPaths(); | |
| if (GetGameplayCueNotifyPaths.Num() > 0) | |
| { | |
| Path = GetGameplayCueNotifyPaths[0]; | |
| } | |
| } | |
| } | |
| GameplayCueTag.RemoveFromStart(TEXT("GameplayCue.")); | |
| FString NewDefaultPathName = FString::Printf(TEXT("%s/GCN_%s"), *Path, *GameplayCueTag); | |
| return NewDefaultPathName; | |
| } | |
| static bool HasPlayWorld() | |
| { | |
| return GEditor->PlayWorld != nullptr; | |
| } | |
| static bool HasNoPlayWorld() | |
| { | |
| return !HasPlayWorld(); | |
| } | |
| static bool HasPlayWorldAndRunning() | |
| { | |
| return HasPlayWorld() && !GUnrealEd->PlayWorld->bDebugPauseExecution; | |
| } | |
| static void OpenCommonMap_Clicked(const FString MapPath) | |
| { | |
| if (ensure(MapPath.Len())) | |
| { | |
| GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(MapPath); | |
| } | |
| } | |
| static bool CanShowCommonMaps() | |
| { | |
| return HasNoPlayWorld() && !GetDefault<ULyraDeveloperSettings>()->CommonEditorMaps.IsEmpty(); | |
| } | |
| static TSharedRef<SWidget> GetCommonMapsDropdown() | |
| { | |
| FMenuBuilder MenuBuilder(true, nullptr); | |
| for (const FSoftObjectPath& Path : GetDefault<ULyraDeveloperSettings>()->CommonEditorMaps) | |
| { | |
| if (!Path.IsValid()) | |
| { | |
| continue; | |
| } | |
| const FText DisplayName = FText::FromString(Path.GetAssetName()); | |
| MenuBuilder.AddMenuEntry( | |
| DisplayName, | |
| LOCTEXT("CommonPathDescription", "Opens this map in the editor"), | |
| FSlateIcon(), | |
| FUIAction( | |
| FExecuteAction::CreateStatic(&OpenCommonMap_Clicked, Path.ToString()), | |
| FCanExecuteAction::CreateStatic(&HasNoPlayWorld), | |
| FIsActionChecked(), | |
| FIsActionButtonVisible::CreateStatic(&HasNoPlayWorld) | |
| ) | |
| ); | |
| } | |
| return MenuBuilder.MakeWidget(); | |
| } | |
| static void CheckGameContent_Clicked() | |
| { | |
| UEditorValidator::ValidateCheckedOutContent(/*bInteractive=*/true, EDataValidationUsecase::Manual); | |
| } | |
| static void RegisterGameEditorMenus() | |
| { | |
| UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar.PlayToolBar"); | |
| FToolMenuSection& Section = Menu->AddSection("PlayGameExtensions", TAttribute<FText>(), FToolMenuInsert("Play", EToolMenuInsertType::After)); | |
| // Uncomment this to add a custom toolbar that is displayed during PIE | |
| // Useful for making easy access to changing game state artificially, adding cheats, etc | |
| // FToolMenuEntry BlueprintEntry = FToolMenuEntry::InitComboButton( | |
| // "OpenGameMenu", | |
| // FUIAction( | |
| // FExecuteAction(), | |
| // FCanExecuteAction::CreateStatic(&HasPlayWorld), | |
| // FIsActionChecked(), | |
| // FIsActionButtonVisible::CreateStatic(&HasPlayWorld)), | |
| // FOnGetContent::CreateStatic(&YourCustomMenu), | |
| // LOCTEXT("GameOptions_Label", "Game Options"), | |
| // LOCTEXT("GameOptions_ToolTip", "Game Options"), | |
| // FSlateIcon(FAppStyle::GetAppStyleSetName(), "LevelEditor.OpenLevelBlueprint") | |
| // ); | |
| // BlueprintEntry.StyleNameOverride = "CalloutToolbar"; | |
| // Section.AddEntry(BlueprintEntry); | |
| FToolMenuEntry CheckContentEntry = FToolMenuEntry::InitToolBarButton( | |
| "CheckContent", | |
| FUIAction( | |
| FExecuteAction::CreateStatic(&CheckGameContent_Clicked), | |
| FCanExecuteAction::CreateStatic(&HasNoPlayWorld), | |
| FIsActionChecked(), | |
| FIsActionButtonVisible::CreateStatic(&HasNoPlayWorld)), | |
| LOCTEXT("CheckContentButton", "Check Content"), | |
| LOCTEXT("CheckContentDescription", "Runs the Content Validation job on all checked out assets to look for warnings and errors"), | |
| FSlateIcon(FGameEditorStyle::GetStyleSetName(), "GameEditor.CheckContent") | |
| ); | |
| CheckContentEntry.StyleNameOverride = "CalloutToolbar"; | |
| Section.AddEntry(CheckContentEntry); | |
| FToolMenuEntry CommonMapEntry = FToolMenuEntry::InitComboButton( | |
| "CommonMapOptions", | |
| FUIAction( | |
| FExecuteAction(), | |
| FCanExecuteAction::CreateStatic(&HasNoPlayWorld), | |
| FIsActionChecked(), | |
| FIsActionButtonVisible::CreateStatic(&CanShowCommonMaps)), | |
| FOnGetContent::CreateStatic(&GetCommonMapsDropdown), | |
| LOCTEXT("CommonMaps_Label", "Common Maps"), | |
| LOCTEXT("CommonMaps_ToolTip", "Some commonly desired maps while using the editor"), | |
| FSlateIcon(FAppStyle::GetAppStyleSetName(), "Icons.Level") | |
| ); | |
| CommonMapEntry.StyleNameOverride = "CalloutToolbar"; | |
| Section.AddEntry(CommonMapEntry); | |
| } | |
| /** | |
| * FLyraEditorModule | |
| */ | |
| class FLyraEditorModule : public FDefaultGameModuleImpl | |
| { | |
| typedef FLyraEditorModule ThisClass; | |
| virtual void StartupModule() override | |
| { | |
| FGameEditorStyle::Initialize(); | |
| if (!IsRunningGame()) | |
| { | |
| FModuleManager::Get().OnModulesChanged().AddRaw(this, &FLyraEditorModule::ModulesChangedCallback); | |
| BindGameplayAbilitiesEditorDelegates(); | |
| if (FSlateApplication::IsInitialized()) | |
| { | |
| ToolMenusHandle = UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateStatic(&RegisterGameEditorMenus)); | |
| } | |
| FEditorDelegates::BeginPIE.AddRaw(this, &ThisClass::OnBeginPIE); | |
| FEditorDelegates::EndPIE.AddRaw(this, &ThisClass::OnEndPIE); | |
| } | |
| // Register the Context Effects Library asset type actions. | |
| { | |
| IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get(); | |
| TSharedRef<FAssetTypeActions_LyraContextEffectsLibrary> AssetAction = MakeShared<FAssetTypeActions_LyraContextEffectsLibrary>(); | |
| LyraContextEffectsLibraryAssetAction = AssetAction; | |
| AssetTools.RegisterAssetTypeActions(AssetAction); | |
| } | |
| } | |
| void OnBeginPIE(bool bIsSimulating) | |
| { | |
| ULyraExperienceManager* ExperienceManager = GEngine->GetEngineSubsystem<ULyraExperienceManager>(); | |
| check(ExperienceManager); | |
| ExperienceManager->OnPlayInEditorBegun(); | |
| } | |
| void OnEndPIE(bool bIsSimulating) | |
| { | |
| } | |
| virtual void ShutdownModule() override | |
| { | |
| // Unregister the Context Effects Library asset type actions. | |
| { | |
| FAssetToolsModule* AssetToolsModule = FModuleManager::GetModulePtr<FAssetToolsModule>("AssetTools"); | |
| TSharedPtr<IAssetTypeActions> AssetAction = LyraContextEffectsLibraryAssetAction.Pin(); | |
| if (AssetToolsModule && AssetAction) | |
| { | |
| AssetToolsModule->Get().UnregisterAssetTypeActions(AssetAction.ToSharedRef()); | |
| } | |
| } | |
| FEditorDelegates::BeginPIE.RemoveAll(this); | |
| FEditorDelegates::EndPIE.RemoveAll(this); | |
| // Undo UToolMenus | |
| if (UObjectInitialized() && ToolMenusHandle.IsValid()) | |
| { | |
| UToolMenus::UnRegisterStartupCallback(ToolMenusHandle); | |
| } | |
| UnbindGameplayAbilitiesEditorDelegates(); | |
| FModuleManager::Get().OnModulesChanged().RemoveAll(this); | |
| FGameEditorStyle::Shutdown(); | |
| } | |
| protected: | |
| static void BindGameplayAbilitiesEditorDelegates() | |
| { | |
| IGameplayAbilitiesEditorModule& GameplayAbilitiesEditorModule = IGameplayAbilitiesEditorModule::Get(); | |
| GameplayAbilitiesEditorModule.GetGameplayCueNotifyClassesDelegate().BindStatic(&GetGameplayCueDefaultClasses); | |
| GameplayAbilitiesEditorModule.GetGameplayCueInterfaceClassesDelegate().BindStatic(&GetGameplayCueInterfaceClasses); | |
| GameplayAbilitiesEditorModule.GetGameplayCueNotifyPathDelegate().BindStatic(&GetGameplayCuePath); | |
| } | |
| static void UnbindGameplayAbilitiesEditorDelegates() | |
| { | |
| if (IGameplayAbilitiesEditorModule::IsAvailable()) | |
| { | |
| IGameplayAbilitiesEditorModule& GameplayAbilitiesEditorModule = IGameplayAbilitiesEditorModule::Get(); | |
| GameplayAbilitiesEditorModule.GetGameplayCueNotifyClassesDelegate().Unbind(); | |
| GameplayAbilitiesEditorModule.GetGameplayCueInterfaceClassesDelegate().Unbind(); | |
| GameplayAbilitiesEditorModule.GetGameplayCueNotifyPathDelegate().Unbind(); | |
| } | |
| } | |
| void ModulesChangedCallback(FName ModuleThatChanged, EModuleChangeReason ReasonForChange) | |
| { | |
| if ((ReasonForChange == EModuleChangeReason::ModuleLoaded) && (ModuleThatChanged.ToString() == TEXT("GameplayAbilitiesEditor"))) | |
| { | |
| BindGameplayAbilitiesEditorDelegates(); | |
| } | |
| } | |
| private: | |
| TWeakPtr<IAssetTypeActions> LyraContextEffectsLibraryAssetAction; | |
| FDelegateHandle ToolMenusHandle; | |
| }; | |
| IMPLEMENT_MODULE(FLyraEditorModule, LyraEditor); | |