121 lines
3.6 KiB
C#
121 lines
3.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 验电笔
|
|
/// </summary>
|
|
public class Tool_TestPen : Tool_Base
|
|
{
|
|
public MeshRenderer screem;
|
|
/// <summary>
|
|
/// 是否闪烁
|
|
/// </summary>
|
|
private bool isFlicker;
|
|
private float time;
|
|
|
|
private void Update()
|
|
{
|
|
if (GameManager.RunModelMgr.SceneType != E_SceneType.Site) return;
|
|
if (LiveSceneManager.Instance.currentTool != null && LiveSceneManager.Instance.currentTool.name == "验电笔")
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
//点击螺丝验电
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 执行验电操作
|
|
/// </summary>
|
|
/// <param name="device_base">被验电设备</param>
|
|
public void Test(Device_Base device_base)
|
|
{
|
|
if (GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(device_base.triggerName, true) == 0)
|
|
{
|
|
if (device_base.deviceType == DeviceType.计量柜_插座)
|
|
{
|
|
var tmp = ((Device_Socket)device_base);
|
|
//位置移动
|
|
transform.parent = null;
|
|
transform.position = tmp.testPosAndRot.position;
|
|
transform.eulerAngles = tmp.testPosAndRot.eulerAngles;
|
|
Debug.Log("计量柜_插座 已验电");
|
|
isFlicker = tmp.hasElectricity;
|
|
|
|
}
|
|
else if (device_base.deviceType == DeviceType.计量柜_柜门)
|
|
{
|
|
var tmp = ((Device_CabinetDoor)device_base);
|
|
|
|
//位置移动
|
|
transform.parent = null;
|
|
transform.position = tmp.testPosAndRot.position;
|
|
transform.localEulerAngles = tmp.testPosAndRot.localEulerAngles;
|
|
Debug.Log("计量柜_柜门 已验电");
|
|
isFlicker = tmp.hasElectricity;
|
|
}
|
|
|
|
screem.materials[0].color = isFlicker ? Color.red : Color.white;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行验电操作
|
|
/// </summary>
|
|
/// <param name="tool_base">被验电设备</param>
|
|
public void Test(Tool_Base tool_base)
|
|
{
|
|
if (tool_base.toolType == ToolType.螺丝)
|
|
{
|
|
var tmp = ((Tool_Screw)tool_base);
|
|
//位置移动
|
|
transform.parent = null;
|
|
transform.position = tmp.installPos.position;
|
|
transform.localEulerAngles = tmp.installPos.localEulerAngles;
|
|
Debug.Log("螺丝 已验电");
|
|
isFlicker = tmp.hasElectricity;
|
|
}
|
|
|
|
screem.materials[0].color = isFlicker ? Color.red : Color.white;
|
|
}
|
|
|
|
|
|
}
|