304 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			304 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C#
		
	
	
	
| using HighlightPlus;
 | |
| using Sirenix.Utilities;
 | |
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| 
 | |
| /// <summary>
 | |
| /// 计量柜
 | |
| /// </summary>
 | |
| public class Device_MeasuringCabinet : MonoBehaviour
 | |
| {
 | |
|     /// <summary>
 | |
|     /// 当前机柜中安装的三相四线电能表
 | |
|     /// </summary>
 | |
|     public Device_3Phase4WireMeter meteringDevice;
 | |
|     /// <summary>
 | |
|     /// 柜门
 | |
|     /// </summary>
 | |
|     public Device_CabinetDoor cabinetDoor;
 | |
|     /// <summary>
 | |
|     /// 插座
 | |
|     /// </summary>
 | |
|     public Device_Socket socket;
 | |
|     /// <summary>
 | |
|     /// 进电开关
 | |
|     /// </summary>
 | |
|     public Device_Switch inSwitch;
 | |
|     /// <summary>
 | |
|     /// 电能表接线
 | |
|     /// </summary>
 | |
|     public List<Tool_Line> jieXian_lines;
 | |
| 
 | |
|     /// <summary>
 | |
|     /// 电能表碰撞
 | |
|     /// </summary>
 | |
|     public BoxCollider dianCollider;
 | |
|     /// <summary>
 | |
|     /// 电能表安装完成后的杂物
 | |
|     /// </summary>
 | |
|     public Device_Sundries sundries;
 | |
|     /// <summary>
 | |
|     /// 进电开关接线螺丝
 | |
|     /// </summary>
 | |
|     public List<Tool_Screw> inSwitchScrews;
 | |
|     /// <summary>
 | |
|     /// 接线检查
 | |
|     /// </summary>
 | |
|     public Check_JieXian check_JieXian;
 | |
| 
 | |
|     private void Awake()
 | |
|     {
 | |
|         AddActions();
 | |
|         if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
 | |
|             GameManager.EventMgr.AddEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
 | |
|         sundries.gameObject.SetActive(false);
 | |
|     }
 | |
|     /// <summary>
 | |
|     /// 添加各种操作回调
 | |
|     /// </summary>
 | |
|     public void AddActions()
 | |
|     {
 | |
|         //添加开关切换回调
 | |
|         inSwitch.AddAction(isOpen =>
 | |
|         {
 | |
|             //刷新带电状态
 | |
|             CheckHasElectricity();
 | |
|         });
 | |
| 
 | |
|         //添加螺丝拆装回调
 | |
|         meteringDevice.jieXian_screws.ForEach(screw =>
 | |
|         {
 | |
|             screw.AddAction(isinstalled =>
 | |
|             {
 | |
|                 //刷新带电状态
 | |
|                 CheckHasElectricity();
 | |
|                 //判断接线完好显示隐藏
 | |
|                 CheckJieXianOk();
 | |
|             });
 | |
|         });
 | |
| 
 | |
|         //接线连接和取下回调
 | |
|         jieXian_lines.ForEach(line =>
 | |
|         {
 | |
|             line.AddAction(isConnected =>
 | |
|             {
 | |
|                 //刷新带点状态
 | |
|                 CheckHasElectricity();
 | |
|                 //判断接线完好显示隐藏
 | |
|                 CheckJieXianOk();
 | |
|             });
 | |
|         });
 | |
|     }
 | |
|     private void SwitchSubProcessStepTriggerID(string arg0)
 | |
|     {
 | |
|         if (dianCollider.gameObject.name == arg0)
 | |
|         {
 | |
|             dianCollider.GetComponent<HighlightEffect>().SetHighlighted(true);
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             dianCollider.GetComponent<HighlightEffect>().SetHighlighted(false);
 | |
|         }
 | |
| 
 | |
|     }
 | |
|     /// <summary>
 | |
|     /// 还原计量柜状态
 | |
|     /// </summary>
 | |
|     public void Init()
 | |
|     {
 | |
|         //还原三相四线电能表
 | |
|         if (meteringDevice == null)
 | |
|         {
 | |
|             meteringDevice = GameObject.FindObjectOfType<Device_3Phase4WireMeter>(true);
 | |
|         }
 | |
|         meteringDevice.Init(true);
 | |
|         //还原接线完好
 | |
|         check_JieXian.isChecked = false;
 | |
|         check_JieXian.GetComponent<BoxCollider>().enabled = true;
 | |
| 
 | |
|         //还原柜门
 | |
|         cabinetDoor.CloseState();
 | |
|         //还原插座
 | |
| 
 | |
|         //还原进线开关
 | |
|         inSwitch.OpenState();
 | |
|         //还原电能表接线
 | |
|         jieXian_lines.ForEach(screw =>
 | |
|         {
 | |
|             screw.isConnected = true;
 | |
|             screw.transform.localPosition = new Vector3(screw.transform.localPosition.x, screw.InstallPosY, screw.transform.localPosition.z);
 | |
|         });
 | |
|         //还原杂物
 | |
|         sundries.gameObject.SetActive(false);
 | |
| 
 | |
|         //刷新验电状态
 | |
|         CheckHasElectricity();
 | |
|     }
 | |
| 
 | |
|     /// <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));
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     /// <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;
 | |
|         });
 | |
