77 lines
1.9 KiB
C#
77 lines
1.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QFramework;
|
|
using System;
|
|
|
|
namespace QFramework.Example
|
|
{
|
|
public class UIBody3DMouseData : UIPanelData
|
|
{
|
|
}
|
|
public partial class UIBody3DMouse : UIPanel
|
|
{
|
|
UIDragItem dragItem;
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UIBody3DMouseData ?? new UIBody3DMouseData();
|
|
dragItem = Content.GetComponent<UIDragItem>();
|
|
|
|
SelectBtn.onClick.AddListener(() =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
private void OnEndDrag()
|
|
{
|
|
Show3DCamera.instance.lockMove = false;
|
|
}
|
|
|
|
private void OnBeginDrag()
|
|
{
|
|
Show3DCamera.instance.lockMove = true;
|
|
}
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
{
|
|
dragItem?.OnBeginDragEvent.AddListener(OnBeginDrag);
|
|
dragItem?.OnEndDragEvent.AddListener(OnEndDrag);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Point != null && Camera.main != null)
|
|
{
|
|
// 获取Image组件的中心点屏幕坐标
|
|
Vector2 imageCenter = new Vector2(Point.rectTransform.position.x, Point.rectTransform.position.y);
|
|
|
|
// 将屏幕坐标转换为射线
|
|
Ray ray = Camera.main.ScreenPointToRay(imageCenter);
|
|
RaycastHit hit;
|
|
|
|
// 进行射线检测
|
|
if (Physics.Raycast(ray, out hit))
|
|
{
|
|
// 打印被击中物体的名字
|
|
Debug.LogError("击中的物体名字: " + hit.collider.gameObject.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnShow()
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
dragItem?.OnBeginDragEvent.RemoveListener(OnBeginDrag);
|
|
dragItem?.OnEndDragEvent.RemoveListener(OnEndDrag);
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
}
|
|
}
|
|
}
|