UE4创建VS工程项目源码分析 之准备

雨点打透心脏的1/2处 2023-10-17 23:50 206阅读 0赞

功能源文件位置:
UE4->Source->Editor->GameProjectGeneration->Private->SNewProjectWizard.cpp

下图按钮所调用的函数为:void SNewProjectWizard::CreateAndOpenProject( );
这里写图片描述

  1. void SNewProjectWizard::CreateAndOpenProject( )
  2. {
  3. if( !IsCreateProjectEnabled() )
  4. {
  5. return;
  6. }
  7. //[ProjectFile]
  8. FString ProjectFile = GetProjectFilenameWithPath();
  9. //(ProjectFile:"E:\\3DEngine\\UnrealEngine4\\UEProject\\C++\\codeTest\\codeTest.uproject")
  10. if ( !CreateProject(ProjectFile) )
  11. {
  12. return;
  13. }
  14. // Prevent periodic validity checks. This is to prevent a brief error message about the project already existing while you are exiting.
  15. bPreventPeriodicValidityChecksUntilNextChange = true;
  16. if( GetSelectedTemplateItem()->bGenerateCode )
  17. {
  18. // If the engine is installed it is already compiled, so we can try to build and open a new project immediately. Non-installed situations might require building
  19. // the engine (especially the case when binaries came from P4), so we only open the IDE for that.
  20. if (FApp::IsEngineInstalled())
  21. {
  22. if (GameProjectUtils::BuildCodeProject(ProjectFile))
  23. {
  24. OpenCodeIDE( ProjectFile );
  25. OpenProject( ProjectFile );
  26. }
  27. else
  28. {
  29. // User will have already been prompted to open the IDE
  30. }
  31. }
  32. else
  33. {
  34. OpenCodeIDE( ProjectFile );
  35. }
  36. }
  37. else
  38. {
  39. OpenProject( ProjectFile );
  40. }
  41. }

函数内部又调用了bool SNewProjectWizard::CreateProject( const FString& ProjectFile )

  1. bool SNewProjectWizard::CreateProject( const FString& ProjectFile )
  2. {
  3. // Get the selected template
  4. TSharedPtr<FTemplateItem> SelectedTemplate = GetSelectedTemplateItem();
  5. if (!ensure(SelectedTemplate.IsValid()))
  6. {
  7. // A template must be selected.
  8. return false;
  9. }
  10. FText FailReason, FailLog;
  11. FProjectInformation ProjectInfo(ProjectFile, SelectedTemplate->bGenerateCode, bCopyStarterContent, SelectedTemplate->ProjectFile);
  12. ProjectInfo.TargetedHardware = SelectedHardwareClassTarget;
  13. ProjectInfo.DefaultGraphicsPerformance = SelectedGraphicsPreset;
  14. ProjectInfo.bIsEnterpriseProject = (SelectedTemplate->Type == FTemplateCategory::EnterpriseCategoryName);
  15. if (!GameProjectUtils::CreateProject(ProjectInfo, FailReason, FailLog))
  16. {
  17. SOutputLogDialog::Open(LOCTEXT("CreateProject", "Create Project"), FailReason, FailLog, FText::GetEmpty());
  18. return false;
  19. }
  20. // Successfully created the project. Update the last created location string.
  21. FString CreatedProjectPath = FPaths::GetPath(FPaths::GetPath(ProjectFile));
  22. // if the original path was the drives root (ie: C:/) the double path call strips the last /
  23. if (CreatedProjectPath.EndsWith(":"))
  24. {
  25. CreatedProjectPath.AppendChar('/');
  26. }
  27. auto* Settings = GetMutableDefault<UEditorSettings>();
  28. Settings->CreatedProjectPaths.Remove(CreatedProjectPath);
  29. Settings->CreatedProjectPaths.Insert(CreatedProjectPath, 0);
  30. Settings->bCopyStarterContentPreference = bCopyStarterContent;
  31. Settings->PostEditChange();
  32. return true;
  33. }

以下图方式来调试该功能
这里写图片描述

FTemplateItem解析

这里写图片描述
参数很直白明了,不用多说了Type肯定有C++和Blueprint。



发表评论

表情:
评论列表 (有 0 条评论,206人围观)

还没有评论,来说两句吧...

相关阅读