在UI界面方面基于德普培元的EETPRO软件UI组件开发了单部六层电梯仿真系统。该系统采用自建的简易化3D模型成功实现了与西门子杯逻辑算法对标程序的兼容运行确保输入输出点位完全一致。支持S7通信协议可直接连接1200/1500系列实物PLC与实物1200/1500 PLC通讯通过PLCSIM Advance实现虚拟1500 PLC通讯使用Nettoplcsim配合PLCSIM完成虚拟1200 PLC通讯通过InputButton脚本控制输出变量状态实现图片精灵的显示切换结合按钮组件点击时对输入变量执行取反操作。要获取精灵图片请先选中目标图片然后将图片属性修改为Sprite类型。InputButton.csusing game4automation; using UnityEngine; using UnityEngine.UI; public class InputButton : MonoBehaviour { public PLCInputBool Input; public PLCOutputBool state; public Sprite sprite0; public Sprite sprite1; public Image targetImage; void Start() { } void Update() { targetImage.sprite state.Value false ? sprite0 : sprite1; } public void Trun() { Input.Value !Input.Value; } }点击按钮时触发Trun()函数实现变量值的逻辑反转。开发UporDown脚本实现上下行指示功能当单个值为1时显示对应方向图片其余情况不隐藏显示。UporDown.csusing game4automation; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UporDown : MonoBehaviour { public PLCOutputBool Up; public PLCOutputBool Down; public Sprite sprite; public Sprite sprite_up; public Sprite sprite_down; public Image targetImage; void Start() { } void Update() { if(Up.Value true Down.Value false) { targetImage.sprite sprite_up; } else if (Up.Value false Down.Value true) { targetImage.sprite sprite_down; } else { targetImage.sprite sprite; } } }创建PLC的Input和Output变量按照西门子变量命名规范。实现电梯功能需要五个脚本协同工作MU 和 Source 脚本负责生成电梯模型并初始化其位置Drive 脚本控制电梯的上下移动而 Rigidbody 脚本则为电梯添加物理属性。ElevatorMovement脚本集成电梯运行三要素获取乘客数量以及载重量。ElevatorMovement.csusing game4automation; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ElevatorMovement : MonoBehaviour { public PLCOutputBool MotorStart; public PLCOutputBool HighSpeedContactors; public PLCOutputBool LowSpeedContactors; public PLCOutputBool UpContactors; public PLCOutputBool DwonContactors; public PLCInputInt Load; public Drive Elevator; public int TargetSpeed 100; public int PassengerNumber; void Start() { } void Update() { PassengerNumber GetPassengerChildCount(); Load.Value PassengerNumber; // if (MotorStart.Value) { if (UpContactors.Value true DwonContactors.Value false) { Elevator.JogForward true; Elevator.JogBackward false; } else if (UpContactors.Value false DwonContactors.Value true) { Elevator.JogForward false; Elevator.JogBackward true; } else { Elevator.JogForward false; Elevator.JogBackward false; } } else { Elevator.JogForward false; Elevator.JogBackward false; } // if (HighSpeedContactors.Value true LowSpeedContactors.Value false) { Elevator.TargetSpeed TargetSpeed; } else if (HighSpeedContactors.Value false LowSpeedContactors.Value true) { Elevator.TargetSpeed TargetSpeed / 2; } else { Elevator.TargetSpeed 0; } } // 获取当前对象的所有子对象中包含Passenger脚本的数量 int GetPassengerChildCount() { int count 0; foreach (Transform child in transform) { if (child.GetComponentPassenger() ! null) count; } return count; } }开关门功能实现多种脚本配合实现。Door脚本实现每层的单独开关门。Lock脚本实现门锁状态采集与控制。乘客功能开发外呼响应开门进入内呼到达目的地开门离开。自带外呼楼层和实际楼层一致和目标楼层。PassengerManage脚本乘客随机生成器。最终效果附演示视频链接耗时一天复刻EETpro单部六层电梯模型_哔哩哔哩_bilibili