using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; /// /// 采集器连线插头 /// public class Device_LinePlug : Device_Base { public LineRenderer lineRenderer; public List point; /// /// 连接的点 /// public Line_end currentScrewEnd; public bool isChose; private Vector3 initPos; /// /// 选中事件 /// public Action choseAction; /// /// 安装拆除事件 /// public Action installAction; protected override void OnAwake() { base.OnAwake(); initPos = transform.localPosition; if (GameManager.RunModelMgr.SceneType != E_SceneType.Site) { lineRenderer.enabled = false; } } protected override void OnMDown() { base.OnMDown(); if (triggerAction == null || triggerAction.Invoke(triggerName, true)==0) { Invoke("Chose", 0.2f); } } private void LateUpdate() { if (GameManager.RunModelMgr.SceneType == E_SceneType.Site) { if (isChose) { //跟随鼠标移动 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); transform.position = ray.origin + ray.direction * 0.5f; //点击安装 if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(ray, out RaycastHit hit)) { Line_end end = hit.transform.GetComponent(); if (end != null) { if (GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(end.triggerName, true) == 0) { Install(end); NoChose(); } return; } } if (GameManager.RunModelMgr.ModeType != E_ModeType.Study) { NoChose(); transform.localPosition = initPos; transform.localEulerAngles = new Vector3(-180, 0, 0); } } } //连线 List tmps = new List(); point.ForEach(p => { tmps.Add(p.position); }); lineRenderer.startWidth = 0.0025f; lineRenderer.endWidth = 0.0025f; lineRenderer.positionCount = tmps.Count; lineRenderer.SetPositions(tmps.ToArray()); } } private void Chose() { isChose = true; GetComponent().enabled = false; //拆除 Uninstall(); //显示连线点 choseAction?.Invoke(true); } private void NoChose() { isChose = false; GetComponent().enabled = true; //隐藏连线点 choseAction?.Invoke(false); } /// /// 安装插头 /// /// public void Install(Line_end end) { if (currentScrewEnd != end) { currentScrewEnd = end; Transform tmpParent = transform.parent; transform.parent = end.transform; transform.position = end.transform.position; transform.localEulerAngles = new Vector3(90, 0, 0); transform.parent = tmpParent; installAction?.Invoke(true, end.triggerName); base.CallScoreAction(true, "采集器连线_" + triggerName + "_" + end.triggerName); } } /// /// 拆除接头 /// public void Uninstall() { if (currentScrewEnd != null) { string tmpEnd = currentScrewEnd.triggerName; currentScrewEnd = null; installAction?.Invoke(false, tmpEnd); } } }