mirror of
				https://github.com/kevinporetti/UnrealImGui.git
				synced 2025-11-03 23:33:16 +00:00 
			
		
		
		
	Changed module type to allow stripping it from selected builds:
- Changed module type to 'Developer'. - Added runtime loader that handles automatic module loading in runtime builds (feature can be selectively enabled).
This commit is contained in:
		
							parent
							
								
									36cdd0c337
								
							
						
					
					
						commit
						b4e959ccd3
					
				@ -16,7 +16,7 @@
 | 
				
			|||||||
	"Modules": [
 | 
						"Modules": [
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"Name": "ImGui",
 | 
								"Name": "ImGui",
 | 
				
			||||||
			"Type": "RuntimeNoCommandlet",
 | 
								"Type": "Developer",
 | 
				
			||||||
			"LoadingPhase": "PreDefault"
 | 
								"LoadingPhase": "PreDefault"
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	]
 | 
						]
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
 | 
					// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using UnrealBuildTool;
 | 
					using UnrealBuildTool;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -18,6 +19,11 @@ public class ImGui : ModuleRules
 | 
				
			|||||||
		bool bBuildEditor = (Target.Type == TargetRules.TargetType.Editor);
 | 
							bool bBuildEditor = (Target.Type == TargetRules.TargetType.Editor);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Developer modules are automatically loaded only in editor builds but can be stripped out from other builds.
 | 
				
			||||||
 | 
							// Enable runtime loader, if you want this module to be automatically loaded in runtime builds (monolithic).
 | 
				
			||||||
 | 
							bool bEnableRuntimeLoader = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		PublicIncludePaths.AddRange(
 | 
							PublicIncludePaths.AddRange(
 | 
				
			||||||
			new string[] {
 | 
								new string[] {
 | 
				
			||||||
				Path.Combine(ModuleDirectory, "../ThirdParty/ImGuiLibrary/Include"),
 | 
									Path.Combine(ModuleDirectory, "../ThirdParty/ImGuiLibrary/Include"),
 | 
				
			||||||
@ -78,5 +84,11 @@ public class ImGui : ModuleRules
 | 
				
			|||||||
				// ... add any modules that your module loads dynamically here ...
 | 
									// ... add any modules that your module loads dynamically here ...
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !UE_4_19_OR_LATER
 | 
				
			||||||
 | 
							List<string> PrivateDefinitions = Definitions;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
							PrivateDefinitions.Add(string.Format("RUNTIME_LOADER_ENABLED = {0}", bEnableRuntimeLoader ? 1 : 0));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -221,6 +221,58 @@ void FImGuiModule::ToggleShowDemo()
 | 
				
			|||||||
	SetShowDemo(!IsShowingDemo());
 | 
						SetShowDemo(!IsShowingDemo());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//----------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					// Runtime loader
 | 
				
			||||||
 | 
					//----------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !WITH_EDITOR && RUNTIME_LOADER_ENABLED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class FImGuiModuleLoader
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						FImGuiModuleLoader()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if (!Load())
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								FModuleManager::Get().OnModulesChanged().AddRaw(this, &FImGuiModuleLoader::LoadAndRelease);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// For different engine versions.
 | 
				
			||||||
 | 
						static FORCEINLINE bool IsValid(const TSharedPtr<IModuleInterface>& Ptr) { return Ptr.IsValid(); }
 | 
				
			||||||
 | 
						static FORCEINLINE bool IsValid(const IModuleInterface* const Ptr) { return Ptr != nullptr; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool Load()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							return IsValid(FModuleManager::Get().LoadModule(ModuleName));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void LoadAndRelease(FName Name, EModuleChangeReason Reason)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// Avoid handling own load event.
 | 
				
			||||||
 | 
							if (Name != ModuleName)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// Try loading until success and then release.
 | 
				
			||||||
 | 
								if (Load())
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									FModuleManager::Get().OnModulesChanged().RemoveAll(this);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static FName ModuleName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static FImGuiModuleLoader Instance;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FName FImGuiModuleLoader::ModuleName = "ImGui";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// In monolithic builds this will start loading process.
 | 
				
			||||||
 | 
					FImGuiModuleLoader FImGuiModuleLoader::Instance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif // !WITH_EDITOR && RUNTIME_LOADER_ENABLED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//----------------------------------------------------------------------------------------------------
 | 
					//----------------------------------------------------------------------------------------------------
 | 
				
			||||||
// Partial implementations of other classes that needs access to ImGuiModuleManager
 | 
					// Partial implementations of other classes that needs access to ImGuiModuleManager
 | 
				
			||||||
//----------------------------------------------------------------------------------------------------
 | 
					//----------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user