129 lines
3.1 KiB
C#
129 lines
3.1 KiB
C#
using MGS.Machinery;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// 升降发射台42s
|
|
/// 开关前舱盖19s
|
|
/// 开后舱盖19s 关后舱盖16s
|
|
/// 打开尾盖8s 关闭尾盖13s
|
|
/// 打开夹钳15s 关闭夹钳19s
|
|
/// 前闭锁3s 后闭锁2s
|
|
/// 整车调平10 收回支腿5s
|
|
/// </summary>
|
|
[RequireComponent(typeof(Mechanism))]
|
|
public class MechanismsDriver : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 打开速度
|
|
/// </summary>
|
|
public float openVelocity = 1;
|
|
/// <summary>
|
|
/// 关闭速度
|
|
/// </summary>
|
|
public float closeVelocity = 1;
|
|
/// <summary>
|
|
/// 接收指令类型
|
|
/// </summary>
|
|
public ReciveOrderType reciveOrderType;
|
|
[HideInInspector]
|
|
public Mechanism mechanism;
|
|
/// <summary>
|
|
/// 指令状态
|
|
/// </summary>
|
|
public OneValueSyncObject driverState;
|
|
/// <summary>
|
|
/// 打开时间
|
|
/// </summary>
|
|
public float openTime = 1;
|
|
/// <summary>
|
|
/// 关闭时间
|
|
/// </summary>
|
|
public float closeTime = 1;
|
|
/// <summary>
|
|
/// 声音同步
|
|
/// </summary>
|
|
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<Mechanism>();
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|