48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
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<UIBase, UIBase> OnDropItem;
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
Clone=Instantiate(gameObject,gameObject.transform.parent);
|
|
Clone.GetComponent<CanvasGroup>().blocksRaycasts = false;
|
|
var CI = Clone.GetComponentsInChildren<Image>();
|
|
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<UI_DragDrop_>();
|
|
if (draggedItem)
|
|
{
|
|
OnDropItem?.Invoke(gameObject.GetComponent<UIBase>(), draggedItem.GetComponent<UIBase>());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|