74 lines
1.9 KiB
C#
74 lines
1.9 KiB
C#
|
|
using F3Device.Screen;
|
|||
|
|
using QFramework;
|
|||
|
|
using QFramework.Example;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
|
|||
|
|
public class UIImageDrag_JiHe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
|||
|
|
{
|
|||
|
|
RectTransform rect;
|
|||
|
|
Canvas canvas; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
|||
|
|
|
|||
|
|
List<RaycastResult> raycastResults;
|
|||
|
|
GameObject target;
|
|||
|
|
public Vector3 originPos;
|
|||
|
|
bool isOverTarget = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD>ק
|
|||
|
|
|
|||
|
|
void Awake()
|
|||
|
|
{
|
|||
|
|
rect = GetComponent<RectTransform>();
|
|||
|
|
canvas = GetComponentInParent<Canvas>(); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Canvas
|
|||
|
|
|
|||
|
|
|
|||
|
|
originPos = rect.transform.localPosition;
|
|||
|
|
|
|||
|
|
raycastResults = new List<RaycastResult>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnDrag(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
rect.transform.position = Input.mousePosition;
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnEndDrag(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
var uiPanel = UIKit.GetPanel<UIImageSelectMap_JiHe>();
|
|||
|
|
if (uiPanel == null) return;
|
|||
|
|
|
|||
|
|
// <20><>ȡĿ<C8A1><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
string targetObjName = uiPanel.Data.TargetObj;
|
|||
|
|
|
|||
|
|
// <20>жϵ<D0B6>ǰ<EFBFBD><C7B0>ק<EFBFBD><D7A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>
|
|||
|
|
if (isOverTarget && target != null && target.name == targetObjName)
|
|||
|
|
{
|
|||
|
|
Debug.Log("<22>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>õ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " + targetObjName);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>гɹ<D0B3><C9B9><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>
|
|||
|
|
// <20><><EFBFBD>磺<EFBFBD><E7A3BA><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD>ù̶<C3B9><CCB6><EFBFBD>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
|||
|
|
transform.position = target.transform.position;
|
|||
|
|
|
|||
|
|
// ֪ͨUI<55><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|||
|
|
// uiPanel.OnDragSuccess();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.Log("δ<><CEB4><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ȷĿ<C8B7>꣬<EFBFBD><EAA3AC><EFBFBD><EFBFBD>ԭλ");
|
|||
|
|
Debug.Log(originPos+"??????");
|
|||
|
|
// δ<><CEB4><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ȷĿ<C8B7>꣬<EFBFBD><EAA3AC><EFBFBD><EFBFBD>ԭʼλ<CABC><CEBB>
|
|||
|
|
rect.anchoredPosition = Vector3.zero;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>״̬
|
|||
|
|
isOverTarget = false;
|
|||
|
|
target = null;
|
|||
|
|
}
|
|||
|
|
}
|