实验用品播放器
<p>[TOC]</p>
<table>
<thead>
<tr>
<th>作者</th>
<th>刘备(594682)</th>
</tr>
</thead>
<tbody>
<tr>
<td>更新日期</td>
<td>2024-9-11</td>
</tr>
<tr>
<td>版本</td>
<td>V1.0.4</td>
</tr>
</tbody>
</table>
<h1>前言</h1>
<p><strong>新人、开发组件人员、使用编辑器者必读</strong>
<strong>该文档会随着项目的完善,持续完善修改</strong>
实验用品播放器是以插件的形式存在的,如要导入新工程需要导出插件包(还要引入unlua库),播放器工程在文档的[播放器工程](#播放器工程 "播放器工程")
【新实验用品数据】链接:<a href="https://www.mubu.com/doc/2deFBu522td">https://www.mubu.com/doc/2deFBu522td</a></p>
<p>> 最快速简单创建器材的方式,可以直接<strong>拷贝 BP_TemplateElement以及相关数据和模型来创建器材</strong></p>
<h1>创建实验用品</h1>
<p><strong>因为实验用品编辑器目前还在开发中,所以需要手动创建配置数据</strong></p>
<h4>1.创建实验用品蓝图</h4>
<p>创建一个蓝图继承自AEquipmentBase的蓝图,BP_MyEquipElement
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=0a03ddeb90525afaa056d9d1f7e17528&amp;file=file.png" alt="" />
例如:BP_MyEquipElement
> 该步骤可由颗粒播放器实现</p>
<h4>2.准备实验用品数据</h4>
<p>>因为实验用品编辑器目前还在开发中,所以需要手动创建配置数据</p>
<h5>2.1 数据准备</h5>
<p>打开\Content\Script\LabConfig目录下的TemplateElement文件夹
复制一份改名你实验用品名称,例如:MyEquipElement</p>
<h5>2.2 资源准备</h5>
<p>略,模型流程仍在开发中,暂时可以用\Content\LabResources\Elements目录下的已有资源代替
例如:复制TemplateElement目录,将目录名改为:MyEquipElement,并将里面文件改名MyEquipElement</p>
<h4>3.Lua静态绑定和配置关联</h4>
<h5>3.1 数据准备</h5>
<p>BeginPlay中添加创建实验用品函数,设置坐标,设置用品名等参数
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=51f32676611535e2c76ef71ccafdc8e5&amp;file=file.png" alt="" /></p>
<h5>3.2 Lua静态绑定</h5>
<p>播放器会根据数据路径,自动绑定lua文件。例如:
例如:MyEquipElement,播放器会自动绑定\Content\Script\LabConfig\MyEquipElement\Equipment.lua</p>
<h4>4.测试实验用品</h4>
<p>当没有看到红字报错,并顺利看到下图表示加载成功
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=97cfe3e68aff3ad32833d82b4dd686a4&amp;file=file.png" alt="" /></p>
<h4>5.创建组件</h4>
<p>组件必须实现 IEquipmentComponent接口,例如:
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=fd70ca98c629a92eb32e591359ae2244&amp;file=file.png" alt="" /></p>
<h4>6.添加组件</h4>
<p>打开\Content\Script\LabConfig目录的实验用品数据,打开ComponentsConfig.json,手动写入要添加的组件
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=501adab9622a733407779b8ef4540a82&amp;file=file.png" alt="" /></p>
<h4>7.数据绑定</h4>
<p>数据绑定用于同步Lua和CPP的状态和变量,当变量修改时,同步绑定的函数调用</p>
<h5>7.1 Lua端绑定和修改方法</h5>
<pre><code class="language-lua">-- Lua数据绑定回调
Binding.Bind(M.luaTb, &quot;State&quot;, function(new, old)
print(&quot;State = &quot; .. new .. &quot; old = &quot; .. old)
self.initTb.State = new
end)
Binding.Bind(M.luaTb, &quot;testStr&quot;, function(new, old)
print(&quot;testStr = &quot; .. new .. &quot; old = &quot; .. old)
self.initTb.testStr = new
end)
Binding.Bind(M.luaTb, &quot;testBool&quot;, function(new, old)
print(new)
self.initTb.testBool = new
end)
-- Lua数据修改
self.luaConfig:Broadcast(&quot;State&quot;,math.random(1000))
self.luaConfig:Broadcast(&quot;testStr&quot;,&quot;hello&quot;)
self.luaConfig:Broadcast(&quot;testBool&quot;,true)</code></pre>
<h5>7.2 CPP端绑定和修改方法</h5>
<pre><code class="language-cpp">// 绑定Cpp回调
Equipment-&gt;LuaCallback.AddDynamic(this, &amp;UTemplateEquipmentComponent::OnStateChange);
void UTemplateEquipmentComponent::OnStateChange(const FString&amp; Key,FEquipmentParams Value)
{
UE_LOG(LogTemp, Log, TEXT(&quot;%s value is %f&quot;), *Key, Value.floatValue);
}
// 数据同步
Equipment-&gt;Broadcast(StateName,100);
Equipment-&gt;Broadcast(StateName,&quot;Hello&quot;);
Equipment-&gt;Broadcast(StateName,true);</code></pre>
<h5>7.3 蓝图修改动态绑定数据</h5>
<p>当Lua中存在绑定数据时,以TemplateElement为例:</p>
<pre><code class="language-lua">M.initTb = {
State = 99,
testStr = &quot;hello&quot;,
testBool = false,
}</code></pre>
<p>蓝图实例会找到对应的绑定数据,自动解析并填充绑定数据
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=26348c37226d778259c73e0628c43087&amp;file=file.png" alt="" /></p>
<p><strong>然后你可以通过修改对应的参数值,来达到改变绑定数据所对应的函数。</strong></p>
<h1>播放器工程</h1>
<p>因为该工程用到了unlua,需要安装cmake才能正常编译
<a href="http://git.sdp.nd/app-code/equipment-player.git">http://git.sdp.nd/app-code/equipment-player.git</a></p>