132 lines
3.6 KiB
C#
132 lines
3.6 KiB
C#
using Microsoft.MixedReality.Toolkit.UI.BoundsControl;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// 启动发动机
|
|
/// </summary>
|
|
public class StartTheEngine : Device
|
|
{
|
|
/// <summary>
|
|
/// 是否可以启动
|
|
/// </summary>
|
|
public OneValueSyncObject canStartCar;
|
|
/// <summary>
|
|
/// 总电源
|
|
/// </summary>
|
|
public OneValueSyncObject mainSwitch;
|
|
/// <summary>
|
|
/// 仪表盘
|
|
/// </summary>
|
|
public GameObject Dashboards;
|
|
/// <summary>
|
|
/// 钥匙旋转同步
|
|
/// </summary>
|
|
public FunctionSync_PositionRoate syncRoate;
|
|
public AudioClip startClip;
|
|
public FunctionSync_Audio sync_StartAudio;
|
|
public FunctionSync_Audio sync_AfterStartAudio;
|
|
// Start is called before the first frame update
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void Update()
|
|
{
|
|
LimitAngles();
|
|
}
|
|
private void LimitAngles()
|
|
{
|
|
|
|
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, Mathf.Clamp(transform.localEulerAngles.z, 90, 180));
|
|
|
|
if (transform.localEulerAngles.z >= 180 && canStartCar.mybool)
|
|
{
|
|
StartDashboards(1);
|
|
}
|
|
else if (transform.localEulerAngles.z <= 90)
|
|
{
|
|
EndDashboards(-1);
|
|
}
|
|
else
|
|
{
|
|
currentState = 0;
|
|
}
|
|
}
|
|
int currentState = -1;
|
|
public void Resetvoke()
|
|
{
|
|
transform.GetComponent<BoundsControl>().Active = true;
|
|
}
|
|
/// <summary>
|
|
/// 启动仪表盘
|
|
/// </summary>
|
|
/// <param name="state"></param>
|
|
private void StartDashboards(int state)
|
|
{
|
|
|
|
foreach (var item in Dashboards.GetComponentsInChildren<LimitPointerAngle>())
|
|
{
|
|
if (!item.syncObject.mybool)
|
|
{
|
|
item.syncObject.mybool = true;
|
|
item.syncObject.SendSync();
|
|
}
|
|
}
|
|
|
|
if (currentState != state)
|
|
{
|
|
currentState = 1;
|
|
transform.GetComponent<BoundsControl>().Active = false;
|
|
Invoke("Resetvoke", 3);
|
|
if (!mainSwitch.mybool)
|
|
{
|
|
mainSwitch.mybool = true;
|
|
mainSwitch.SendSync();
|
|
if (mainSwitch.action_apprisedetail != null) mainSwitch.action_apprisedetail.Invoke();
|
|
sync_StartAudio.SetAudio(AudioControlEnum.Play);
|
|
Invoke("AudioPlayFinisher", startClip.length);
|
|
}
|
|
}
|
|
}
|
|
private void AudioPlayFinisher()
|
|
{
|
|
sync_AfterStartAudio.SetAudio(AudioControlEnum.Play);
|
|
}
|
|
/// <summary>
|
|
/// 关闭仪表盘
|
|
/// </summary>
|
|
/// <param name="state"></param>
|
|
private void EndDashboards(int state)
|
|
{
|
|
foreach (var item in Dashboards.GetComponentsInChildren<LimitPointerAngle>())
|
|
{
|
|
if (item.syncObject.mybool)
|
|
{
|
|
item.syncObject.mybool = false;
|
|
item.syncObject.SendSync();
|
|
}
|
|
}
|
|
|
|
if (currentState != state)
|
|
{
|
|
currentState = -1;
|
|
transform.GetComponent<BoundsControl>().Active = false;
|
|
Invoke("Resetvoke", 3);
|
|
mainSwitch.mybool = false;
|
|
mainSwitch.SendSync();
|
|
if (mainSwitch.action_apprisedetail != null) mainSwitch.action_apprisedetail.Invoke();
|
|
sync_AfterStartAudio.SetAudio(AudioControlEnum.Stop);
|
|
}
|
|
}
|
|
public void RotateStarted()
|
|
{
|
|
syncRoate.GetControl();
|
|
}
|
|
public void RotateStoped()
|
|
{
|
|
syncRoate.ReleaseControl();
|
|
}
|
|
|
|
}
|