组件接口-说明文档
<table>
<thead>
<tr>
<th>最后更新日期</th>
<th>2024-01-18</th>
</tr>
</thead>
<tbody>
<tr>
<td>作者</td>
<td>QFord、LJX、ZYY</td>
</tr>
<tr>
<td>V1.0.0</td>
<td>创建文档</td>
</tr>
<tr>
<td>V2.0.0</td>
<td>1.设置器材模型对象创建的根节点 2.从器材LuaTable中获取属性3.设置器材LuaTable中的属性</td>
</tr>
<tr>
<td>V2.0.1</td>
<td>新增器材多语言切换接口</td>
</tr>
</tbody>
</table>
<p>> 文档版本和组件版本对应</p>
<p>[TOC]</p>
<h1>组件概述</h1>
<p>物件(器材)播放器组件提供器材的创建、删除、修改和查询基础能力。
此外,还提供观察器材、加速器材和显示器材电场线等扩展能力。
> 注:扩展能力将计划在2.0.0版本中开发(2024-1~2024-2)。</p>
<hr />
<h1>组件接口汇总</h1>
<p>- <a href="#CreateEquipment">CreateEquipment</a>: 创建单个器材
- <a href="#CreateEquipments">CreateEquipments</a>: 创建多个器材
- <a href="#CreateEquipmentByCoroutine">CreateEquipmentByCoroutine</a>: 使用协程创建单个器材
- <a href="#CreateEquipmentsByCoroutine">CreateEquipmentsByCoroutine</a>: 使用协程创建多个器材
- <a href="#DeleteEquipmentByGuid">DeleteEquipmentByGuid</a>: 根据guid删除器材
- <a href="#DeleteEquipmentByObject">DeleteEquipmentByObject</a>: 根据Gameobject删除器材
- <a href="#DeleteAllEquipments">DeleteAllEquipments</a>: 清空场景中所有器材
- <a href="#SetEquipRoot">SetEquipRoot</a>: 设置器材模型对象创建的根节点
- <a href="#GetEquipPropertyFromLuaTable">GetEquipPropertyFromLuaTable</a>: 从场景中已创建的器材LuaTable中获取属性
- <a href="#SetEquipPropertyToLuaTable">SetEquipPropertyToLuaTable</a>: 设置场景中已创建的器材LuaTable中的属性
- <a href="#SwitchLanguage">SwitchLanguage</a>: 器材多语言切换</p>
<h1>组件基础接口</h1>
<p> <a id="CreateEquipment"></a></p>
<h3>创建单个器材</h3>
<p>GameObject CreateEquipment(EquipementPreset presets)</p>
<p><strong>简要说明:</strong></p>
<ul>
<li>创建单个器材</li>
</ul>
<p><strong>参数:</strong></p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">presets</td>
<td style="text-align: left;">EquipementPreset</td>
<td>器材信息</td>
</tr>
</tbody>
</table>
<p><strong>返回值说明</strong></p>
<p>GameObject</p>
<p><strong>示例</strong>
```C#
var code = new EquipementPreset() { Code = "JiuJingDengElement", Position = BornTrans.position};
var goList = EquipmentManager.CreateEquipment(code);</p>
<pre><code>
&lt;a id=&quot;CreateEquipments&quot;&gt;&lt;/a&gt;
###一次创建多个器材
GameObject[] CreateEquipments(EquipementPreset[] presets)
**简要说明:**
- 一次创建多个器材
**参数:**
|参数名|类型|说明|
|:---- |:----- |----- |
|presets |EquipementPreset[] |器材信息列表|
**返回值说明**
GameObject[]
**示例**
```C#
var codes = new string[] { &quot;JiuJingDengElement&quot;,&quot;ZhongHaoShiGuanElement&quot; };
var goList = EquipmentManager.CreateEquipments(
codes.Select((e, i) =&gt; new EquipementPreset()
{
Code = e,
Position = BornTrans.position
}).ToArray()
);</code></pre>
<p> <a id="CreateEquipmentByCoroutine"></a></p>
<h3>使用协程创建单个器材</h3>
<p>bool CreateEquipmentByCoroutine(EquipementPreset preset, UnityAction<GameObject> OnCreateCompleted)</p>
<p><strong>简要说明:</strong></p>
<ul>
<li>使用协程创建单个器材</li>
</ul>
<p><strong>参数:</strong></p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">preset</td>
<td style="text-align: left;">EquipementPreset</td>
<td>器材信息</td>
</tr>
<tr>
<td style="text-align: left;">OnCreateCompleted</td>
<td style="text-align: left;">UnityAction<GameObject></td>
<td>创建完成回调,返回器材对象</td>
</tr>
</tbody>
</table>
<p><strong>返回值说明</strong></p>
<p>bool:true表示立即开始创建,false表示上一个创建流程还未结束,加入任务队列中等待</p>
<p><strong>示例</strong></p>
<pre><code class="language-csharp">var preset = new EquipementPreset() { Code = &quot;JiuJingDengElement&quot; };
GameObject go;
bool bSuccess = EquipmentManager.CreateEquipmentByCoroutine(preset, (GameObject obj) =&gt;
{
go = obj;
});</code></pre>
<p> <a id="CreateEquipmentsByCoroutine"></a></p>
<h3>使用协程创建多个器材</h3>
<p>bool CreateEquipmentsByCoroutine(EquipementPreset[] presets, UnityAction<string, GameObject> OnSingleCreated, UnityAction<List<GameObject>> OnCreateCompleted)</p>
<p><strong>简要说明:</strong></p>
<ul>
<li>使用协程创建多个器材</li>
</ul>
<p><strong>参数:</strong></p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">presets</td>
<td style="text-align: left;">EquipementPreset[]</td>
<td>器材信息列表</td>
</tr>
<tr>
<td style="text-align: left;">OnSingleCreated</td>
<td style="text-align: left;">UnityAction<string, GameObject></td>
<td>单个器材创建完成回调,返回器材Code和器材对象,若创建失败,则器材对象为空</td>
</tr>
<tr>
<td style="text-align: left;">OnCreateCompleted</td>
<td style="text-align: left;">UnityAction<List<GameObject>></td>
<td>创建完成回调,返回器材对象列表</td>
</tr>
</tbody>
</table>
<p><strong>返回值说明</strong></p>
<p>bool:true表示立即开始创建,false表示上一个创建流程还未结束,加入任务队列中等待</p>
<p><strong>示例</strong>
```C#
EquipementPreset[] presets = new EquipementPreset[2];
presets[0] = new EquipementPreset() { Code = "JiuJingDengElement" };
presets[1] = new EquipementPreset() { Code = "ZhongHaoShiGuanElement" };
List<GameObject> goList;
bool bSuccess = EquipmentManager.CreateEquipmentsByCoroutine(presets, null, (List<GameObject> objs) =>
{
goList = objs;
});</p>
<pre><code>
&lt;a id=&quot;DeleteEquipmentByGuid&quot;&gt;&lt;/a&gt;
###根据guid删除单个器材
void DeleteEquipmentByGuid(string objectId, bool deleteGroupObjects)
**简要说明:**
- 根据guid删除单个器材
**参数:**
|参数名|类型|说明|
|:---- |:----- |----- |
|objectId |string |器材guid|
|deleteGroupObjects |bool |true :有组合器材会一起删除,false:只删除指定器材|
**返回值说明**
void
**示例**
```C#
string guid = LabObjectIdManager.Instance.GetGuid(currentEntityId);
EquipmentManager.DeleteEquipmentByGuid(guid, false);</code></pre>
<p> <a id="DeleteEquipmentByObject"></a></p>
<h3>根据GameObject删除单个器材</h3>
<p>void DeleteEquipmentByObject(GameObject objectTarget, bool deleteGroupObjects)</p>
<p><strong>简要说明:</strong></p>
<ul>
<li>根据GameObject删除单个器材</li>
</ul>
<p><strong>参数:</strong></p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">objectTarget</td>
<td style="text-align: left;">GameObject</td>
<td>器材对象</td>
</tr>
<tr>
<td style="text-align: left;">deleteGroupObjects</td>
<td style="text-align: left;">bool</td>
<td>true :有组合器材会一起删除,false:只删除指定器材</td>
</tr>
</tbody>
</table>
<p><strong>返回值说明</strong></p>
<p>void</p>
<p><strong>示例</strong>
```C#
string guid = LabObjectIdManager.Instance.GetGuid(currentEntityId);
var obj = LabObjectManager.Instance.GetLabObjGoByID(guid);
EquipmentManager.DeleteEquipmentByObject(obj, false);</p>
<pre><code>
&lt;a id=&quot;DeleteAllEquipments&quot;&gt;&lt;/a&gt;
###清空场景所有器材
void DeleteAllEquipments()
**简要说明:**
- 清空场景所有器材
**参数:**
|参数名|类型|说明|
|:---- |:----- |----- |
|无 |无 |无|
**返回值说明**
void
**示例**
```C#
EquipmentManager.DeleteAllEquipments();</code></pre>
<p> <a id="SetEquipRoot"></a></p>
<h3>动态设置器材模型对象创建的根节点</h3>
<p>void SetEquipRoot(Transform rootTrans)</p>
<p><strong>简要说明:</strong></p>
<ul>
<li>动态设置器材模型对象创建的根节点</li>
</ul>
<p><strong>参数:</strong></p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">rootTrans</td>
<td style="text-align: left;">Transform</td>
<td>根节点</td>
</tr>
</tbody>
</table>
<p><strong>返回值说明</strong></p>
<p>void</p>
<p><strong>示例</strong>
```C#
GameObject equipRoot = new GameObject("EquipRoot");
EquipmentManager.SetEquipRoot(equipRoot.transform);</p>
<pre><code>
&lt;a id=&quot;GetEquipPropertyFromLuaTable&quot;&gt;&lt;/a&gt;
###从场景中已创建的器材LuaTable中获取属性
object GetEquipPropertyFromLuaTable(string code, string propertyName)
**简要说明:**
- 从器材LuaTable中获取属性
**参数:**
|参数名|类型|说明|
|:---- |:----- |----- |
| code | string | 器材编码 |
| propertyName | string | 属性名 |
**返回值说明**
object 属性对象
**示例**
```C#
object obj = EquipmentManager.GetEquipPropertyFromLuaTable(&quot;AmpereMeterElement&quot;, &quot;numberName&quot;);</code></pre>
<p> <a id="SetEquipPropertyToLuaTable"></a></p>
<h3>设置场景中已创建的器材LuaTable中的属性</h3>
<p>void SetEquipPropertyToLuaTable(string code, string propertyName, object value)</p>
<p><strong>简要说明:</strong></p>
<ul>
<li>设置器材LuaTable中的属性</li>
</ul>
<p><strong>参数:</strong></p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">code</td>
<td style="text-align: left;">string</td>
<td>器材编码</td>
</tr>
<tr>
<td style="text-align: left;">propertyName</td>
<td style="text-align: left;">string</td>
<td>属性名</td>
</tr>
<tr>
<td style="text-align: left;">value</td>
<td style="text-align: left;">object</td>
<td>属性值</td>
</tr>
</tbody>
</table>
<p><strong>返回值说明</strong></p>
<p>void</p>
<p><strong>示例</strong>
```C#
EquipmentManager.SetEquipPropertyToLuaTable("AmpereMeterElement", "formatteststringlong", "11111111111111");</p>
<pre><code>
&lt;a id=&quot;SwitchLanguage&quot;&gt;&lt;/a&gt;
###器材多语言切换
void SwitchLanguage(string languageCode)
**简要说明:**
- 器材多语言切换,需要本地下载的器材包含有对应的语言文件
![](https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=3a387e558621199c25cf6156f408544c&amp;file=file.png)
**参数:**
|参数名|类型|说明|
|:---- |:----- |----- |
|languageCode |string |语言编码 中文:zh_CN zh-CN 英文:en_US 阿拉伯:ar_SA ar_EG 繁体中文:zh_HK zh-HK zh-TW|
**返回值说明**
void
**示例**
```C#
var code = &quot;en_US&quot;;
EquipmentManager.SwitchLanguage(code);</code></pre>
<h1>组件扩展接口(除器材的CRUD外,如观察器材、显示器材电场线等)</h1>
<p><strong> 待更新 </strong>
> 注:扩展能力将计划在1.5.0版本中开发(2024-1~2024-2)。</p>
<p>Test.cs类中包含所有接口的测试用例。</p>
<p>播放器参数(原学科设置)设置项及测试用例:</p>
<pre><code class="language-csharp"> /// &lt;summary&gt;
/// 通用设置项
/// &lt;/summary&gt;
public void TestCommonSetting()
{
//显示器材读数
//【器材读数】:如显示在电压表上方的电压大小读数UI
PlayerEntrySettingSimulator.Instance.Common.XianShiDuShu = true;
//显示器材序号
//【器材序号】:如显示在电流表上方的“A1”序号标签UI
PlayerEntrySettingSimulator.Instance.Common.XianShiXuHao = true;
//显示器材损坏状态
//【损坏状态】:如电流表短路损坏时,显示在电流表上方的“!”标签UI
PlayerEntrySettingSimulator.Instance.Common.XianShiXuHao = true;
//显示器材读数观察窗口
//【观察窗口】:如点击电流表时,显示在屏幕正上方的电流表指针读数的放大窗口
PlayerEntrySettingSimulator.Instance.Common.XuanZhongGuanChaChuangKou = true;
}
/// &lt;summary&gt;
/// 时间控制设置项
/// &lt;/summary&gt;
public void TestTimeControlSetting()
{
//开启时间加速功能
PlayerEntrySettingSimulator.Instance.Time.ActiveGenericTimeControl = true;
//时间加速方式
//0:固定变速倍率; 1:区间变速倍率
PlayerEntrySettingSimulator.Instance.Time.AdjustSpeedMode = 0;
//区间变速倍率范围 [MinTimesSpeed , MaxTimesSpeed]
PlayerEntrySettingSimulator.Instance.Time.MinTimesSpeed = 1;
PlayerEntrySettingSimulator.Instance.Time.MaxTimesSpeed = 10;
// 当前时间控制状态:
// 0:暂停; 1:正常; 2:变速
PlayerEntrySettingSimulator.Instance.Time.TimeState = 1;
//当前时间变速倍率
PlayerEntrySettingSimulator.Instance.Time.TimesSpeed = 1;
//开启时间暂停功能
PlayerEntrySettingSimulator.Instance.Time.ActiveTimePauseInPlayer = true;
}
/// &lt;summary&gt;
/// 化学学科设置项
/// &lt;/summary&gt;
public void TestChemistrySetting()
{
//以下设置项用于点击器材时,显示在器材上方的化学数据界面数据项的设置
//显示容器温度
PlayerEntrySettingSimulator.Instance.Chemistry.XianShiWenDu = true;
//显示容器所拥有的各物质的质量
PlayerEntrySettingSimulator.Instance.Chemistry.XianShiZhiLiang = true;
//显示容器所拥有的各物质的摩尔质量
PlayerEntrySettingSimulator.Instance.Chemistry.XianShiMoEr = true;
//显示容器所拥有的各物质的体积
PlayerEntrySettingSimulator.Instance.Chemistry.XianShiTiJi = true;
//显示容器所拥有的各物质的浓度
PlayerEntrySettingSimulator.Instance.Chemistry.XianShiNongDu = true;
//显示当前容器发生的化学反应的化学方程式(部分化学反应才有,如CaCO3+HCl)
PlayerEntrySettingSimulator.Instance.Chemistry.XianShiHuaXueFangChengShi = true;
//开启科学计数法显示数值(当数值极大或极小时,使用科学计数法显示)
PlayerEntrySettingSimulator.Instance.Chemistry.ScientifiCounting = true;
//科学计数法显示的小数位数
PlayerEntrySettingSimulator.Instance.Chemistry.ScientifiCountingDecimal = 2;
//设置完成后需调用该接口以应用设置
PlayerSettingAdapter.ApplySettingsToPlayerCore();
}
/// &lt;summary&gt;
/// 化学学科设置项
/// &lt;/summary&gt;
public void TestPhysicsSetting()
{
///显示导线电流特效
PlayerEntrySettingSimulator.Instance.Circuit.XianShiDaoXianDianLiu = true;
//显示电场线
PlayerEntrySettingSimulator.Instance.Magnetism.XianShiDianChangXian = true;
//显示磁感线
PlayerEntrySettingSimulator.Instance.Magnetism.XianShiCiGanXian = true;
//显示光学角度
//如使用激光笔照射半圆形玻璃砖时,可开启各光线之间的角度数值显示
PlayerEntrySettingSimulator.Instance.Optics.XianShiJiaoDu = true;
//显示反射光线
PlayerEntrySettingSimulator.Instance.Optics.XianShiFanSheGuangXian = true;
//设置完成后需调用该接口以应用设置
PlayerSettingAdapter.ApplySettingsToPlayerCore();
}</code></pre>