using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using XFrame.Core.UI; namespace YHElectric { public class RayInteraction : MonoBehaviour { Camera cam; Ray ray; RaycastHit hit; public static bool inputDoubleClick = false; int detectionLayer; void Start() { cam = Camera.main; detectionLayer= 1 << LayerMask.NameToLayer("Equipment"); } void Update() { inputDoubleClick = false; if (HaveClickTwice(0.3f, ref twiceTime)) { inputDoubleClick = true; } ray = cam.ScreenPointToRay(Input.mousePosition); if (inputDoubleClick)//!EventSystem.current.IsPointerOverGameObject() { if (Physics.Raycast(ray, out hit)) { if (hit.collider.CompareTag("Equipment")) { string name = hit.collider.GetComponent().type.ToString(); WebCommunication.CallWGL(name); } } } } float twiceTime; /// /// 鼠标双击判断 /// /// /// /// bool HaveClickTwice(float offsetTime, ref float timer) { if (Input.GetKeyDown("mouse 0")) return HaveExecuteTwiceAtTime(offsetTime, ref timer); else return false; } static bool HaveExecuteTwiceAtTime(float offsetTime, ref float timer) { if (Time.time - timer < offsetTime) return true; else { timer = Time.time; return false; } } } }