public void OnDrag(PointerEventData eventData) { if (!dragging) { return; } // move the dragged object with the mouse transform.position = eventData.position; DropZone zone = GetDropZoneUnderMouse(); Debug.Log(zone); if (zone != currentZoneBelow) { if (zone != null) { zone.OnDraggingEnter(); } if (currentZoneBelow != null) { currentZoneBelow.OnDraggingExit(); } currentZoneBelow = zone; } }
// finds the firstSlot component currently under the mouse private DropZone GetDropZoneUnderMouse() { PointerEventData pointer = new PointerEventData(EventSystem.current); pointer.position = Input.mousePosition; List <RaycastResult> hits = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointer, hits); foreach (RaycastResult hit in hits) { DropZone zone = hit.gameObject.GetComponent <DropZone>(); DropZoneExtention zoneExtention = hit.gameObject.GetComponent <DropZoneExtention>(); if (zoneExtention != null) { return(zoneExtention.zone); } if (zone != null) { return(zone); } } return(null); }
public void AddDraggableToZone(DropZone zone) { zone.OnDraggingExit(); currentZone = zone; transform.SetParent(zone.transform); transform.SetAsLastSibling(); zone.OnDrop(this); }
private void CreateComponents(GameObject prefab, IEnumerable <object> components, DropZone zone, Vector3 position) { foreach (var c in components) { var component = Instantiate(prefab, zone.transform); component.GetComponent <RectTransform>().anchoredPosition = position; var componentUI = component.GetComponent <SpellComponentUIController>(); if (c is string) { componentUI.nameText.text = (string)c; } else if (c is SpellEffect) { componentUI.nameText.text = ((SpellEffect)c).effectName; componentUI.logoText.text = ((SpellEffect)c).effectName.Substring(0, 2).ToUpper(); } var draggable = component.GetComponent <Draggable>(); draggable.data = c; } }
private void CreateComponent(GameObject prefab, object component, DropZone zone, Vector3 position) { CreateComponents(prefab, new List <object> { component }, zone, position); }
// Start is called before the first frame update void Start() { currentZone = transform.GetComponentInParent <DropZone>(); Debug.Log(transform.parent); }