虚拟实验室-Unreal 版本

虚拟实验室的Unreal 版本,第一个版本主要是以《探究通电螺线管外部的磁场分布》颗粒为例,设计和开发一个正式版本。


UE-C++调试

<p>[TOC]</p> <table> <thead> <tr> <th>作者</th> <th>QFord</th> </tr> </thead> <tbody> <tr> <td>更新日期</td> <td>2024-6-8</td> </tr> </tbody> </table> <h1>断点调试</h1> <h2>Visual Studio</h2> <ol> <li> <p>在需要设置断点的代码所在行的行号左侧点击生成红色圆标记,菜单Debug-Start Debugging(F5),然后运行UE关卡即可。 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=1f0cd3150a16f2409e5fa01c7c1b2cea&amp;amp;file=file.png" alt="" /></p> <p>&gt; 有的时候会失效,这时候使用重启大法或者清除UE非版本管理的文件后再试。</p> </li> </ol> <h2>Rider</h2> <p>TODO:待工程院AI插件可用后再试试</p> <h1>输出日志</h1> <h2>打印普通信息日志</h2> <p><code>UE_LOG(LogTemp, Log, TEXT(&amp;quot;This is a normal log message&amp;quot;));</code></p> <h2>打印警告信息日志</h2> <p><code>UE_LOG(LogTemp, Warning, TEXT(&amp;quot;This is a warning log message&amp;quot;));</code></p> <h2>打印错误信息日志</h2> <p><code>UE_LOG(LogTemp, Error, TEXT(&amp;quot;This is an error log message&amp;quot;));</code></p> <h2>打印带参数的日志</h2> <pre><code class="language-cpp">int Score = 100; FString PlayerName = &amp;quot;Alice&amp;quot;; UE_LOG(LogTemp, Log, TEXT(&amp;quot;Player %s scored %d points&amp;quot;), *PlayerName, Score);</code></pre> <h2>打印对象信息日志</h2> <pre><code class="language-cpp">AActor* MyActor = GetWorld()-&amp;gt;SpawnActor&amp;lt;AActor&amp;gt;(...); UE_LOG(LogTemp, Log, TEXT(&amp;quot;Spawned actor: %s&amp;quot;), *MyActor-&amp;gt;GetName());</code></pre> <h2>打印调试信息日志</h2> <pre><code class="language-cpp">#if UE_BUILD_DEBUG UE_LOG(LogTemp, Log, TEXT(&amp;quot;Debug information&amp;quot;)); #endif</code></pre> <h1>其他调试手段</h1> <h2>1. 通过代码触发[暂停模拟]</h2> <p>效果同点击下图的按钮 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=9ef2fc7e3f3deeae4ede923fdcc3a36d&amp;amp;file=file.png" alt="" /> &gt; 在Unreal编辑器中,“暂停模拟”按钮用于暂停当前正在运行的模拟。这个按钮通常位于编辑器界面顶部的工具栏中。点击该按钮后,模拟将暂停,允许你检查和调整场景中的元素。再次点击该按钮可以恢复模拟。</p> <p><strong>步骤1:添加私有依赖模块:</strong> PrivateDependencyModuleNames.AddRange(new string[] { &quot;UnrealEd&quot; }); 如下图所示: <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=ac2582153750220f407416c4dfe15168&amp;amp;file=file.png" alt="" /> &gt; 模块的构建文件,通常是命名为&lt;ModuleName&gt;.Build.cs,默认的模块名是你新建UE工程时的命名。 我这里列举的例子是项目的真实案例: 有一个名为VLabUE的模块,我们希望添加UnrealEd作为私有依赖模块。我们可以在VLabUE.Build.cs文件中进行如下修改:</p> <pre><code class="language-cpp">public class VLabUE : ModuleRules { public VLabUE(ReadOnlyTargetRules Target) : base(Target) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PublicDependencyModuleNames.AddRange(new string[] { &amp;quot;Core&amp;quot;, &amp;quot;CoreUObject&amp;quot;, &amp;quot;Engine&amp;quot;, &amp;quot;InputCore&amp;quot; }); PrivateDependencyModuleNames.AddRange(new string[] { &amp;quot;UnrealEd&amp;quot; }); } }</code></pre> <p><strong>步骤2:实现代码:</strong></p> <pre><code class="language-cpp">#include &amp;quot;Editor.h&amp;quot; #include &amp;quot;UnrealEd.h&amp;quot; //暂停UE编辑器中游戏的运行 if (GEditor) { GEditor-&amp;gt;SetPIEWorldsPaused(true); }</code></pre>

页面列表

ITEM_HTML