using Microsoft.MixedReality.Toolkit.Input; using System.Collections.Generic; using UnityEngine; public class SwitchBase : PermanentTriggerBase { public static List switchBases = new List(); /// /// 顺序 /// public bool isorder = true; private int count = 0; /// /// 指示灯 /// public GameObject indicatorLight; /// /// 开关状态 /// public OneValueSyncObject sync_State; public OneValueSyncObject sync_SwitchOn; /// /// 发射车电源 /// public OneValueSyncObject sync_MySwitchOn; /// /// 指示灯 /// public FunctionSync_Active indicator_Light; /// /// 旋转同步 /// public FunctionSync_PositionRoate sync_MyRoate; public FunctionSync_Audio sync_Audio; // Start is called before the first frame update void Start() { //base.Start(); switchBases.Add(this); } protected override void OnMDown() { base.OnMDown(); count++; if (count % 2 == 1) { ChangeState(); } Linkage(); if (count == 2) count = 0; StepManager.Instance.FinishStep(triggerName); } /// /// 切换开关状态 /// public void ChangeState() { switch (sync_State.myint) { case -1: sync_State.myint = 0; isorder = true; break; case 0: if (isorder) { sync_State.myint = 1; } else { sync_State.myint = -1; } break; case 1: sync_State.myint = 0; isorder = false; break; default: break; } sync_State.SendSync(); if (sync_State.action_apprisedetail != null) { sync_State.action_apprisedetail.Invoke(); } } /// /// 开关联动 /// private void Linkage() { if (sync_SwitchOn != null) { switch (sync_State.myint) { case -1: if (indicator_Light && sync_SwitchOn.mybool) indicator_Light.ShowObject(); sync_MyRoate.transform.localEulerAngles = new Vector3(0, 0, -30); break; case 0: if (indicator_Light && sync_SwitchOn.mybool) indicator_Light.DisShowObject(); sync_MyRoate.transform.localEulerAngles = new Vector3(0, 0, 0); break; case 1: if (indicator_Light && sync_SwitchOn.mybool) indicator_Light.ShowObject(); sync_MyRoate.transform.localEulerAngles = new Vector3(0, 0, 30); break; default: break; } } else { switch (sync_State.myint) { case -1: if (sync_MySwitchOn) { sync_MySwitchOn.mybool = true; sync_MySwitchOn.SendSync(); if (sync_MySwitchOn.action_apprisedetail != null) sync_MySwitchOn.action_apprisedetail.Invoke(); } if (indicator_Light) indicator_Light.ShowObject(); sync_MyRoate.transform.localEulerAngles = new Vector3(0, 0, -30); break; case 0: if (indicator_Light) indicator_Light.DisShowObject(); sync_MyRoate.transform.localEulerAngles = new Vector3(0, 0, 0); break; case 1: if (sync_MySwitchOn) { sync_MySwitchOn.mybool = false; sync_MySwitchOn.SendSync(); if (sync_MySwitchOn.action_apprisedetail != null) sync_MySwitchOn.action_apprisedetail.Invoke(); } if (indicator_Light) indicator_Light.DisShowObject(); sync_MyRoate.transform.localEulerAngles = new Vector3(0, 0, 30); break; default: break; } } sync_MyRoate.ReleaseControl(); sync_Audio.SetAudio(AudioControlEnum.Play); } }