|     }
 | |
|     /// <summary>
 | |
|     /// 刷新接线完好的显示隐藏
 | |
|     /// </summary>
 | |
|     public void CheckJieXianOk()
 | |
|     {
 | |
|         if (jieXian_lines.TrueForAll(a => a.isConnected) && meteringDevice.jieXian_screws.TrueForAll(a => a.isInstall))
 | |
|         {
 | |
|             //显示接线完好物体
 | |
|             SiteManager.instance.measuringCabinet.check_JieXian.isChecked = false;
 | |
|             SiteManager.instance.measuringCabinet.check_JieXian.GetComponent<BoxCollider>().enabled = true;
 | |
|             Debug.Log("显示接线");
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             //隐藏接线完好物体
 | |
|             SiteManager.instance.measuringCabinet.check_JieXian.isChecked = true;
 | |
|             SiteManager.instance.measuringCabinet.check_JieXian.GetComponent<BoxCollider>().enabled = false;
 | |
|             Debug.Log("隐藏接线");
 | |
|         }
 | |
|     }
 | |
|     private void Update()
 | |
|     {
 | |
|         //是否可以触发能表的拆卸或安装电
 | |
|         if (meteringDevice == null)
 | |
|         {
 | |
|             dianCollider.enabled = true;
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             //电能表固定螺丝拆掉了,线拆掉了
 | |
|             if (!meteringDevice.fix_screw_left.isInstall && !meteringDevice.fix_screw_right.isInstall && jieXian_lines.TrueForAll(a => !a.isConnected))
 | |
|             {
 | |
|                 dianCollider.enabled = true;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 dianCollider.enabled = false;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         //安装或拆除电能表
 | |
|         if (dianCollider.enabled)
 | |
|         {
 | |
|             if (Input.GetMouseButtonDown(0))
 | |
|             {
 | |
|                 if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
 | |
|                 {
 | |
|                     if (hit.collider == dianCollider)
 | |
|                     {
 | |
|                         if ((GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(dianCollider.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.Add();
 | |
|                                     //接线关联螺丝
 | |
|                                     SetLineScrew();
 | |
|                                     //重新注册回调
 | |
|                                     AddActions();
 | |
|                                     //刷新带电状态
 | |
|                                     CheckHasElectricity();
 | |
|                                     //打分
 | |
|                                     ScoreManager.instance.Check(dianCollider.gameObject.name, true);
 | |
|                                 }
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 //拆下电能表
 | |
|                                 meteringDevice.Remove();
 | |
|                                 //情况接线关联螺丝
 | |
|                                 ClearLineScrew();
 | |
|                                 sundries.gameObject.SetActive(true);
 | |
|                                 //打分
 | |
|                                 ScoreManager.instance.Check(dianCollider.gameObject.name, false);
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void OnDestroy()
 | |
|     {
 | |
|         if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
 | |
|             GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
 | |
|     }
 | |
|     private void OnDisable()
 | |
|     {
 | |
|         if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
 | |
|             GameManager.EventMgr.RemoveEventListener<string>(Enum_EventType.SwitchSubProcessStepTriggerID, SwitchSubProcessStepTriggerID);
 | |
|     }
 | |
| }
 |