133 lines
4.0 KiB
C#
133 lines
4.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 天线插头
|
|
/// </summary>
|
|
public class Device_SpecializedVariableAcquisitionTerminal_TianXianPlug : Device_Base
|
|
{
|
|
public bool isChose;
|
|
public bool isInstalled;
|
|
/// <summary>
|
|
/// 当前安装的插座
|
|
/// </summary>
|
|
public DeviceTrigger currentInstalledTrigger;
|
|
/// <summary>
|
|
/// 选中回调
|
|
/// </summary>
|
|
public Action<bool> choseAction;
|
|
/// <summary>
|
|
/// 是否可以选中
|
|
/// </summary>
|
|
public Func<bool> canChoseAction;
|
|
private LineRenderer lineRenderer;
|
|
/// <summary>
|
|
/// linerender点集
|
|
/// </summary>
|
|
public List<Transform> linePoints;
|
|
/// <summary>
|
|
/// 线的粗细
|
|
/// </summary>
|
|
public float LineWidth = 0.005f;
|
|
|
|
private GameObject HideObj_WhenInstall = null;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
lineRenderer = transform.GetComponent<LineRenderer>();
|
|
}
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
Chose();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
//跟随鼠标
|
|
if(isChose)
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
transform.position = ray.origin + ray.direction * 0.4f;
|
|
if(triggerName== "专变天线插头上")
|
|
{
|
|
transform.position = transform.position + Vector3.up * 0.02f;
|
|
}
|
|
else if(triggerName== "专变天线插头下")
|
|
{
|
|
transform.position = transform.position + Vector3.down * 0.02f;
|
|
}
|
|
}
|
|
|
|
//连线
|
|
List<Vector3> tmps = new List<Vector3>();
|
|
linePoints.ForEach(p => { tmps.Add(p.position); });
|
|
lineRenderer.startWidth = LineWidth;
|
|
lineRenderer.endWidth = LineWidth;
|
|
lineRenderer.positionCount = tmps.Count;
|
|
lineRenderer.SetPositions(tmps.ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选中(拔掉)
|
|
/// </summary>
|
|
public void Chose()
|
|
{
|
|
if (canChoseAction == null || canChoseAction?.Invoke() == true)
|
|
{
|
|
if (triggerAction?.Invoke(triggerName, true) == 0)
|
|
{
|
|
isChose = true;
|
|
isInstalled = false;
|
|
this.currentInstalledTrigger = null;
|
|
if (HideObj_WhenInstall != null)//HQB 20250221 241BUG
|
|
{
|
|
HideObj_WhenInstall.SetActive(true);
|
|
HideObj_WhenInstall = null;
|
|
}
|
|
choseAction?.Invoke(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 插上
|
|
/// </summary>
|
|
/// <param name="deviceTrigger"></param>
|
|
public void Install(DeviceTrigger deviceTrigger)
|
|
{
|
|
if (isChose && !isInstalled)
|
|
{
|
|
if (triggerAction?.Invoke(deviceTrigger.triggerName, true) == 0)
|
|
{
|
|
this.currentInstalledTrigger = deviceTrigger;
|
|
isInstalled = true;
|
|
isChose = false;
|
|
Transform initparent = transform.parent;
|
|
transform.parent = deviceTrigger.transform.parent;
|
|
transform.localPosition = deviceTrigger.transform.localPosition;
|
|
transform.localEulerAngles= deviceTrigger.transform.localEulerAngles;
|
|
transform.parent = initparent;
|
|
HideObj_WhenInstall = deviceTrigger.gameObject;
|
|
deviceTrigger.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetInStallState(DeviceTrigger deviceTrigger)
|
|
{
|
|
this.currentInstalledTrigger = deviceTrigger;
|
|
isInstalled = true;
|
|
isChose = false;
|
|
Transform initparent = transform.parent;
|
|
transform.parent = deviceTrigger.transform.parent;
|
|
transform.localPosition = deviceTrigger.transform.localPosition;
|
|
transform.localEulerAngles = deviceTrigger.transform.localEulerAngles;
|
|
transform.parent = initparent;
|
|
deviceTrigger.gameObject.SetActive(false);
|
|
}
|
|
}
|