using Microsoft.MixedReality.Toolkit.UI.BoundsControl; using UnityEngine; /// /// 启动发动机 /// public class StartTheEngine : Device { /// /// 是否可以启动 /// public OneValueSyncObject canStartCar; /// /// 总电源 /// public OneValueSyncObject mainSwitch; /// /// 仪表盘 /// public GameObject Dashboards; /// /// 钥匙旋转同步 /// 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().Active = true; } /// /// 启动仪表盘 /// /// private void StartDashboards(int state) { foreach (var item in Dashboards.GetComponentsInChildren()) { if (!item.syncObject.mybool) { item.syncObject.mybool = true; item.syncObject.SendSync(); } } if (currentState != state) { currentState = 1; transform.GetComponent().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); } /// /// 关闭仪表盘 /// /// private void EndDashboards(int state) { foreach (var item in Dashboards.GetComponentsInChildren()) { if (item.syncObject.mybool) { item.syncObject.mybool = false; item.syncObject.SendSync(); } } if (currentState != state) { currentState = -1; transform.GetComponent().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(); } }