202 lines
7.0 KiB
C#
202 lines
7.0 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
/// <summary>
|
|
/// 验电笔
|
|
/// </summary>
|
|
public class Tool_TestPen : Tool_Base
|
|
{
|
|
public MeshRenderer screem;
|
|
/// <summary>
|
|
/// 是否闪烁
|
|
/// </summary>
|
|
private bool isFlicker;
|
|
private float time;
|
|
/// <summary>
|
|
/// 是否回到手里
|
|
/// </summary>
|
|
private float backToHandTime;
|
|
|
|
private void Update()
|
|
{
|
|
if (GameManager.RunModelMgr != null && GameManager.RunModelMgr.SceneType != E_SceneType.Site)
|
|
return;
|
|
|
|
if (EventSystem.current.IsPointerOverGameObject()) return;
|
|
if (Input.GetMouseButtonDown(0) && !isMoving)
|
|
{
|
|
//点击螺丝验电
|
|
Ray tmpray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
if (Physics.Raycast(tmpray, out RaycastHit hit))
|
|
{
|
|
//插座/柜门
|
|
Device_Base db = hit.transform.GetComponent<Device_Base>();
|
|
if (db != null)
|
|
{
|
|
Test(db);
|
|
return;
|
|
}
|
|
|
|
//螺丝
|
|
Tool_Base tb = hit.transform.GetComponent<Tool_Base>();
|
|
if (tb != null)
|
|
{
|
|
Test(tb);
|
|
return;
|
|
}
|
|
|
|
//点击转移
|
|
TransferClick transferClick= hit.transform.GetComponent<TransferClick>();
|
|
if(transferClick != null)
|
|
{
|
|
if(transferClick.tool_Base!=null)
|
|
{
|
|
Test(transferClick.tool_Base);
|
|
return;
|
|
}
|
|
else if(transferClick.device_Base!=null)
|
|
{
|
|
Test(transferClick.device_Base);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (isFlicker)
|
|
{
|
|
time += Time.deltaTime * 3;
|
|
if (time < 1)
|
|
{
|
|
screem.materials[0].color = Color.red;
|
|
}
|
|
else if (time > 1 && time < 2)
|
|
{
|
|
screem.materials[0].color = Color.white;
|
|
}
|
|
else
|
|
{
|
|
time = 0;
|
|
}
|
|
}
|
|
|
|
//收回手中
|
|
if(backToHandTime>0)
|
|
{
|
|
backToHandTime -= Time.deltaTime;
|
|
if (backToHandTime <= 0)
|
|
{
|
|
isFlicker = false;
|
|
screem.materials[0].color = Color.white;
|
|
base.ReBackHead();
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 执行验电操作
|
|
/// </summary>
|
|
/// <param name="device_base">被验电设备</param>
|
|
public void Test(Device_Base device_base)
|
|
{
|
|
if (device_base.deviceType == DeviceType.计量柜_插座)
|
|
{
|
|
if ((triggerAction == null ? 0 : triggerAction.Invoke($"{triggerName}+{device_base.triggerName}", false)) == 0)
|
|
{
|
|
isMoving = true;
|
|
var tmp = ((Device_Socket)device_base);
|
|
//位置移动
|
|
base.hand_out_action?.Invoke();
|
|
transform.parent = tmp.transform;
|
|
transform.DOLocalRotate(tmp.testPosAndRot.localEulerAngles, 0.5f);
|
|
transform.DOMove(tmp.testPosAndRot.position, 1).OnComplete(() =>
|
|
{
|
|
Debug.Log("计量柜_插座 已验电");
|
|
isFlicker = tmp.hasElectricity;
|
|
transform.parent = null;
|
|
screem.materials[0].color = isFlicker ? Color.red : Color.white;
|
|
backToHandTime = 2f;
|
|
base.CallScoreAction(null, $"{triggerName}+{device_base.triggerName}");
|
|
triggerAction?.Invoke($"{triggerName}+{device_base.triggerName}", true);
|
|
});
|
|
}
|
|
}
|
|
else if (device_base.deviceType == DeviceType.计量柜_柜门)
|
|
{
|
|
if ((triggerAction == null ? 0 : triggerAction.Invoke($"{triggerName}+{device_base.triggerName}", false)) == 0)
|
|
{
|
|
Transform testPosAndRot = null;
|
|
bool hasElectricity;
|
|
if (device_base is Door)
|
|
{
|
|
testPosAndRot = ((Door)device_base).testPosAndRot;
|
|
hasElectricity = ((Door)device_base).hasElectricity;
|
|
}
|
|
else if (device_base is Device_CabinetDoor)
|
|
{
|
|
testPosAndRot = ((Device_CabinetDoor)device_base).testPosAndRot;
|
|
hasElectricity = ((Device_CabinetDoor)device_base).hasElectricity;
|
|
}
|
|
else if(device_base is ClickMove)
|
|
{
|
|
testPosAndRot = ((ClickMove)device_base).testPosAndRot;
|
|
hasElectricity = ((ClickMove)device_base).hasElectricity;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
isMoving = true;
|
|
//位置移动
|
|
base.hand_out_action?.Invoke();
|
|
transform.parent = device_base.transform;
|
|
transform.DOLocalRotate(testPosAndRot.localEulerAngles, 0.5f);
|
|
transform.DOMove(testPosAndRot.position, 1).OnComplete(() =>
|
|
{
|
|
Debug.Log("计量柜_柜门 已验电");
|
|
isFlicker = hasElectricity;
|
|
transform.parent = null;
|
|
screem.materials[0].color = isFlicker ? Color.red : Color.white;
|
|
backToHandTime = 2f;
|
|
base.CallScoreAction(null, $"{triggerName}+{device_base.triggerName}");
|
|
triggerAction?.Invoke($"{triggerName}+{device_base.triggerName}", true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行验电操作
|
|
/// </summary>
|
|
/// <param name="tool_base">被验电设备</param>
|
|
public void Test(Tool_Base tool_base)
|
|
{
|
|
if (tool_base.toolType == ToolType.螺丝)
|
|
{
|
|
if ((triggerAction == null ? 0 : triggerAction.Invoke($"{triggerName}+{tool_base.triggerName}", false)) == 0)
|
|
{
|
|
isMoving = true;
|
|
var tmp = ((Tool_Screw)tool_base);
|
|
base.hand_out_action?.Invoke();
|
|
//位置移动
|
|
transform.parent = tmp.transform;
|
|
transform.DOLocalRotate(tmp.TestPenAng+ new Vector3(0, -1 * tmp.transform.localEulerAngles.y, 0), 0.5f);
|
|
transform.DOMove(tmp.installPos.position, 1).OnComplete(() =>
|
|
{
|
|
Debug.Log("螺丝 已验电");
|
|
isFlicker = tmp.hasElectricity;
|
|
transform.parent = null;
|
|
screem.materials[0].color = isFlicker ? Color.red : Color.white;
|
|
backToHandTime = 2f;
|
|
base.CallScoreAction(null, $"{triggerName}+{tool_base.triggerName}");
|
|
triggerAction?.Invoke($"{triggerName}+{tool_base.triggerName}", true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|