using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using XRLib.UI; namespace Studio { public class UI_DragDrop_ : MonoBehaviour,IBeginDragHandler,IDragHandler,IEndDragHandler,IDropHandler { GameObject Clone; public float cloneAlpha=1f; public Action OnDropItem; public void OnBeginDrag(PointerEventData eventData) { Clone=Instantiate(gameObject,gameObject.transform.parent); Clone.GetComponent().blocksRaycasts = false; var CI = Clone.GetComponentsInChildren(); foreach(var c in CI) { c.color = new Color(c.color.r, c.color.g, c.color.b, cloneAlpha); } } public void OnDrag(PointerEventData eventData) { Clone.transform.position = Input.mousePosition; } public void OnEndDrag(PointerEventData eventData) { Destroy(Clone); } public void OnDrop(PointerEventData eventData) { if (eventData.pointerDrag != null) { UI_DragDrop_ draggedItem = eventData.pointerDrag.GetComponent(); if (draggedItem) { OnDropItem?.Invoke(gameObject.GetComponent(), draggedItem.GetComponent()); } } } } }