|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System;
|
|
|
|
|
using AX.InputSystem;
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI<EFBFBD>϶<EFBFBD><EFBFBD>Ľű<EFBFBD>,<EFBFBD>ýű<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><EFBFBD>϶<EFBFBD><EFBFBD><EFBFBD>panel<EFBFBD><EFBFBD><EFBFBD><EFBFBD>panel<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>canvas<EFBFBD>£<EFBFBD><EFBFBD>µ<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><EFBFBD><EFBFBD>panel<EFBFBD><EFBFBD><EFBFBD><EFBFBD>canvas<EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD>
|
|
|
|
|
[RequireComponent(typeof(CreateStaticObjID))]
|
|
|
|
|
[RequireComponent(typeof(BaseGameObjInfo))]
|
|
|
|
|
public class DragPanel : MonoBehaviour, IDragHandler, IEndDragHandler,IBeginDragHandler
|
|
|
|
|
{
|
|
|
|
|
private Vector2 originalLocalPointerPosition;
|
|
|
|
|
private Vector3 originalPanelLocalPosition;
|
|
|
|
|
private RectTransform panelRectTransform;//Ҫ<EFBFBD>϶<EFBFBD><EFBFBD><EFBFBD>panel
|
|
|
|
|
private RectTransform parentRectTransform;//<EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><EFBFBD><EFBFBD>panel<EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><EFBFBD><EFBFBD>Canvas<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
panelRectTransform = transform.parent as RectTransform;
|
|
|
|
|
parentRectTransform = panelRectTransform.parent as RectTransform;
|
|
|
|
|
}
|
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if (eventData.button != PointerEventData.InputButton.Left) return;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ק
|
|
|
|
|
var arg = new OnDragCmdArgs();
|
|
|
|
|
arg.position = eventData.position;
|
|
|
|
|
DragBegin(arg);
|
|
|
|
|
InputManager.isDargUI = true;
|
|
|
|
|
}
|
|
|
|
|
public void DragBegin(OnDragCmdArgs args)
|
|
|
|
|
{
|
|
|
|
|
RegisterUIInputEvent.RegisterUIInputHistory(gameObject, this.GetType().Name, "DragBegin", args);
|
|
|
|
|
originalPanelLocalPosition = panelRectTransform.localPosition;
|
|
|
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRectTransform, args.position, null, out originalLocalPointerPosition);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void OnDrag(PointerEventData data)
|
|
|
|
|
{
|
|
|
|
|
if (data.button != PointerEventData.InputButton.Left) return;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ק
|
|
|
|
|
var arg = new OnDragCmdArgs();
|
|
|
|
|
arg.position = data.position;
|
|
|
|
|
Drag(arg);
|
|
|
|
|
}
|
|
|
|
|
public void Drag(OnDragCmdArgs args)
|
|
|
|
|
{
|
|
|
|
|
RegisterUIInputEvent.RegisterUIInputHistory(gameObject, this.GetType().Name, "Drag", args);
|
|
|
|
|
|
|
|
|
|
if (panelRectTransform == null || parentRectTransform == null)
|
|
|
|
|
return;
|
|
|
|
|
Vector2 localPointerPosition;
|
|
|
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRectTransform, args.position, null, out localPointerPosition))
|
|
|
|
|
{
|
|
|
|
|
Vector3 offsetToOriginal = localPointerPosition - originalLocalPointerPosition;
|
|
|
|
|
panelRectTransform.localPosition = originalPanelLocalPosition + offsetToOriginal;
|
|
|
|
|
}
|
|
|
|
|
ClampToWindow();
|
|
|
|
|
}
|
|
|
|
|
void ClampToWindow()
|
|
|
|
|
{
|
|
|
|
|
Vector3 pos = panelRectTransform.localPosition;
|
|
|
|
|
|
|
|
|
|
Vector3 minPosition = parentRectTransform.rect.min - panelRectTransform.rect.min;
|
|
|
|
|
Vector3 maxPosition = parentRectTransform.rect.max - panelRectTransform.rect.max;
|
|
|
|
|
|
|
|
|
|
pos.x = Mathf.Clamp(panelRectTransform.localPosition.x, minPosition.x, maxPosition.x);
|
|
|
|
|
pos.y = Mathf.Clamp(panelRectTransform.localPosition.y, minPosition.y, maxPosition.y);
|
|
|
|
|
panelRectTransform.localPosition = pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if (eventData.button != PointerEventData.InputButton.Left) return;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ק
|
|
|
|
|
var arg = new OnDragCmdArgs();
|
|
|
|
|
arg.currentCursorPos = Input.mousePosition;
|
|
|
|
|
RegisterUIInputEvent.RegisterUIInputHistory(gameObject, this.GetType().Name, "EndDrag", arg);
|
|
|
|
|
EndDrag(arg);
|
|
|
|
|
}
|
|
|
|
|
public void EndDrag(CmdArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (GameSettings.othersSettings.playState == PlayState.Playing)
|
|
|
|
|
{
|
|
|
|
|
CursorManager.GetInstance.SetClick(args);
|
|
|
|
|
}
|
|
|
|
|
InputManager.isDargUI = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|