虚拟实验室-Unreal 版本

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


基础能力--资源加载

<p>[TOC]</p> <table> <thead> <tr> <th>作者</th> <th>范丽民(969618)</th> </tr> </thead> <tbody> <tr> <td>更新日期</td> <td>2024-7-23</td> </tr> <tr> <td>版本</td> <td>V1.0.0</td> </tr> </tbody> </table> <h1>组件说明</h1> <p>UE 中对资源加载方法很多,为了避免每个人乱掉造成之后的维护混乱,特此对资源加载方式封装,也方便之后的代码版本升级以及资源加载问题调试。 需要注意的是加载时尽量加后缀名,例如 “A_Click.A_Click” ,这样可以避免加载成为UPackage 导致二次查询,效率降低问题。 目前先封装了本地同步和异步加载。之后还会有新的扩展。</p> <h1>组件用法</h1> <p>```C++ //同步加载 UResourceManager::Get()-&gt;Load&lt;资源组件名&gt;(&quot;资源路径&quot;); //异步加载 UResourceManager::Get()-&gt;LoadAsync&lt;资源组件名&gt;(&quot;资源路径&quot;, 回调函数);</p> <pre><code># 组件接口 ```C++ //同步加载 template&amp;lt; typename T &amp;gt; T* UResourceManager::Load(const FString&amp;amp; AssetPath) //异步加载 template&amp;lt; typename T &amp;gt; TSharedPtr&amp;lt;FStreamableHandle&amp;gt; UResourceManager::LoadAsync(const FString&amp;amp; AssetPath, TFunction&amp;lt;void(T*)&amp;gt; OnLoaded) </code></pre> <h1>组件示例</h1> <p>```c++</p> <h1>include &quot;Common/ResourceManager.h&quot;</h1> <p>//同步加载 USoundWave* soundWave = UResourceManager::Get()-&gt;Load&lt;USoundWave&gt;(&quot;/Game/VLabUE/Audio/A_Click.A_Click&quot;);</p> <p>//异步加载 UResourceManager::Get()-&gt;LoadAsync&lt;USoundWave&gt;(&quot;/Game/VLabUE/Audio/A_Click.A_Click&quot;, [this](USoundWave<em> SoundWave) { if (SoundWave) { UAudioComponent</em> SoundComponent = UGameplayStatics::CreateSound2D(this,Cast&lt;USoundWave&gt;(SoundWave)); SoundComponent-&gt;Play(); } });</p> <pre><code></code></pre>

页面列表

ITEM_HTML