// 직선이 드래그 영역에 포함되는지 확인. public static bool CheckLineIncluded(GraphLine.LinePoint linePoint, DragInfo dragInfo) { if (linePoint.start.x > dragInfo.topLeft.x && linePoint.start.x < dragInfo.topLeft.x + dragInfo.width && linePoint.end.x > dragInfo.topLeft.x && linePoint.end.x < dragInfo.topLeft.x + dragInfo.width && linePoint.start.y < dragInfo.topLeft.y && linePoint.start.y > dragInfo.topLeft.y - dragInfo.height && linePoint.end.y < dragInfo.topLeft.y && linePoint.end.y > dragInfo.topLeft.y - dragInfo.height) { return(true); } return(false); }
// 드래그로 라인 선택하기. public void SetLineSelectedWithDragArea(DragInfo dragInfo) { if (locatedLineList.Count == 0) { return; } for (int ix = 0; ix < locatedLineList.Count; ++ix) { // 라인 정보 구하기. GraphLine.LinePoint linePoint = locatedLineList[ix].GetLinePoint; // 드래그 영역의 4개의 점 구하기. Vector2 topLeft = dragInfo.topLeft; Vector2 topRight = new Vector2(dragInfo.topLeft.x + dragInfo.width, dragInfo.topLeft.y); Vector2 lowerLeft = new Vector2(dragInfo.topLeft.x, dragInfo.topLeft.y - dragInfo.height); Vector2 lowerRight = new Vector2(dragInfo.topLeft.x + dragInfo.width, dragInfo.topLeft.y - dragInfo.height); // 충돌 여부 확인. bool top = Util.CheckLineIntersect(linePoint.start, linePoint.end, topLeft, topRight); bool left = Util.CheckLineIntersect(linePoint.start, linePoint.end, topLeft, lowerLeft); bool right = Util.CheckLineIntersect(linePoint.start, linePoint.end, topRight, lowerRight); bool bottom = Util.CheckLineIntersect(linePoint.start, linePoint.end, lowerLeft, lowerRight); // 라인이 드래그 영역에 포함되는지 여부 확인. bool isIncluded = Util.CheckLineIncluded(linePoint, dragInfo); // 충돌. if (top || left || right || bottom || isIncluded) { SetLineSelectionByDrag(locatedLineList[ix]); continue; } else { SetLineUnSelected(locatedLineList[ix]); } } }
protected virtual void Awake() { dragItem = GetComponentInParent <DragItem>(); refRectTransform = GetComponent <RectTransform>(); linePoint = new GraphLine.LinePoint(Vector2.zero, Vector2.zero); }