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

public class ItemHandler : MonoBehaviour, IDragHandler, IEndDragHandler
{
  [SerializeField] private int id;
  public int ID
  {
    get { return id; }
    set { id = value; }
  }

  [SerializeField] private int row;
  public int Row
  {
    get { return row; }
    set { row = value; }
  }

  [SerializeField] private int column;
  public int Column
  {
    get { return column; }
    set { column = value; }
  }

  // ==================================================

  public void OnDrag(PointerEventData eventData)
  {
  }

  public void OnEndDrag(PointerEventData eventData)
  {
    eventData.position = Input.mousePosition; // 设置鼠标位置 // ?无必要

    GraphicRaycaster graphicRaycaster = GameObject.Find("Canvas").GetComponent<GraphicRaycaster>();
    List<RaycastResult> results = new List<RaycastResult>();
    graphicRaycaster.Raycast(eventData, results); // 执行射线检测

    Debug.Log("123123");

    if (results.Count <= 0)
    {
      return;
    }
    if (!results[0].gameObject.GetComponent<ItemHandler>())
    {
      Debug.Log("No");
      return;
    }

    Debug.Log(gameObject.name + "/" + results[0].gameObject.name);
    PuzzleManager.Instance.Move(gameObject, results[0].gameObject);
  }
}