150 lines
4.0 KiB
C#
150 lines
4.0 KiB
C#
|
|
using F3Device.Screen;
|
|||
|
|
using QFramework;
|
|||
|
|
using QFramework.Example;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using static UnityEngine.GraphicsBuffer;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ͨ<><CDA8><EFBFBD><EFBFBD>ק<EFBFBD><D7A7><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public class DragUIItem : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
|||
|
|
{
|
|||
|
|
public string targetName; // Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
private RectTransform rectTransform;
|
|||
|
|
private Canvas canvas;
|
|||
|
|
private Vector2 startPosition;
|
|||
|
|
private LayoutGroup parentLayoutGroup;
|
|||
|
|
private GraphicRaycaster graphicRaycaster;
|
|||
|
|
private int startIndex;
|
|||
|
|
|
|||
|
|
public bool IsFirst = true;
|
|||
|
|
|
|||
|
|
private void Awake()
|
|||
|
|
{
|
|||
|
|
rectTransform = GetComponent<RectTransform>();
|
|||
|
|
canvas = GetComponentInParent<Canvas>();
|
|||
|
|
graphicRaycaster = canvas.GetComponent<GraphicRaycaster>();
|
|||
|
|
startPosition = rectTransform.anchoredPosition;
|
|||
|
|
parentLayoutGroup = GetComponentInParent<LayoutGroup>();
|
|||
|
|
|
|||
|
|
raycastResults = new List<RaycastResult>();
|
|||
|
|
IsFirst = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
if (parentLayoutGroup != null)
|
|||
|
|
{
|
|||
|
|
parentLayoutGroup.enabled = false;
|
|||
|
|
|
|||
|
|
if (parentLayoutGroup.GetComponent<ContentSizeFitter>() != null)
|
|||
|
|
parentLayoutGroup.GetComponent<ContentSizeFitter>().enabled = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
startIndex = transform.GetSiblingIndex();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnDrag(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
rectTransform.transform.position = Input.mousePosition;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool isRight;
|
|||
|
|
List<RaycastResult> raycastResults;
|
|||
|
|
private GameObject target;
|
|||
|
|
|
|||
|
|
public void OnEndDrag(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
raycastResults.Clear();
|
|||
|
|
EventSystem.current.RaycastAll(eventData, raycastResults);
|
|||
|
|
|
|||
|
|
target = null;
|
|||
|
|
foreach (var result in raycastResults)
|
|||
|
|
{
|
|||
|
|
if (result.gameObject.name == targetName)
|
|||
|
|
{
|
|||
|
|
target = result.gameObject;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (target != null)
|
|||
|
|
{
|
|||
|
|
if (IsFirst)
|
|||
|
|
{
|
|||
|
|
ScoreController.Instance.Add("<22><>ά<EFBFBD><CEAC><EFBFBD>쿼<EFBFBD><ECBFBC>", 1);
|
|||
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>1<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ק");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD>һ<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD>÷֣<C3B7>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBC>⣬<EFBFBD><E2A3AC>ֹ<EFBFBD>ٴα<D9B4><CEB1><EFBFBD>ק
|
|||
|
|
GraphicRaycaster graphicRaycaster = GetComponent<GraphicRaycaster>();
|
|||
|
|
if (graphicRaycaster != null)
|
|||
|
|
{
|
|||
|
|
graphicRaycaster.enabled = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>߽<EFBFBD><DFBD><EFBFBD>Image<67><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>raycastTarget
|
|||
|
|
Image image = GetComponent<Image>();
|
|||
|
|
if (image != null)
|
|||
|
|
{
|
|||
|
|
image.raycastTarget = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
gameObject.SetActive(false);
|
|||
|
|
target.gameObject.transform.Find("Text (Legacy)").gameObject.SetActive(true);
|
|||
|
|
if (parentLayoutGroup != null)
|
|||
|
|
{
|
|||
|
|
parentLayoutGroup.enabled = true;
|
|||
|
|
|
|||
|
|
if (parentLayoutGroup.GetComponent<ContentSizeFitter>() != null)
|
|||
|
|
parentLayoutGroup.GetComponent<ContentSizeFitter>().enabled = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
IsFirst = false;
|
|||
|
|
ResetPosition(); Debug.Log("<22><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><F3A3ACB2>÷<EFBFBD>");
|
|||
|
|
var data = new UIResultTipData();
|
|||
|
|
data.label = $"<22><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>ã<EFBFBD>";
|
|||
|
|
data.isRight = false;
|
|||
|
|
data.autoHideTime = 0.5f;
|
|||
|
|
UIKit.OpenPanelAsync<UIResultTip>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().Start(this);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
target = null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|||
|
|
private void ResetPosition()
|
|||
|
|
{
|
|||
|
|
transform.SetSiblingIndex(startIndex);
|
|||
|
|
|
|||
|
|
if (parentLayoutGroup != null)
|
|||
|
|
{
|
|||
|
|
parentLayoutGroup.enabled = true;
|
|||
|
|
|
|||
|
|
if (parentLayoutGroup.GetComponent<ContentSizeFitter>() != null)
|
|||
|
|
parentLayoutGroup.GetComponent<ContentSizeFitter>().enabled = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|