135 lines
4.4 KiB
C#
135 lines
4.4 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 专变电台
|
|
/// </summary>
|
|
public class Device_SpecializedVariableAcquisitionTerminal_RadioStation : Device_Base
|
|
{
|
|
public bool isInstalled;
|
|
public bool is电台故障;
|
|
public Material blackMat;
|
|
public Material greenMat;
|
|
public bool hasElectricity;
|
|
/// <summary>
|
|
/// 电台固定螺丝
|
|
/// </summary>
|
|
public List<Tool_Screw> screws;
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
Remove();
|
|
}
|
|
/// <summary>
|
|
/// 安装,应变成专变采集终端的子物体
|
|
/// </summary>
|
|
/// <param name="deviceTrigger"></param>
|
|
/// <param name="inOrUnstallAction"></param>
|
|
public void Add(DeviceTrigger deviceTrigger, Action<bool> inOrUnstallAction = null)
|
|
{
|
|
if (!isMoving && !isInstalled)
|
|
{
|
|
isMoving = true;
|
|
SetScrewState(false);
|
|
transform.parent = deviceTrigger.transform.parent;
|
|
hand_out_action?.Invoke();
|
|
//吸附上去
|
|
transform.localEulerAngles = deviceTrigger.transform.localEulerAngles;
|
|
transform.DOLocalMove(deviceTrigger.transform.localPosition, 1).OnComplete(() =>
|
|
{
|
|
LiveSceneManager.Instance.OnCheckSubProcess(false);
|
|
Debug.Log("电台已安装");
|
|
isMoving = false;
|
|
isInstalled = true;
|
|
GetComponent<BoxCollider>().enabled = true;
|
|
inOrUnstallAction?.Invoke(true);
|
|
triggerAction?.Invoke(deviceTrigger.triggerName, true);
|
|
CallScoreAction(null, deviceTrigger.triggerName);
|
|
//删除手里的tip
|
|
LiveSceneManager.Instance.OnCheckSubProcess(false);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
inOrUnstallAction?.Invoke(false);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 拆除
|
|
/// </summary>
|
|
public void Remove()
|
|
{
|
|
if (!isMoving && isInstalled)
|
|
{
|
|
//全拔了,螺丝全拧松才能拆除
|
|
Device_SpecializedVariableAcquisitionTerminal dst= transform.parent.GetComponent<Device_SpecializedVariableAcquisitionTerminal>();
|
|
if (dst!=null && !dst.line_电台电源线插头.isInstalled && !dst.line_电台宽线插头.isOpen && !dst.line_电台网线插头.isOpen && !dst.line_电台_天线连接线插头.isOpen && screws.All(a=>!a.isInstall))
|
|
{
|
|
if (triggerAction?.Invoke(triggerName, false) == 0)
|
|
{
|
|
isMoving = true;
|
|
transform.DOLocalMoveZ(0.0322f, 0.5f).OnComplete(() =>
|
|
{
|
|
isMoving = false;
|
|
isInstalled = false;
|
|
Destroy(gameObject);
|
|
triggerAction?.Invoke(triggerName, true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 直接安装
|
|
/// </summary>
|
|
/// <param name="deviceTrigger"></param>
|
|
/// <param name="inOrUnstallAction"></param>
|
|
public void SetIntallState(DeviceTrigger deviceTrigger, Action<bool> inOrUnstallAction = null)
|
|
{
|
|
SetScrewState(true);
|
|
transform.parent = deviceTrigger.transform.parent;
|
|
//吸附上去
|
|
transform.localEulerAngles = deviceTrigger.transform.localEulerAngles;
|
|
transform.localPosition = deviceTrigger.transform.localPosition;
|
|
isInstalled = true;
|
|
GetComponent<BoxCollider>().enabled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置螺丝状态
|
|
/// </summary>
|
|
/// <param name="isinstall"></param>
|
|
public void SetScrewState(bool isinstall)
|
|
{
|
|
if (isinstall)
|
|
{
|
|
screws.ForEach(a =>
|
|
{
|
|
a.isInstall = true;
|
|
a.transform.localPosition = new Vector3(a.transform.localPosition.x,a.initPostionY,a.transform.localPosition.z);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
screws.ForEach(a =>
|
|
{
|
|
a.isInstall = false;
|
|
a.transform.localPosition = new Vector3(a.transform.localPosition.x, a.initPostionY-0.02f, a.transform.localPosition.z);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新故障状态
|
|
/// </summary>
|
|
/// <param name="isFault">是否故障</param>
|
|
public void CheckFaultState()
|
|
{
|
|
transform.Find("电台本身/电源").GetComponent<MeshRenderer>().material = ((hasElectricity && !is电台故障) ? greenMat : blackMat);
|
|
}
|
|
}
|