145 lines
4.0 KiB
C#
145 lines
4.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
/// <summary>
|
|
/// 采集器连线插头
|
|
/// </summary>
|
|
public class Device_LinePlug : Device_Base
|
|
{
|
|
public LineRenderer lineRenderer;
|
|
public List<Transform> point;
|
|
/// <summary>
|
|
/// 连接的点
|
|
/// </summary>
|
|
public Line_end currentScrewEnd;
|
|
|
|
public bool isChose;
|
|
|
|
private Vector3 initPos;
|
|
|
|
/// <summary>
|
|
/// 选中事件
|
|
/// </summary>
|
|
public Action<bool> choseAction;
|
|
/// <summary>
|
|
/// 安装拆除事件
|
|
/// </summary>
|
|
public Action<bool, string> 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<Line_end>();
|
|
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<Vector3> tmps = new List<Vector3>();
|
|
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<BoxCollider>().enabled = false;
|
|
//拆除
|
|
Uninstall();
|
|
//显示连线点
|
|
choseAction?.Invoke(true);
|
|
}
|
|
|
|
private void NoChose()
|
|
{
|
|
isChose = false;
|
|
GetComponent<BoxCollider>().enabled = true;
|
|
//隐藏连线点
|
|
choseAction?.Invoke(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安装插头
|
|
/// </summary>
|
|
/// <param name="end"></param>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆除接头
|
|
/// </summary>
|
|
public void Uninstall()
|
|
{
|
|
if (currentScrewEnd != null)
|
|
{
|
|
string tmpEnd = currentScrewEnd.triggerName;
|
|
currentScrewEnd = null;
|
|
installAction?.Invoke(false, tmpEnd);
|
|
}
|
|
}
|
|
}
|