private void OnDownHandler(UUIEventListener listener) { int touchID = listener.pointerEventData.pointerId; Vector3 pos = listener.pointerEventData.position; m_panelTouchPosDict[touchID] = pos; if (m_panelTouchPosDict.Count == 2) { Vector2 from = new Vector2(); Vector2 to = new Vector2(); int index = 0; foreach (var touch in m_panelTouchPosDict) { m_rawScaleFinger[index] = touch.Key; if (index++ == 0) { from = touch.Value; } else { to = touch.Value; } } m_rawRect = UIHelper.GetRect(from, to); } }
internal float GetRectScale(ref TRect rect, ref TRect rawRect) { if (rect.width / rect.height > rawRect.width / rawRect.height) { return(rect.width / rawRect.width); } else { return(rect.height / rawRect.height); } }
public bool IsOverLapWith(TRect rect) { float verticalDistance = Mathf.Abs(y - rect.y);; //垂直距离 float horizontalDistance = Mathf.Abs(x - rect.x);; //水平距离 float verticalThreshold = (height + rect.height) / 2; //两矩形分离的垂直临界值 float horizontalThreshold = (width + rect.width) / 2; //两矩形分离的水平临界值 if (verticalDistance > verticalThreshold || horizontalDistance > horizontalThreshold) { return(false); } return(true); }
public bool IsOverLapWith(TRect rect) { float halfWidth = rect.width * 0.5f; float halfHeight = rect.height * 0.5f; float distanceX = Mathf.Abs(x - rect.x); float distanceY = Mathf.Abs(y - rect.y); if (distanceX > (halfWidth + radius) || distanceY > (halfHeight + radius)) { return(false); } else if (distanceX <= halfWidth || distanceY <= halfHeight) { return(true); } float sq = (distanceX - halfWidth) * (distanceX - halfWidth) + (distanceY - halfHeight) * (distanceY - halfHeight); return(sq <= radius * radius); }
private void OnDragHandlerScale(UUIEventListener listener) { int id = listener.pointerEventData.pointerId; Vector2 delta = listener.pointerEventData.delta; Vector2 pos = listener.pointerEventData.position; Vector2 lastPos = pos - delta; m_panelTouchPosDict[id] = pos; if (m_panelTouchPosDict.Count < 2 || (m_rawScaleFinger[0] != id && m_rawScaleFinger[1] != id)) { if (onFingerDrag != null) { onFingerDrag.Invoke(delta); } return; } Vector2 sndPos = Vector2.zero; if (m_rawScaleFinger[0] == id) { sndPos = m_panelTouchPosDict[m_rawScaleFinger[1]]; } else { sndPos = m_panelTouchPosDict[m_rawScaleFinger[0]]; } TRect lastRect = UIHelper.GetRect(lastPos, sndPos); TRect curRect = UIHelper.GetRect(pos, sndPos); float lastScale = GetRectScale(ref lastRect, ref m_rawRect); float curScale = GetRectScale(ref curRect, ref m_rawRect); if (onFingerScroll != null) { onFingerScroll.Invoke(curScale / lastScale); } }
public TEllipse(TRect boundingRect) : this(boundingRect.center, boundingRect.size) { }
public static TRect Lerp(TRect a, TRect b, float t) { return(new TRect(Vector2.Lerp(a.center, b.center, t), Vector2.Lerp(a.size, b.size, t))); }