153 lines
4.5 KiB
C#
153 lines
4.5 KiB
C#
using Microsoft.MixedReality.Toolkit.Input;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SwitchBase : PermanentTriggerBase
|
|
{
|
|
public static List<SwitchBase> switchBases = new List<SwitchBase>();
|
|
|
|
/// <summary>
|
|
/// 顺序
|
|
/// </summary>
|
|
public bool isorder = true;
|
|
private int count = 0;
|
|
/// <summary>
|
|
/// 指示灯
|
|
/// </summary>
|
|
public GameObject indicatorLight;
|
|
|
|
/// <summary>
|
|
/// 开关状态
|
|
/// </summary>
|
|
public OneValueSyncObject sync_State;
|
|
public OneValueSyncObject sync_SwitchOn;
|
|
/// <summary>
|
|
/// 发射车电源
|
|
/// </summary>
|
|
public OneValueSyncObject sync_MySwitchOn;
|
|
/// <summary>
|
|
/// 指示灯
|
|
/// </summary>
|
|
public FunctionSync_Active indicator_Light;
|
|
/// <summary>
|
|
/// 旋转同步
|
|
/// </summary>
|
|
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);
|
|
}
|
|
/// <summary>
|
|
/// 切换开关状态
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 开关联动
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
}
|