new UI collisions? detect relative positions

okay…
Iam working on making an UI inventory system… Iam intending to make it like Divine Divinity, where you can freely drag items around your inventory

I have these panels, and i have a child raw image for the gun image

I have a script on the inventory window to be able to drag it around the screen freely, and on the Raw Image of the gun has the draggable window script too

how would I detect when the Raw Image of the gun leaves the panel?

I tried putting RectTransform.anchoredPosition on a Debug.Log on the Raw Image gun… and i can see i could possibly use that value, BUT i wonder if theres another way? thats just easy, like “UI element is over other UI element” or something

Iam VERY new to scripting the new UI … Iam decent scripting in Unity in general C#


this is what it looks like… Inventory window, and then the darker white is actual inventory space, I can currently drag the window and the gun moves with it… and I can drag the gun anywhere on the screen… I want to make it so when I drag the gun onto the transparent area, it snaps back to the less transparent area… and when you drag the gun onto the grass, the raw image disappears, and i instantiate gun at the players feet.
i can handle most of that myself, i just dont know how to detect UI’s positions relative to other UI element positions and stuff… dunno how to script the new UI

alt text

this is the Script C# im currently using to drag the window and raw image around:

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;

public class UIWindowBase : MonoBehaviour, IDragHandler
{
	public static bool ResetCoords = false;
	private RectTransform m_transform = null;
	private Vector3 originalCoods = Vector3.zero;
	

	void Start () 
	{
		m_transform = GetComponent<RectTransform>();
		originalCoods = m_transform.position;
	}
	
	public void OnDrag(PointerEventData eventData)
	{
		m_transform.position += new Vector3(eventData.delta.x, eventData.delta.y);
		
		// magic : add zone clamping if's here.
	}
		
	void Update()
	{
		Debug.Log (m_transform.anchoredPosition);
	}

here you go


in that video he uses IpointerDown/IpointerUp interfaces to detect whether drag/drop had occur

if you want to drop items etc without clicking but only by releasing the item, implement (IDropHandler,IDragHandler,IBeginDragHandler) interfaces