虚拟实验室-Unreal 版本

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


实验用品播放器

<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库),播放器工程在文档的[播放器工程](#播放器工程 &quot;播放器工程&quot;) 【新实验用品数据】链接:<a href="https://www.mubu.com/doc/2deFBu522td">https://www.mubu.com/doc/2deFBu522td</a></p> <p>&gt; 最快速简单创建器材的方式,可以直接<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;amp;file=file.png" alt="" /> 例如:BP_MyEquipElement &gt; 该步骤可由颗粒播放器实现</p> <h4>2.准备实验用品数据</h4> <p>&gt;因为实验用品编辑器目前还在开发中,所以需要手动创建配置数据</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;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;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;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;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, &amp;quot;State&amp;quot;, function(new, old) print(&amp;quot;State = &amp;quot; .. new .. &amp;quot; old = &amp;quot; .. old) self.initTb.State = new end) Binding.Bind(M.luaTb, &amp;quot;testStr&amp;quot;, function(new, old) print(&amp;quot;testStr = &amp;quot; .. new .. &amp;quot; old = &amp;quot; .. old) self.initTb.testStr = new end) Binding.Bind(M.luaTb, &amp;quot;testBool&amp;quot;, function(new, old) print(new) self.initTb.testBool = new end) -- Lua数据修改 self.luaConfig:Broadcast(&amp;quot;State&amp;quot;,math.random(1000)) self.luaConfig:Broadcast(&amp;quot;testStr&amp;quot;,&amp;quot;hello&amp;quot;) self.luaConfig:Broadcast(&amp;quot;testBool&amp;quot;,true)</code></pre> <h5>7.2 CPP端绑定和修改方法</h5> <pre><code class="language-cpp">// 绑定Cpp回调 Equipment-&amp;gt;LuaCallback.AddDynamic(this, &amp;amp;UTemplateEquipmentComponent::OnStateChange); void UTemplateEquipmentComponent::OnStateChange(const FString&amp;amp; Key,FEquipmentParams Value) { UE_LOG(LogTemp, Log, TEXT(&amp;quot;%s value is %f&amp;quot;), *Key, Value.floatValue); } // 数据同步 Equipment-&amp;gt;Broadcast(StateName,100); Equipment-&amp;gt;Broadcast(StateName,&amp;quot;Hello&amp;quot;); Equipment-&amp;gt;Broadcast(StateName,true);</code></pre> <h5>7.3 蓝图修改动态绑定数据</h5> <p>当Lua中存在绑定数据时,以TemplateElement为例:</p> <pre><code class="language-lua">M.initTb = { State = 99, testStr = &amp;quot;hello&amp;quot;, testBool = false, }</code></pre> <p>蓝图实例会找到对应的绑定数据,自动解析并填充绑定数据 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=26348c37226d778259c73e0628c43087&amp;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>

页面列表

ITEM_HTML