using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; public class LockPanelHandleCtr : MonoBehaviour, IPointerDownHandler { public RectTransform _SelfRec; public RectTransform _BGRec; //用背景尺寸计算 public GameObject _DescText; private float _MaxAnchoredVal = 0; private float _MistakeVal = 0.5f; //误差距离 private void GetMaxAnchoredVal() { _MaxAnchoredVal = _BGRec.rect.width - gameObject.GetComponent().rectTransform.rect.width - _MistakeVal; } private void OnEnable() { Reset(); GetMaxAnchoredVal(); } private void Reset() { _SelfRec.anchoredPosition = new Vector2(0, 0); _DescText.SetActive(true); } public void OnDrag(PointerEventData eventData) { if(_SelfRec.anchoredPosition.x >= _MaxAnchoredVal) { if (LockPanelCtr.Instance) LockPanelCtr.Instance.OnUnLock(); } else { _SelfRec.anchoredPosition = new Vector2(Mathf.Clamp(_SelfRec.anchoredPosition.x + eventData.delta.x, 0, _MaxAnchoredVal), 0); if(_DescText.activeInHierarchy) _DescText.SetActive(false); } } public void OnPointerUp(PointerEventData eventData) { if(_SelfRec.anchoredPosition.x >= _MaxAnchoredVal) { if (LockPanelCtr.Instance) LockPanelCtr.Instance.OnUnLock(); } else { Reset(); } } public void OnPointerDown(PointerEventData eventData) { if (LockPanelCtr.Instance) LockPanelCtr.Instance.OnUnLock(); return; } }