基础能力--资源加载
<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()->Load<资源组件名>("资源路径");
//异步加载
UResourceManager::Get()->LoadAsync<资源组件名>("资源路径", 回调函数);</p>
<pre><code># 组件接口
```C++
//同步加载
template&lt; typename T &gt;
T* UResourceManager::Load(const FString&amp; AssetPath)
//异步加载
template&lt; typename T &gt;
TSharedPtr&lt;FStreamableHandle&gt; UResourceManager::LoadAsync(const FString&amp; AssetPath, TFunction&lt;void(T*)&gt; OnLoaded)
</code></pre>
<h1>组件示例</h1>
<p>```c++</p>
<h1>include "Common/ResourceManager.h"</h1>
<p>//同步加载
USoundWave* soundWave = UResourceManager::Get()->Load<USoundWave>("/Game/VLabUE/Audio/A_Click.A_Click");</p>
<p>//异步加载
UResourceManager::Get()->LoadAsync<USoundWave>("/Game/VLabUE/Audio/A_Click.A_Click", [this](USoundWave<em> SoundWave)
{
if (SoundWave)
{
UAudioComponent</em> SoundComponent = UGameplayStatics::CreateSound2D(this,Cast<USoundWave>(SoundWave));
SoundComponent->Play();
}
});</p>
<pre><code></code></pre>