You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
[RequireComponent(typeof(Canvas))]
public class UCGraphicRaycaster : GraphicRaycaster
{
[SerializeField]
private Camera MonitorCamera;
public bool castMouseOnly = false;
public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
{
if (castMouseOnly && eventData.pointerId != -1)
return;
if (MonitorCamera != null && eventCamera != null)
{
//Debug.Log(eventData.position);
Vector2 position = eventData.position;
position.x /= MonitorCamera.pixelRect.width;
position.y /= MonitorCamera.pixelRect.height;
position.x *= eventCamera.pixelRect.width;
position.y *= eventCamera.pixelRect.height;
eventData.position = position;
//Debug.Log("Screen Size: " + MonitorCamera.pixelRect.width + " " + MonitorCamera.pixelRect.height);
//Debug.Log("Target Size: " + eventCamera.pixelRect.width + " " + eventCamera.pixelRect.height);
//Debug.Log(eventData.position);
}
base.Raycast(eventData, resultAppendList);
}
}