Hello,
I am trying to create multiple pointers while using the event system so I can use the built in event systems like the IDropHandler interfaces. I initially was going to create my own raycast system to detect the corners of my rect transform…but figured registering the corners as multiple “mouse positions” might be better for incorporating the UI event system.
Basically when the corners of the transform intersect with other rect transforms, I want the same regular unity events to occur as if a mouse input position was in the same position…ie, hovering, pressing, dropping, etc.
I added a new pointer event data using the current event system…but there seems to be no events being triggered based on position of the pointer event data… How do you trigger these events using custom pointer event datas?
public class DragHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
[SerializeField] private Canvas canvas;
[SerializeField] private CanvasGroup canvasGroup;
[SerializeField] private EventSystem system;
private RectTransform rectTrans;
private PointerEventData[] cornerPointers = new PointerEventData[4];
private void Awake()
{
rectTrans = GetComponent<RectTransform>();
for (int i = 0; i < cornerPointers.Length; i++)
cornerPointers[i] = new PointerEventData(system);
}
public void OnBeginDrag(PointerEventData eventData)
{
canvasGroup.blocksRaycasts = false;
rectTrans.transform.position = eventData.position;
}
public void OnDrag(PointerEventData eventData)
{
DoCornerCast();
rectTrans.position += (Vector3)eventData.delta;
}
public void OnEndDrag(PointerEventData eventData)
{
canvasGroup.blocksRaycasts = true;
}
protected virtual void DoCornerCast()
{
var corners = new Vector3[4];
rectTrans.GetWorldCorners(corners);
for (int i = 0; i < corners.Length; i++)
{
cornerPointers[i].position = corners[i];
}
}
}