using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.EventSystems; /// /// 万用表笔 /// public class Multimeter_pen : MonoBehaviour, IPointerClickHandler { //红或黑 public string id; private void Awake() { id = gameObject.name; } /// /// 是否选中 /// private bool isChose; public void OnPointerClick(PointerEventData eventData) { if(eventData.button== PointerEventData.InputButton.Left) { //左键点选中 Debug.Log("选中"+ id+"笔"); //选中 isChose = true; } else if(eventData.button == PointerEventData.InputButton.Right) { //右键点放下 Debug.Log("放开" + id + "笔"); //取消选中 isChose = false; //回到初始位置 transform.localPosition = (id=="红"? new Vector3(-0.06210404f, 0.009172082f, -0.09704163f) :new Vector3(-0.08662688f, 0.009172082f, -0.09702184f)); } } /// /// 执行测量操作 /// /// 被验电设备 public void Test(Tool_Base tool_base) { if (tool_base.toolType == ToolType.螺丝) { var tmp = ((Tool_Screw)tool_base); //位置移动 transform.position = tmp.installPos.position; transform.eulerAngles = tmp.installPos.eulerAngles; Debug.Log("万能表笔验证螺丝"); } } private void Update() { if (isChose) { transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition); if(Input.GetMouseButtonDown(0)) { //点击螺丝验电 Ray tmpray=Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(tmpray,out RaycastHit hit)) { Tool_Screw screw= hit.transform.GetComponent(); if(screw!=null) { Test(screw); } } } } } }