68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
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<Equipment>().type.ToString();
|
|
WebCommunication.CallWGL(name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
float twiceTime;
|
|
/// <summary>
|
|
/// 鼠标双击判断
|
|
/// </summary>
|
|
/// <param name="offsetTime"></param>
|
|
/// <param name="timer"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|