2025-06-19 18:23:31 +08:00
|
|
|
|
using F3Device.Screen;
|
|
|
|
|
|
using QFramework;
|
|
|
|
|
|
using QFramework.Example;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
2025-06-20 18:32:18 +08:00
|
|
|
|
using UnityEngine.UI;
|
2025-06-19 18:23:31 +08:00
|
|
|
|
|
|
|
|
|
|
public class UIImageDrag_JiHe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
|
|
|
|
|
{
|
|
|
|
|
|
RectTransform rect;
|
|
|
|
|
|
Canvas canvas; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
|
|
|
|
|
|
|
|
|
|
|
List<RaycastResult> raycastResults;
|
2025-06-20 18:32:18 +08:00
|
|
|
|
public GameObject target;
|
2025-07-01 17:54:39 +08:00
|
|
|
|
//public string targetObjName = uiPanel.Data.TargetObj;
|
|
|
|
|
|
public string targetObjName;
|
2025-06-20 18:32:18 +08:00
|
|
|
|
public Vector3 originPos;
|
2025-06-19 18:23:31 +08:00
|
|
|
|
bool isOverTarget = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD>ק
|
2025-06-20 18:32:18 +08:00
|
|
|
|
bool isRight = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ
|
2025-06-19 18:23:31 +08:00
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
rect = GetComponent<RectTransform>();
|
2025-06-20 18:32:18 +08:00
|
|
|
|
canvas = GetComponentInParent<Canvas>();
|
|
|
|
|
|
originPos = rect.anchoredPosition;
|
|
|
|
|
|
raycastResults = new List<RaycastResult>();
|
2025-06-19 18:23:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-20 18:32:18 +08:00
|
|
|
|
// ֻ<><D6BB><EFBFBD>ڷ<EFBFBD><DAB7>ò<EFBFBD><C3B2><EFBFBD>ȷʱ<C8B7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ק
|
2025-06-19 18:23:31 +08:00
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
|
|
|
|
{
|
2025-06-20 18:32:18 +08:00
|
|
|
|
if (!isRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
// ȷ<><C8B7><EFBFBD><EFBFBD>קʱ<D7A7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>
|
|
|
|
|
|
transform.SetAsLastSibling();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><>ֹ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
eventData.Use();
|
|
|
|
|
|
}
|
2025-06-19 18:23:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-20 18:32:18 +08:00
|
|
|
|
// ֻ<><D6BB><EFBFBD>ڷ<EFBFBD><DAB7>ò<EFBFBD><C3B2><EFBFBD>ȷʱ<C8B7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ק
|
2025-06-19 18:23:31 +08:00
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
|
|
|
|
{
|
2025-06-20 18:32:18 +08:00
|
|
|
|
if (!isRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
rect.transform.position = Input.mousePosition;
|
|
|
|
|
|
}
|
2025-06-19 18:23:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-20 18:32:18 +08:00
|
|
|
|
// ֻ<><D6BB><EFBFBD>ڷ<EFBFBD><DAB7>ò<EFBFBD><C3B2><EFBFBD>ȷʱ<C8B7>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>ק<EFBFBD><D7A7><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
2025-06-19 18:23:31 +08:00
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
|
|
|
|
{
|
2025-06-20 18:32:18 +08:00
|
|
|
|
if (isRight) return;
|
|
|
|
|
|
|
2025-06-19 18:23:31 +08:00
|
|
|
|
var uiPanel = UIKit.GetPanel<UIImageSelectMap_JiHe>();
|
2025-06-20 18:32:18 +08:00
|
|
|
|
if (uiPanel == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rect.anchoredPosition = originPos;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-06-19 18:23:31 +08:00
|
|
|
|
|
2025-07-01 17:54:39 +08:00
|
|
|
|
|
2025-06-19 18:23:31 +08:00
|
|
|
|
|
2025-06-20 18:32:18 +08:00
|
|
|
|
raycastResults.Clear();
|
|
|
|
|
|
EventSystem.current.RaycastAll(eventData, raycastResults);
|
|
|
|
|
|
|
|
|
|
|
|
target = null;
|
|
|
|
|
|
foreach (var result in raycastResults)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (result.gameObject.name == targetObjName)
|
|
|
|
|
|
{
|
|
|
|
|
|
target = result.gameObject;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (target != null)
|
2025-06-19 18:23:31 +08:00
|
|
|
|
{
|
2025-06-20 18:32:18 +08:00
|
|
|
|
var frame = target.transform.Find("Frame").gameObject;
|
|
|
|
|
|
frame.GetComponent<Image>().color = Color.green;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rect.parent = frame.gameObject.transform;
|
|
|
|
|
|
rect.anchoredPosition =new Vector2(-15, 45);
|
|
|
|
|
|
rect.sizeDelta = new Vector2(176.3376f, 142.2313f);
|
|
|
|
|
|
isRight = true;
|
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ק");
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBC>⣬<EFBFBD><E2A3AC>ֹ<EFBFBD>ٴα<D9B4><CEB1><EFBFBD>ק
|
|
|
|
|
|
GraphicRaycaster graphicRaycaster = GetComponent<GraphicRaycaster>();
|
|
|
|
|
|
if (graphicRaycaster != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
graphicRaycaster.enabled = false;
|
|
|
|
|
|
}
|
2025-06-19 18:23:31 +08:00
|
|
|
|
|
2025-06-20 18:32:18 +08:00
|
|
|
|
// <20><><EFBFBD>߽<EFBFBD><DFBD><EFBFBD>Image<67><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>raycastTarget
|
|
|
|
|
|
Image image = GetComponent<Image>();
|
|
|
|
|
|
if (image != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
image.raycastTarget = false;
|
|
|
|
|
|
}
|
2025-06-19 18:23:31 +08:00
|
|
|
|
|
|
|
|
|
|
// ֪ͨUI<55><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2025-06-20 18:32:18 +08:00
|
|
|
|
// uiPanel.OnDragSuccess();
|
2025-06-19 18:23:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-06-20 18:32:18 +08:00
|
|
|
|
rect.anchoredPosition = originPos;
|
2025-07-01 17:54:39 +08:00
|
|
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(rect.transform.parent.GetComponent<RectTransform>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-06-19 18:23:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isOverTarget = false;
|
|
|
|
|
|
target = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|