using MGS.Machinery; using UnityEngine; /// /// 升降发射台42s /// 开关前舱盖19s /// 开后舱盖19s 关后舱盖16s /// 打开尾盖8s 关闭尾盖13s /// 打开夹钳15s 关闭夹钳19s /// 前闭锁3s 后闭锁2s /// 整车调平10 收回支腿5s /// [RequireComponent(typeof(Mechanism))] public class MechanismsDriver : MonoBehaviour { /// /// 打开速度 /// public float openVelocity = 1; /// /// 关闭速度 /// public float closeVelocity = 1; /// /// 接收指令类型 /// public ReciveOrderType reciveOrderType; [HideInInspector] public Mechanism mechanism; /// /// 指令状态 /// public OneValueSyncObject driverState; /// /// 打开时间 /// public float openTime = 1; /// /// 关闭时间 /// public float closeTime = 1; /// /// 声音同步 /// public FunctionSync_Audio sync_Audio; public LimitCrank limitCrank; public bool forceDrive = false; public int forrceDriveState = 0; // Start is called before the first frame update protected virtual void Awake() { Initialize(); Init(); } public void Init() { driverState.InitDynamic("sync_" + gameObject.name, CallBack, driverState.valueType); } private void CallBack(string str, bool isEnter) { if (isEnter) { InitMechanisms(driverState.myint); } } protected virtual void Initialize() { mechanism = GetComponent(); } private void Update() { if (!forceDrive) DriveMechanism(); else DriveMechanism(forrceDriveState); } public void DriveMechanism() { switch (driverState.myint) { case 1: mechanism.Drive(openVelocity, DriveType.Ignore); break; case 0: mechanism.Drive(0, DriveType.Ignore); break; case -1: mechanism.Drive(-closeVelocity, DriveType.Ignore); break; default: break; } } public void DriveMechanism(int inputState) { switch (inputState) { case 1: mechanism.Drive(openVelocity, DriveType.Ignore); break; case 0: mechanism.Drive(0, DriveType.Ignore); break; case -1: mechanism.Drive(-closeVelocity, DriveType.Ignore); break; default: break; } } public void InitMechanisms(int _state) { switch (_state) { case 1: mechanism.Drive(1000000, DriveType.Ignore); break; case -1: mechanism.Drive(-1000000, DriveType.Ignore); break; default: break; } } }