public override void exitNotPhone() { for (int i = 0; i < data.pointList.Count; i++) { bool contine = false; Point item = data.pointList[i]; for (int j = 0; j < data.wallList.Count; j++) { WallData wall = data.wallList[j]; if (wall.Contines(item)) { contine = true; break; } } //for (int j = 0; j < helperData.helpLineList.Count; j++) //{ // WallData wall = helperData.helpLineList[j]; // if (wall.Contines(item)) // { // contine = true; // break; // } //} if (contine == false) { data.RemovePoint(item); i--; } } base.exitNotPhone(); }
public override void exitPhone() { SetWallController.Instance.Close(); phoneHelperData.sleep(); for (int i = 0; i < data.pointList.Count; i++) { bool contine = false; Point item = data.pointList[i]; for (int j = 0; j < data.wallList.Count; j++) { WallData wall = data.wallList[j]; if (wall.Contines(item)) { contine = true; break; } } if (contine == false) { data.RemovePoint(item); i--; } } base.exitPhone(); }
public List <WallData> GetWallList(Point target) { List <WallData> list = new List <WallData>(); for (int i = 0; i < data.wallList.Count; i++) { WallData item = data.wallList[i]; if (item.Contines(target)) { list.Add(item); } } return(list); }
public override void mUpdate() { base.mUpdate(); if (changed) { return; } if (uguiHitUI.uiHited == true) { return; } if (canMove == false) { if (Input.GetMouseButtonUp(0) == false) { return; } } if (Input.GetMouseButtonDown(0)) { saved = false; } if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { //Debug.LogWarning("Input.GetMouseButton(0)"); Vector2 pos = GetScreenToWorldPos(Input.mousePosition); if (lastMousePos == pos && Input.GetMouseButtonUp(0) == false) { return; } lastMousePos = pos; if (saved == false) { saved = true; } Vector2 v2 = pos; Point nearPoint = null; WallData nearWall = null; //bool nearPointAxis = false; //bool cross = false; float minDis = 0.3f; for (int i = 0; i < data.pointList.Count; i++) { Point item = data.pointList[i]; if (item == target) { continue; } float dis = Vector2.Distance(item.pos, pos); if (dis < minDis) { nearPoint = item; v2 = item.pos; minDis = dis; } } if (nearPoint == null) { minDis = 0.25f; for (int i = 0; i < data.wallList.Count; i++) { WallData item = data.wallList[i]; if (item.Contines(target) == true) { continue; } float dis = item.GetDis(pos); if (dis > minDis) { continue; } Vector2 nearV2 = item.GetDisPoint(pos); if (wallfunc.PointOnWall(nearV2, item)) { nearWall = item; v2 = nearV2; break; } } } if (nearPoint == null && nearWall == null) { minDis = 0.15f; for (int i = 0; i < data.pointList.Count; i++) { Point item = data.pointList[i]; if (item == target) { continue; } if (Mathf.Abs(pos.x - item.pos.x) < minDis) { v2.x = item.pos.x; //nearPointAxis = true; } if (Mathf.Abs(pos.y - item.pos.y) < minDis) { v2.y = item.pos.y; //nearPointAxis = true; } } } //for (int i = 0; i < data.wallList.Count; i++) //{ // WallData wall = data.wallList[i]; // if (wall.Contines(target)) // { // continue; // } // if (nearPoint != null && wall.Contines(nearPoint)) // { // continue; // } // if (nearWall != null && wall == nearWall) // { // continue; // } // List<Point> list = data.GetNearestPoints(target); // for (int k = 0; k < list.Count; k++) // { // if (linefunc.GetCross(wall, list[k], v2) == true) // { // cross = true; // break; // } // } // if (cross == true) // { // break; // } //} ////if (cross == false) ////{ bool equl = false; if (target.pos == v2) { equl = true; } target.pos = v2; bool up = false; if (Input.GetMouseButtonUp(0)) { canMove = false; up = true; if (nearPoint != null) { data.CombinePoint(nearPoint, target); if (target == null || data.Contins(target) == false) { setState(FreeState2D.NAME); } } else if (nearWall != null) { data.CombinePointWall(target, nearWall); } targetList.Clear(); ///target 临边新位置产生的切分(不包括临边顶点的切分) List <Point> list = data.GetNearestPoints(target); for (int k = 0; k < list.Count; k++) { WallData targetWall = data.GetWall(list[k], target); targetList.Add(targetWall); ///target 临边切分其他墙体 for (int i = 0; i < data.wallList.Count; i++) { WallData item = data.wallList[i]; if (item == targetWall) { continue; } bool p1OnItem = false; bool p2OnItem = false; bool targetCrossItem = false; if (item.Contines(targetWall.point1) == true || item.Contines(targetWall.point2) == true) { if (item.Contines(targetWall.point1) == false && wallfunc.PointOnWall(targetWall.point1, item)) { p1OnItem = true; } if (item.Contines(targetWall.point2) == false && wallfunc.PointOnWall(targetWall.point2, item)) { p2OnItem = true; } } else { if (wallfunc.PointOnWall(targetWall.point1, item)) { p1OnItem = true; } if (wallfunc.PointOnWall(targetWall.point2, item)) { p2OnItem = true; } if (p1OnItem == false && p2OnItem == false) { if (wallfunc.PointOnWall(item.point1, targetWall) == false && wallfunc.PointOnWall(item.point2, targetWall) == false && linefunc.GetCross(item, targetWall)) { targetCrossItem = true; } } } if (p1OnItem == true && p2OnItem == true) { data.RemovePoint(targetWall.point1); data.RemovePoint(targetWall.point2); targetWall = item; } else if (p1OnItem == true) { data.CombinePointWall(targetWall.point1, item); } else if (p2OnItem == true) { data.CombinePointWall(targetWall.point2, item); } else if (targetCrossItem == true) { bool isParallel = linefunc.IsTwoLineParallel(item, targetWall); if (isParallel == false)///targetCrossItem == true 好像永远不会出现item, target平行的情况 { Vector2 crossP = linefunc.GetTwoLineCrossPoint(item, targetWall, Vector2.zero); Point point = new Point(crossP); data.AddPoint(point); data.CombinePointWall(point, item); i--; } } if (p1OnItem == true || p2OnItem == true) { i--; } } //for (int i = 0; i < data.wallList.Count; i++) //{ // WallData wall = data.wallList[i]; // if (wall.Contines(list[k]) || wall.Contines(target)) continue; // if (linefunc.GetCross(wall, targetWall) == true) // { // Vector2 cross = linefunc.GetTwoLineCrossPoint(wall, targetWall, Vector2.zero); // Point crossP = new Point(cross); // data.AddPoint(crossP); // data.CombinePointWall(crossP, wall); // i--; // //continue; // } //} } ///其他点切分target for (int i = 0; i < data.pointList.Count; i++) { Point point = data.pointList[i]; for (int k = 0; k < targetList.Count; k++) { WallData wall = targetList[k]; if (point == wall.point1 || point == wall.point2) { continue; } if (wallfunc.PointOnWall(point, wall)) { List <WallData> newTargetwalls = data.CombinePointWall(point, wall); targetList.RemoveAt(k); targetList.InsertRange(k, newTargetwalls); k--; } } } roomfunc.ForceRefreshRoomData(data); } if (up == false && equl == true) { return; } RefreshView(); //} //else //{ //} } }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="mousePos">鼠标位置</param> /// <returns></returns> private Vector2 AdjustPoint(ref Point point, ref bool crossed, ref OnWallType type, Vector2 mousePos) { Vector2 v2 = mousePos; float minDis = 0.09f; //bool nearPointAxis = false; WallData nearWall = null; WallData nearHelpWall = null; for (int i = 0; i < data.pointList.Count; i++) { float dis = Vector2.SqrMagnitude(data.pointList[i].pos - mousePos); if (dis < minDis) { point = data.pointList[i]; v2 = point.pos; minDis = dis; type = OnWallType.OnJustHelpWallPoint; for (int j = 0; j < data.wallList.Count; j++) { if (data.wallList[j].Contines(point)) { type = OnWallType.OnWallPoint; break; } } } } bool obliqueChooseX = false; if (point == null) { if (defaultSetting.oblique == false) { float xDis = v2.x - helperData.currentPoint.pos.x; float yDis = v2.y - helperData.currentPoint.pos.y; if (Mathf.Abs(xDis) <= Mathf.Abs(yDis)) { v2.x = mousePos.x = helperData.currentPoint.pos.x; obliqueChooseX = true; } else { v2.y = mousePos.y = helperData.currentPoint.pos.y; } minDis = 0.09f; for (int i = 0; i < data.pointList.Count; i++) { float dis = Vector2.SqrMagnitude(data.pointList[i].pos - mousePos); if (dis < minDis) { point = data.pointList[i]; v2 = point.pos; minDis = dis; type = OnWallType.OnJustHelpWallPoint; for (int j = 0; j < data.wallList.Count; j++) { if (data.wallList[j].Contines(point)) { type = OnWallType.OnWallPoint; break; } } } } } } if (point == null) { minDis = 0.3f; for (int i = 0; i < data.wallList.Count; i++) { WallData item = data.wallList[i]; float dis = item.GetDis(mousePos); if (dis > minDis) { continue; } //minDis = dis; Vector2 nearV2 = item.GetDisPoint(mousePos); if (wallfunc.PointOnWall(nearV2, item)) { type = OnWallType.OnWallSide; nearWall = item; v2 = nearV2; } } } if (point == null && nearWall == null) { minDis = 0.25f; for (int i = 0; i < helperData.helpLineList.Count; i++) { WallData item = helperData.helpLineList[i]; float dis = item.GetDis(mousePos); if (dis > minDis) { continue; } //minDis = dis; Vector2 nearV2 = item.GetDisPoint(mousePos); if (wallfunc.PointOnWall(nearV2, item)) { type = OnWallType.OnHelpWallSide; nearHelpWall = item; v2 = nearV2; } } } if (helperData.helpLineList.Count >= 1) { //向量1 Vector2 vector1 = v2 - helperData.currentPoint.pos; WallData wall = helperData.helpLineList[helperData.helpLineList.Count - 1]; Vector2 vector2 = wall.point1.pos - wall.point2.pos; float angle = GetAngle(vector1, vector2); if (angle < 15) { crossed = true; } } if (point == null && nearWall == null && nearHelpWall == null) { minDis = 0.2f; for (int i = 0; i < data.pointList.Count; i++) { Point item = data.pointList[i]; if (Mathf.Abs(mousePos.x - item.pos.x) < minDis) { if (defaultSetting.oblique == true || obliqueChooseX == false) { v2.x = item.pos.x; } //nearPointAxis = true; } if (Mathf.Abs(mousePos.y - item.pos.y) < minDis) { if (defaultSetting.oblique == true || obliqueChooseX == true) { v2.y = item.pos.y; } //nearPointAxis = true; } } } for (int i = 0; i < data.wallList.Count; i++) { WallData wall = data.wallList[i]; if (point != null && wall.Contines(point)) { continue; } else if (nearWall != null && wall == nearWall) { continue; } if (linefunc.GetCross(wall, helperData.currentPoint, v2) == true) { crossed = true; } } for (int i = 0; i < helperData.helpLineList.Count; i++) { WallData wall = helperData.helpLineList[i]; if (point != null && wall.Contines(point)) { continue; } else if (nearHelpWall != null && wall == nearHelpWall) { continue; } if (linefunc.GetCross(wall, helperData.currentPoint, v2) == true) { crossed = true; } } return(v2); }
private Vector2 AdjustPhonePoint(ref Point point, ref bool crossed, ref OnWallType type, Vector2 inputPos) { Vector2 v2 = inputPos; float minDis = 0.09f; //bool nearPointAxis = false; WallData nearWall = null; for (int i = 0; i < data.pointList.Count; i++) { float dis = Vector2.SqrMagnitude(data.pointList[i].pos - inputPos); if (dis < minDis) { point = data.pointList[i]; v2 = point.pos; minDis = dis; type = OnWallType.OnWallPoint; } } bool obliqueChooseX = false; if (point == null) { if (defaultSetting.oblique == false) { float xDis = v2.x - phoneHelperData.currentPoint.pos.x; float yDis = v2.y - phoneHelperData.currentPoint.pos.y; if (Mathf.Abs(xDis) <= Mathf.Abs(yDis)) { v2.x = inputPos.x = phoneHelperData.currentPoint.pos.x; obliqueChooseX = true; } else { v2.y = inputPos.y = phoneHelperData.currentPoint.pos.y; } } minDis = 0.09f; for (int i = 0; i < data.pointList.Count; i++) { float dis = Vector2.SqrMagnitude(data.pointList[i].pos - inputPos); if (dis < minDis) { point = data.pointList[i]; v2 = point.pos; minDis = dis; type = OnWallType.OnWallPoint; } } } if (point == null) { minDis = 0.3f; for (int i = 0; i < data.wallList.Count; i++) { WallData item = data.wallList[i]; float dis = item.GetDis(inputPos); if (dis > minDis) { continue; } //minDis = dis; Vector2 nearV2 = item.GetDisPoint(inputPos); if (wallfunc.PointOnWall(nearV2, item)) { type = OnWallType.OnWallSide; nearWall = item; v2 = nearV2; } } } if (point == null && nearWall == null) { minDis = 0.2f; for (int i = 0; i < data.pointList.Count; i++) { Point item = data.pointList[i]; if (Mathf.Abs(inputPos.x - item.pos.x) < minDis) { if (defaultSetting.oblique == true || obliqueChooseX == false) { v2.x = item.pos.x; } //nearPointAxis = true; } if (Mathf.Abs(inputPos.y - item.pos.y) < minDis) { if (defaultSetting.oblique == true || obliqueChooseX == true) { v2.y = item.pos.y; } //nearPointAxis = true; } } } for (int i = 0; i < data.wallList.Count; i++) { WallData wall = data.wallList[i]; if (point != null && wall.Contines(point)) { continue; } else if (nearWall != null && wall == nearWall) { continue; } if (linefunc.GetCross(wall, phoneHelperData.currentPoint, v2) == true) { crossed = true; } } return(v2); }
/// <summary> /// targetWall 切割判断 刷新视图 /// </summary> private void CaculatCut(WallData targetWall) { for (int i = 0; i < data.wallList.Count; i++) { WallData item = data.wallList[i]; if (item == targetWall) { continue; } bool p1OnItem = false; bool p2OnItem = false; bool targetCrossItem = false; if (item.Contines(targetWall.point1) == true || item.Contines(targetWall.point2) == true) { if (item.Contines(targetWall.point1) == false && wallfunc.PointOnWall(targetWall.point1, item)) { p1OnItem = true; } if (item.Contines(targetWall.point2) == false && wallfunc.PointOnWall(targetWall.point2, item)) { p2OnItem = true; } } else { if (wallfunc.PointOnWall(targetWall.point1, item)) { p1OnItem = true; } if (wallfunc.PointOnWall(targetWall.point2, item)) { p2OnItem = true; } if (p1OnItem == false && p2OnItem == false) { if (wallfunc.PointOnWall(item.point1, targetWall) == false && wallfunc.PointOnWall(item.point2, targetWall) == false && linefunc.GetCross(item, targetWall)) { targetCrossItem = true; } } } if (p1OnItem == true && p2OnItem == true) { data.RemovePoint(targetWall.point1); data.RemovePoint(targetWall.point2); targetWall = item; } else if (p1OnItem == true) { data.CombinePointWall(targetWall.point1, item); } else if (p2OnItem == true) { data.CombinePointWall(targetWall.point2, item); } else if (targetCrossItem == true) { bool isParallel = linefunc.IsTwoLineParallel(item, targetWall); if (isParallel == false) { Vector2 crossP = linefunc.GetTwoLineCrossPoint(item, targetWall, Vector2.zero); Point point = new Point(crossP); data.AddPoint(point); data.CombinePointWall(point, item); i--; } } if (p1OnItem == true || p2OnItem == true) { i--; } } targets.Clear(); targets.Add(targetWall); for (int i = 0; i < data.pointList.Count; i++) { Point p = data.pointList[i]; for (int k = 0; k < targets.Count; k++) { WallData itemTarget = targets[k]; if (itemTarget.point1 == p || itemTarget.point2 == p) { continue; } if (wallfunc.PointOnWall(p, itemTarget)) { List <WallData> list = data.CombinePointWall(p, itemTarget); targets.RemoveAt(k); targets.InsertRange(k, list); k--; } } } roomfunc.ForceRefreshRoomData(data); RefreshView(); }
public override void mUpdate() { base.mUpdate(); if (uguiHitUI.uiHited == true) { return; } if (Input.GetMouseButtonDown(0)) { undoHelper.save(); creatRoom(Input.mousePosition); awake(); RefreshView(); } else if (Input.GetMouseButtonUp(0)) { #region 合并公共点线面 点在线上切分 线交叉切分 for (int i = 0; i < list.Count; i++) { Point p = list[i]; for (int k = 0; k < data.pointList.Count; k++) { Point pointk = data.pointList[k]; if (pointk == p) { continue; } if (Vector2.Distance(pointk.pos, p.pos) < 0.1f) { data.CombinePoint(pointk, p); i--; //target.pointList[i] = p; break; } } } ///选中房间点切分非选中房间线 for (int i = 0; i < list.Count; i++) { Point p = list[i]; for (int k = 0; k < data.wallList.Count; k++) { WallData item = data.wallList[k]; if (item.Contines(p)) { continue; } if (wallfunc.PointOnWall(p, item)) { data.CombinePointWall(p, item); break; } } } ///选中房间线 切分非选中房间线(切分后交叉点已生成 即:后面点切分选中房间线 包含了 线切分选中房间线的部分) for (int i = 0; i < list.Count; i++) { Point p = list[i]; Point p2 = list[(i + 1) % list.Count]; WallData wall = data.GetWall(p, p2); if (wall == null) { Debug.LogError("wall == null " + p.id + "/" + p2.id); continue; } for (int k = 0; k < data.wallList.Count; k++) { WallData item = data.wallList[k]; if (item.Contines(p) || item.Contines(p2)) { continue; } if (wallfunc.PointOnWall(item.point1, wall) == true) { continue; } if (wallfunc.PointOnWall(item.point2, wall) == true) { continue; } if (linefunc.GetCross(item, wall)) { Vector2 crossP = linefunc.GetTwoLineCrossPoint(item, wall, Vector2.zero); Point point = new Point(crossP); data.AddPoint(point); data.CombinePointWall(point, item); k--; } } } ///非选中房间点切分选中房间线 itemList.Clear(); for (int i = 0; i < list.Count; i++) { WallData item = data.GetWall(list[i], list[(i + 1) % list.Count]); itemList.Add(item); } for (int i = 0; i < data.pointList.Count; i++) { Point p = data.pointList[i]; for (int k = 0; k < itemList.Count; k++) { WallData itemk = itemList[k]; if (itemk.Contines(p)) { continue; } if (wallfunc.PointOnWall(p, itemk)) { List <WallData> list = data.CombinePointWall(p, itemk); itemList.RemoveAt(k); itemList.InsertRange(k, list); break; } } } #endregion roomfunc.ForceRefreshRoomData(data); RefreshView(); setState(FreeState2D.NAME); mianpageMachine.setState(MainPageFreeState.Name); } else if (Input.GetMouseButton(0)) { Vector2 pos = GetScreenToWorldPos(Input.mousePosition); float minDis = 0.06f; ///房间的第index个点有吸附 或者index和(index+1)%count的那堵墙有吸附 int minDisPointIndex = -1; ///边界点靠近点 Point mindisPoint = null; ///边界点靠近墙 WallData mindisWall = null; ///墙靠近边界点 Point mindisWallToPoint = null; #region pos != oldPos if (pos != oldPos) { offset = pos - startPos; #region 纠正offset for (int i = 0; i < list.Count; i++) { list[i].pos = startPosList[i] + offset; } for (int i = 0; i < list.Count; i++) { Point point = list[i]; point.pos = startPosList[i] + offset; for (int k = 0; k < data.pointList.Count; k++) { Point pointk = data.pointList[k]; if (list.Contains(pointk)) { continue; } float sqrDis = (point.pos - pointk.pos).sqrMagnitude; if (sqrDis < minDis) { minDisPointIndex = i; mindisPoint = pointk; minDis = sqrDis; offset = pointk.pos - startPosList[i]; } } } if (minDisPointIndex == -1) { minDis = 0.2f; for (int i = 0; i < list.Count; i++) { Point point = list[i]; for (int k = 0; k < data.wallList.Count; k++) { WallData wallk = data.wallList[k]; if (list.Contains(wallk.point1) && list.Contains(wallk.point2)) { continue; } float dis = linefunc.GetDis(wallk.a, wallk.b, wallk.c, point.pos.x, point.pos.y); if (dis <= minDis) { Vector2 disP = linefunc.GetDisPoint(wallk.a, wallk.b, wallk.c, point.pos.x, point.pos.y); if (wallfunc.PointOnWall(disP, wallk)) { minDisPointIndex = i; mindisWall = wallk; minDis = dis; offset = disP - startPosList[i]; } } } } } #region 墙吸附于点 if (minDisPointIndex == -1) { minDis = 0.2f; for (int i = 0; i < list.Count; i++) { WallData wall = data.GetWall(list[i], list[(i + 1) % list.Count]); for (int k = 0; k < data.pointList.Count; k++) { Point pointk = data.pointList[k]; if (list.Contains(pointk)) { continue; } float dis = linefunc.GetDis(wall.a, wall.b, wall.c, pointk.pos.x, pointk.pos.y); if (dis <= minDis) { Vector2 disP = linefunc.GetDisPoint(wall.a, wall.b, wall.c, pointk.pos.x, pointk.pos.y); if (wallfunc.PointOnWall(disP, wall)) { minDisPointIndex = i; mindisWallToPoint = list[i]; minDis = dis; offset = list[i].pos - startPosList[i] + pointk.pos - disP; } } } } } #endregion #endregion for (int i = 0; i < list.Count; i++) { list[i].pos = startPosList[i] + offset; } oldPos = pos; RefreshView(); } #endregion } }
public override void mUpdate() { base.mUpdate(); if (changed) { return; } if (uguiHitUI.uiHited == true) { return; } if (canMove == false) { if (Input.GetMouseButtonUp(0) == false) { return; } } if (Input.GetMouseButtonDown(0)) { awake(); saved = false; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 pos = GetScreenToWorldPos(Input.mousePosition); float minDis = 0.06f; ///房间的第index个点有吸附 或者index和(index+1)%count的那堵墙有吸附 int minDisPointIndex = -1; ///边界点靠近点 Point mindisPoint = null; ///边界点靠近墙 WallData mindisWall = null; ///墙靠近边界点 Point mindisWallToPoint = null; bool roomChanged = false; #region pos != oldPos if (pos != oldPos) { if (saved == false) { saved = true; } moved = true; offset = pos - startPos; #region//重置点顺序 int minCopyIndex = 0; for (int i = 0; i < target.pointList.Count; i++) { Point pointi = target.pointList[i]; List <Point> nearList = data.GetNearestPoints(pointi); if (nearList.Count > 2) { minCopyIndex = i; break; } } if (minCopyIndex != 0) { resetList.Clear(); for (int i = minCopyIndex; i < target.pointList.Count + minCopyIndex; i++) { resetList.Add(target.pointList[i % target.pointList.Count]); } target.pointList.Clear(); target.pointList.InsertRange(0, resetList); resetStartPosList.Clear(); for (int i = minCopyIndex; i < startPosList.Count + minCopyIndex; i++) { resetStartPosList.Add(startPosList[i % startPosList.Count]); } startPosList.Clear(); startPosList.InsertRange(0, resetStartPosList); } #endregion #region 纠正offset for (int i = 0; i < target.pointList.Count; i++) { Point pointi = target.pointList[i]; Point pointF = target.pointList[(i - 1 + target.pointList.Count) % target.pointList.Count]; Point pointT = target.pointList[(i + 1) % target.pointList.Count]; List <Point> nearList = data.GetNearestPoints(pointi); if (nearList.Count > 2) { roomChanged = true; WallData wallF = data.GetWall(pointi, pointF); WallData wallT = data.GetWall(pointi, pointT); if (data.GetRoom(wallF.point1To2Data) == null || data.GetRoom(wallF.point2To1Data) == null) { data.RemoveWall(wallF); } if (data.GetRoom(wallT.point1To2Data) == null || data.GetRoom(wallT.point2To1Data) == null) { data.RemoveWall(wallT); } Point newPoint = new Point(pointi.pos); data.AddPoint(newPoint); data.AddWall(pointF, newPoint, wallF.height, wallF.width); data.AddWall(newPoint, pointT, wallT.height, wallT.width); target.pointList[i] = newPoint; //去除房间移走后剩余线的共线的多余点 nearList = data.GetNearestPoints(pointi); if (nearList.Count == 2) { CheckRemove(nearList[0], pointi, nearList[1]); } //去除选中房间共线的多余点 bool isRemoved = CheckRemove(pointF, newPoint, pointT); if (isRemoved == true) { target.pointList.RemoveAt(i); startPosList.RemoveAt(i); i--; } } } for (int i = 0; i < target.pointList.Count; i++) { target.pointList[i].pos = startPosList[i] + offset; } for (int i = 0; i < target.pointList.Count; i++) { Point point = target.pointList[i]; point.pos = startPosList[i] + offset; for (int k = 0; k < data.pointList.Count; k++) { Point pointk = data.pointList[k]; if (target.pointList.Contains(pointk)) { continue; } float sqrDis = (point.pos - pointk.pos).sqrMagnitude; if (sqrDis < minDis) { minDisPointIndex = i; mindisPoint = pointk; minDis = sqrDis; offset = pointk.pos - startPosList[i]; } } } if (minDisPointIndex == -1) { minDis = 0.2f; for (int i = 0; i < target.pointList.Count; i++) { Point point = target.pointList[i]; for (int k = 0; k < data.wallList.Count; k++) { WallData wallk = data.wallList[k]; if (target.pointList.Contains(wallk.point1) && target.pointList.Contains(wallk.point2)) { continue; } float dis = linefunc.GetDis(wallk.a, wallk.b, wallk.c, point.pos.x, point.pos.y); if (dis <= minDis) { Vector2 disP = linefunc.GetDisPoint(wallk.a, wallk.b, wallk.c, point.pos.x, point.pos.y); if (wallfunc.PointOnWall(disP, wallk)) { minDisPointIndex = i; mindisWall = wallk; minDis = dis; offset = disP - startPosList[i]; } } } } } #region 墙吸附于点 if (minDisPointIndex == -1) { minDis = 0.2f; for (int i = 0; i < target.pointList.Count; i++) { WallData wall = data.GetWall(target.pointList[i], target.pointList[(i + 1) % target.pointList.Count]); for (int k = 0; k < data.pointList.Count; k++) { Point pointk = data.pointList[k]; if (target.pointList.Contains(pointk)) { continue; } float dis = linefunc.GetDis(wall.a, wall.b, wall.c, pointk.pos.x, pointk.pos.y); if (dis <= minDis) { Vector2 disP = linefunc.GetDisPoint(wall.a, wall.b, wall.c, pointk.pos.x, pointk.pos.y); if (wallfunc.PointOnWall(disP, wall)) { minDisPointIndex = i; mindisWallToPoint = target.pointList[i]; minDis = dis; offset = target.pointList[i].pos - startPosList[i] + pointk.pos - disP; } } } } } #endregion #endregion for (int i = 0; i < target.pointList.Count; i++) { target.pointList[i].pos = startPosList[i] + offset; } oldPos = pos; } else if (Input.GetMouseButtonUp(0) == false) { return; } #endregion #region Input.GetMouseButtonUp if (Input.GetMouseButtonUp(0)) { #region 合并公共点线面 点在线上切分 线交叉切分 ///合并点 for (int i = 0; i < target.pointList.Count; i++) { Point p = target.pointList[i]; for (int k = 0; k < data.pointList.Count; k++) { Point pointk = data.pointList[k]; if (pointk == p) { continue; } if (Vector2.Distance(pointk.pos, p.pos) < 0.1f) { data.CombinePoint(pointk, p); i--; //target.pointList[i] = p; break; } } } ///选中房间点切分非选中房间线 for (int i = 0; i < target.pointList.Count; i++) { Point p = target.pointList[i]; for (int k = 0; k < data.wallList.Count; k++) { WallData item = data.wallList[k]; if (item.Contines(p)) { continue; } if (wallfunc.PointOnWall(p, item)) { data.CombinePointWall(p, item); break; } } } ///选中房间线 切分非选中房间线(切分后交叉点已生成 即:后面点切分选中房间线 包含了 线切分选中房间线的部分) for (int i = 0; i < target.pointList.Count; i++) { Point p = target.pointList[i]; Point p2 = target.pointList[(i + 1) % target.pointList.Count]; WallData wall = data.GetWall(p, p2); if (wall == null) { Debug.LogWarning("wall == null " + p.id + "/" + p2.id); continue; } for (int k = 0; k < data.wallList.Count; k++) { WallData item = data.wallList[k]; if (item.Contines(p) || item.Contines(p2)) { continue; } if (wallfunc.PointOnWall(item.point1, wall) == true) { continue; } if (wallfunc.PointOnWall(item.point2, wall) == true) { continue; } if (linefunc.GetCross(item, wall)) { Vector2 crossP = linefunc.GetTwoLineCrossPoint(item, wall, Vector2.zero); Point point = new Point(crossP); data.AddPoint(point); data.CombinePointWall(point, item); k--; } } } ///非选中房间点切分选中房间线 itemList.Clear(); for (int i = 0; i < target.pointList.Count; i++) { WallData item = data.GetWall(target.pointList[i], target.pointList[(i + 1) % target.pointList.Count]); itemList.Add(item); } for (int i = 0; i < data.pointList.Count; i++) { Point p = data.pointList[i]; for (int k = 0; k < itemList.Count; k++) { WallData itemk = itemList[k]; if (itemk.Contines(p)) { continue; } if (wallfunc.PointOnWall(p, itemk)) { List <WallData> list = data.CombinePointWall(p, itemk); itemList.RemoveAt(k); itemList.InsertRange(k, list); break; } } } #endregion roomfunc.ForceRefreshRoomData(data); target = roomfunc.GetRoom(itemList); if (target != null) { awake(); } } #endregion if (roomChanged) { roomfunc.ForceRefreshRoomData(data); target = roomfunc.GetRoom(target.pointList); //if (target != null) awake(); } RefreshView(); if (target == null || data.Contins(target) == false) { Debug.LogWarning("target == null"); setState(FreeState2D.NAME); } } }