447 lines
13 KiB
C#
447 lines
13 KiB
C#
using HighlightPlus;
|
|
using Sirenix.Utilities;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity.VisualScripting.Antlr3.Runtime;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 10006_6001_计量装置轮换
|
|
/// </summary>
|
|
public class Device_Control_6001 : Device_Control
|
|
{
|
|
/// <summary>
|
|
/// 采集器
|
|
/// </summary>
|
|
public Device_Collector collector;
|
|
/// <summary>
|
|
/// 采集器安装区域
|
|
/// </summary>
|
|
public DeviceTrigger device_collectorTrigger;
|
|
/// <summary>
|
|
/// 采集器安装位置
|
|
/// </summary>
|
|
public Transform collector_transform;
|
|
|
|
/// <summary>
|
|
/// 当前机柜中安装的三相四线电能表
|
|
/// </summary>
|
|
public Device_3Phase4WireMeter meteringDevice;
|
|
/// <summary>
|
|
/// 插座
|
|
/// </summary>
|
|
public Device_Socket socket;
|
|
/// <summary>
|
|
/// 进电开关
|
|
/// </summary>
|
|
public Device_Switch inSwitch;
|
|
/// <summary>
|
|
/// 电能表接线
|
|
/// </summary>
|
|
public List<Tool_Line> jieXian_lines;
|
|
|
|
/// <summary>
|
|
/// 电能表碰撞
|
|
/// </summary>
|
|
public DeviceTrigger dianTrigger;
|
|
/// <summary>
|
|
/// 电能表安装完成后的杂物
|
|
/// </summary>
|
|
public Device_Sundries sundries;
|
|
/// <summary>
|
|
/// 进电开关接线螺丝
|
|
/// </summary>
|
|
public List<Tool_Screw> inSwitchScrews;
|
|
/// <summary>
|
|
/// 接线检查
|
|
/// </summary>
|
|
public Check_JieXian check_JieXian;
|
|
|
|
#region 柜门
|
|
/// <summary>
|
|
/// 柜门螺丝
|
|
/// </summary>
|
|
public Tool_Screw door_screw;
|
|
/// <summary>
|
|
/// 柜门
|
|
/// </summary>
|
|
public Door cabinetDoor;
|
|
/// <summary>
|
|
/// 柜门封印
|
|
/// </summary>
|
|
public Device_Seal door_seal;
|
|
/// <summary>
|
|
/// 柜门封印触发区域
|
|
/// </summary>
|
|
public DeviceTrigger door_seal_trigger;
|
|
#endregion
|
|
|
|
private void Start()
|
|
{
|
|
//Init();
|
|
base.hasInit = true;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
//设置控制脚本
|
|
StepStateControl.instance?.SetDeviceControl(6001, this);
|
|
ScoreManager.instance?.SetDeviceControl(6001, this);
|
|
|
|
//注册工具拿出和收回,显示隐藏物体的封印的触发
|
|
EventCenter.Instance.AddEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, CheckTriggerShow);
|
|
|
|
AddActions();
|
|
|
|
sundries.gameObject.SetActive(false);
|
|
|
|
//添加电能表区域点击事件
|
|
dianTrigger.clickAction += () =>
|
|
{
|
|
if ((GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(dianTrigger.gameObject.name, true)) == 0)
|
|
{
|
|
if (meteringDevice == null)
|
|
{
|
|
//安装电能表
|
|
if (LiveSceneManager.Instance.currentTool != null && LiveSceneManager.Instance.currentTool.GetComponent<Device_3Phase4WireMeter>() != null)
|
|
{
|
|
meteringDevice = LiveSceneManager.Instance.currentTool.GetComponent<Device_3Phase4WireMeter>();
|
|
meteringDevice.cover.openLocalPos = new Vector3(0.295f, 0.121f, -0.067f);
|
|
meteringDevice.Add(this, dianTrigger.transform.localPosition, dianTrigger.transform.localEulerAngles);
|
|
|
|
//接线关联螺丝
|
|
SetLineScrew();
|
|
//重新注册回调
|
|
//AddActions();
|
|
//添加螺丝拆装回调
|
|
meteringDevice.jieXian_screws.ForEach(screw =>
|
|
{
|
|
screw.AddinstallAction(isinstalled =>
|
|
{
|
|
//刷新带电状态
|
|
CheckHasElectricity();
|
|
//判断接线完好显示隐藏
|
|
CheckJieXianOk();
|
|
});
|
|
});
|
|
//刷新带电状态
|
|
CheckHasElectricity();
|
|
//打分
|
|
dianTrigger.CallScoreAction(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//拆下电能表
|
|
meteringDevice.Remove(a =>
|
|
{
|
|
if (a)
|
|
{
|
|
//拆下场景中自带的电能表才显示杂物
|
|
if (meteringDevice.name == "原三相四线费控智能电能表")
|
|
{
|
|
sundries.gameObject.SetActive(true);
|
|
}
|
|
meteringDevice = null;
|
|
//情况接线关联螺丝
|
|
ClearLineScrew();
|
|
//打分
|
|
dianTrigger.CallScoreAction(false);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
|
|
//柜门封印触发区点击事件
|
|
door_seal_trigger.clickAction += () =>
|
|
{
|
|
//安装封印
|
|
if (door_screw.isInstall)
|
|
{
|
|
if (GameManager.ProcessMgr == null || GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(door_seal_trigger.name, true) == 0)
|
|
{
|
|
door_seal.Install();
|
|
door_seal_trigger.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
};
|
|
|
|
//采集器安装区域点击事件
|
|
collector.installArea = device_collectorTrigger.transform;
|
|
|
|
device_collectorTrigger.clickAction += () =>
|
|
{
|
|
Device_Collector cur_collector = LiveSceneManager.Instance.currentTool.GetComponent<Device_Collector>();
|
|
ToolFuncManager.GetChild(cur_collector.transform, "连线").gameObject.SetActive(false);
|
|
ToolFuncManager.GetChild(cur_collector.transform, "采集器插头_下").gameObject.SetActive(false);
|
|
cur_collector.Add(device_collectorTrigger, () => {
|
|
collector.MoveToInstall();
|
|
cur_collector.gameObject.SetActive(false);
|
|
collector.gameObject.SetActive(true);
|
|
collector.gameObject.name = "采集器";
|
|
collector.isInstalled = true;
|
|
if (GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(device_collectorTrigger.triggerName, false) == 0)
|
|
{
|
|
collector.plug.SetPlugColliderState(true);
|
|
ScoreManager.instance.Check(collector.gameObject.name, "采集器完成重装");
|
|
}
|
|
});
|
|
};
|
|
|
|
GameManager.UIMgr.ShowPanel<UI_ConnectStation>();//HQB 显示联系台站的按钮
|
|
}
|
|
/// <summary>
|
|
/// 添加各种操作回调
|
|
/// </summary>
|
|
public void AddActions()
|
|
{
|
|
//柜门打开条件
|
|
cabinetDoor.canOpen += () =>
|
|
{
|
|
return !door_screw.isInstall;
|
|
};
|
|
|
|
//柜门螺丝条件
|
|
door_screw.AddCheckAction(() =>
|
|
{
|
|
return door_seal.isCut && !cabinetDoor.isOpen;
|
|
});
|
|
|
|
//添加开关切换回调
|
|
inSwitch.AddAction(isOpen =>
|
|
{
|
|
//刷新带电状态
|
|
CheckHasElectricity();
|
|
});
|
|
|
|
//添加螺丝拆装回调
|
|
meteringDevice.jieXian_screws.ForEach(screw =>
|
|
{
|
|
screw.AddinstallAction(isinstalled =>
|
|
{
|
|
//刷新带电状态
|
|
CheckHasElectricity();
|
|
//判断接线完好显示隐藏
|
|
CheckJieXianOk();
|
|
});
|
|
});
|
|
|
|
//接线连接和取下回调,判断回调
|
|
jieXian_lines.ForEach(line =>
|
|
{
|
|
//无电能表不可移动
|
|
line.AddCanMoveCheck(() => { return meteringDevice != null; });
|
|
|
|
line.AddCompleteAction(isConnected =>
|
|
{
|
|
//刷新带点状态
|
|
CheckHasElectricity();
|
|
//判断接线完好显示隐藏
|
|
CheckJieXianOk();
|
|
});
|
|
});
|
|
|
|
///开关螺丝不可拆卸
|
|
inSwitchScrews.ForEach(a =>
|
|
{
|
|
a.AddCheckAction(() =>
|
|
{
|
|
//提示不可拆
|
|
TipPanel.ShowTip("当前螺丝不可拆卸!");
|
|
return false;
|
|
});
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 还原计量柜状态
|
|
/// </summary>
|
|
public void Init()
|
|
{
|
|
//还原三相四线电能表
|
|
if (meteringDevice == null)
|
|
{
|
|
meteringDevice = GameObject.FindObjectOfType<Device_3Phase4WireMeter>(true);
|
|
}
|
|
meteringDevice.Init(true);
|
|
//还原接线完好
|
|
check_JieXian.isChecked = false;
|
|
check_JieXian.gameObject.SetActive(true);
|
|
|
|
//还原柜门
|
|
cabinetDoor.SetState(false);
|
|
door_screw.isInstall = true;
|
|
door_screw.transform.localPosition = new Vector3(door_screw.transform.localPosition.x, door_screw.initPostionY, door_screw.transform.localPosition.z);
|
|
door_seal.isCut = false;
|
|
door_seal.gameObject.SetActive(true);
|
|
|
|
//还原插座
|
|
|
|
//还原进线开关
|
|
inSwitch.OpenState();
|
|
//还原电能表接线
|
|
jieXian_lines.ForEach(line =>
|
|
{
|
|
line.SetConenctState(true);
|
|
});
|
|
//还原杂物
|
|
sundries.gameObject.SetActive(false);
|
|
|
|
//刷新验电状态
|
|
CheckHasElectricity();
|
|
|
|
//还原采集器 HQB
|
|
collector.Init(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空接线的螺丝参数
|
|
/// </summary>
|
|
public void ClearLineScrew()
|
|
{
|
|
Debug.Log("清除接线关联的螺丝");
|
|
jieXian_lines.ForEach(a =>
|
|
{
|
|
a.screws.Clear();
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 设置接线的螺丝参数
|
|
/// </summary>
|
|
public void SetLineScrew()
|
|
{
|
|
Debug.Log("接线重新关联螺丝");
|
|
jieXian_lines.ForEach(a =>
|
|
{
|
|
a.screws = meteringDevice.jieXian_screws.FindAll(b => b.gameObject.name.StartsWith(a.gameObject.name.Replace("线", "")));
|
|
if (a.screws == null || a.screws.Count == 0)
|
|
{
|
|
Debug.LogError("接线未找到对应螺丝");
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新电能表螺丝带电状态
|
|
/// </summary>
|
|
public void CheckHasElectricity()
|
|
{
|
|
Debug.Log("带电状态刷新");
|
|
//进线螺丝是否带电
|
|
jieXian_lines.ForEach(a =>
|
|
{
|
|
if (!inSwitch.isOpen)
|
|
{
|
|
//开关关闭不带电
|
|
a.screws.ForEach(b => b.hasElectricity = false);
|
|
}
|
|
else
|
|
{
|
|
//开关打开--线接上--螺丝拧上带电
|
|
if (!a.isConnected)
|
|
{
|
|
a.screws.ForEach(b => b.hasElectricity = false);
|
|
}
|
|
else
|
|
{
|
|
a.screws.ForEach(b =>
|
|
{
|
|
//安装了则
|
|
//零线无电流,有电压
|
|
if (b.triggerName.Contains("零"))
|
|
{
|
|
b.hasElectricity = false;
|
|
}
|
|
else
|
|
{
|
|
//其他的看是否上电
|
|
b.hasElectricity = b.isInstall;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
//进电开关螺丝是否带电
|
|
inSwitchScrews.ForEach(a =>
|
|
{
|
|
a.hasElectricity = inSwitch.isOpen;
|
|
});
|
|
//电能表是否带点
|
|
if (meteringDevice != null)
|
|
meteringDevice.screemControl.hasElectricity = (inSwitch.isOpen && jieXian_lines.All(line => line.isConnected));
|
|
}
|
|
/// <summary>
|
|
/// 刷新接线完好的显示隐藏
|
|
/// </summary>
|
|
public void CheckJieXianOk()
|
|
{
|
|
if (jieXian_lines.TrueForAll(a => a.isConnected) && meteringDevice.jieXian_screws.TrueForAll(a => a.isInstall))
|
|
{
|
|
//显示接线完好物体
|
|
check_JieXian.isChecked = false;
|
|
check_JieXian.gameObject.SetActive(true);
|
|
Debug.Log("显示接线");
|
|
}
|
|
else
|
|
{
|
|
//隐藏接线完好物体
|
|
check_JieXian.isChecked = true;
|
|
check_JieXian.gameObject.SetActive(false);
|
|
Debug.Log("隐藏接线");
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
//是否可以触发能表的拆卸或安装电
|
|
if (meteringDevice == null)
|
|
{
|
|
dianTrigger.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
//电能表固定螺丝拆掉了,线拆掉了
|
|
if (!meteringDevice.fix_screw_left.isInstall && !meteringDevice.fix_screw_right.isInstall && jieXian_lines.TrueForAll(a => !a.isConnected))
|
|
{
|
|
dianTrigger.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
dianTrigger.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查显示或隐藏封印触发器
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
private void CheckTriggerShow(GameObject obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
//收回
|
|
Debug.Log("收回");
|
|
door_seal_trigger.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
//拿出
|
|
Debug.Log("拿出");
|
|
if (obj.name == "盒装封印")
|
|
{
|
|
if (!cabinetDoor.isOpen && door_seal.isCut && door_screw.isInstall)
|
|
door_seal_trigger.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void OnDestroy()
|
|
{
|
|
EventCenter.Instance.RemoveEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, CheckTriggerShow);
|
|
GameManager.UIMgr.HidePanel<UI_ConnectStation>();//HQB 显示联系台站的按钮
|
|
}
|
|
}
|