public bool GetCross(WallData line, Point currentPoint, Vector2 mousepos)
 {
     if (line.GetDis(currentPoint.pos) < 0.01f || line.GetDis(mousepos) < 0.01f)
     {
         return(false);
     }
     return(CheckTwoLineCrose(line.point1.pos, line.point2.pos, currentPoint.pos, mousepos));
 }
Beispiel #2
0
    private void GoodsInWall(WallData wall, ref Vector3 world, ref float Angle)
    {
        float angle      = wall.GetWallAngle();
        float deltaAngle = angle - Angle;
        float xifudis    = targetSize.y / 2;
        int   times90    = (int)(deltaAngle / 90);

        if (times90 % 2 != 0)
        {
            times90 += 1;
        }
        deltaAngle = times90 * 90;
        float dis = xifudis + wall.width / 2;

        if (wall.GetDis(world) < dis)
        {
            Vector2 pos = wall.GetDisPoint(world);
            if (wallFunc.PointOnWall(pos, wall) || (wall.point1.pos - pos).magnitude < xifudis ||
                (wall.point2.pos - pos).magnitude < xifudis)
            {
                world = pos;
                if (targetWall == null)
                {
                    Vector3 eulerAngles = targetObj.transform.rotation.eulerAngles;
                    Angle         = angle - deltaAngle;
                    eulerAngles.z = Angle;
                    targetObj.transform.rotation = Quaternion.Euler(eulerAngles);
                    targetSize.y = wall.width;
                    targetObj.transform.localScale = targetSize;
                    targetWall = wall;
                }
            }
        }
    }
Beispiel #3
0
    private void OpenDisInput()
    {
        minDis = float.MaxValue;
        Vector2 pos = GetV2WithoutY(target.position);

        minPos = pos;
        WallData wall     = disView.data;
        int      sidetype = lineFunc.Clockwise(pos, wall.point1.pos, wall.point2.pos);

        if (sidetype == 0)
        {
            sidetype = 1;
        }
        for (int i = 0; i < vertexs.Count; i++)
        {
            Vector2 vertexspos = vertexs[i];
            float   dis        = wall.GetDis(vertexspos);
            int     sidetypei  = lineFunc.Clockwise(vertexspos, wall.point1.pos, wall.point2.pos);

            if (sidetypei == 0)
            {
                dis = 0;
            }
            else if (sidetypei != sidetype)
            {
                dis = -dis;
            }
            dis -= wall.width / 2;
            if (dis < minDis)
            {
                minDis = dis;
                minPos = vertexspos;
            }
            else if (dis == minDis)
            {
                if (vertexspos.x < minPos.x || vertexspos.y < minPos.y)
                {
                    minPos = vertexspos;
                }
            }
        }

        UITool.SetActionTrue(obj);
        Cancel();
        optionsPage.inputUnit.onClick.AddListener(onOpenInput);
        optionsPage.ok.onClick.AddListener(Ok);
        optionsPage.cancel.onClick.AddListener(Cancel);
    }
    /// <summary>
    /// 内嵌
    /// </summary>
    private void Inlay(ref Vector3 world, ref float Angle)
    {
        targetWall = null;
        Vector2 world2d = Vector2.zero;

        world2d.x = world.x;
        world2d.y = world.z;
        for (int i = 0; i < data.wallList.Count; i++)
        {
            WallData wall       = data.wallList[i];
            float    angle      = wall.GetWallAngle();
            float    deltaAngle = angle - (Angle - forTop);
            float    xifudis    = targetSize.z / 2;
            int      times90    = (int)(deltaAngle / 90);
            if (times90 % 2 != 0)
            {
                times90 += 1;
            }
            deltaAngle = times90 * 90;
            //int times180 = times90 / 2;
            float dis = xifudis + wall.width / 2;
            if (wall.GetDis(world2d) < dis)
            {
                Vector2 pos = wall.GetDisPoint(world2d);
                if (wallFunc.PointOnWall(pos, wall) || (wall.point1.pos - pos).magnitude < xifudis ||
                    (wall.point2.pos - pos).magnitude < xifudis)
                {
                    world.x = pos.x;
                    world.z = pos.y;
                    if (targetWall == null)
                    {
                        Vector3 eulerAngles = targetObj.transform.rotation.eulerAngles;
                        Angle         = angle - deltaAngle;
                        eulerAngles.y = -(Angle - forTop);
                        targetObj.transform.rotation = Quaternion.Euler(eulerAngles);
                        targetWall = wall;
                    }
                }
            }
        }
        if (targetWall != null)
        {
        }
    }
Beispiel #5
0
    private float GoodsWallDis(WallData wall, Vector2 world, float Angle)
    {
        float angle      = wall.GetWallAngle();
        float deltaAngle = angle - Angle;
        float xifudis    = targetSize.y / 2;
        int   times45    = (int)(deltaAngle / 45);

        if (times45 % 2 != 0)
        {
            times45 += 1;
        }
        deltaAngle = times45 * 45;
        int times90 = times45 / 2;

        if (times90 % 2 != 0)
        {
            xifudis = targetSize.x / 2;
        }
        float dis     = xifudis + wall.width / 2;
        float walldis = wall.GetDis(world);

        if (walldis < dis)
        {
            Vector2 pos = wall.GetDisPoint(world);
            if (wallFunc.PointOnWall(pos, wall)
                //|| (wall.point1.pos - pos).magnitude < xifudis
                //|| (wall.point2.pos - pos).magnitude < xifudis
                )
            {
                return(Mathf.Abs(walldis - dis));
                //world = wall.GetDisPoint(world, dis);
                //if (targetWall == null)
                //{
                //    Vector3 eulerAngles = targetObj.transform.rotation.eulerAngles;
                //    Angle = angle - deltaAngle;
                //    eulerAngles.z = Angle;
                //    targetObj.transform.rotation = Quaternion.Euler(eulerAngles);
                //    targetWall = wall;
                //}
            }
        }
        return(float.MaxValue);
    }
Beispiel #6
0
    private void GoodsInWall(WallData wall, ref Vector3 world, ref float Angle)
    {
        float angle      = wall.GetWallAngle();
        float deltaAngle = angle - Angle;
        float xifudis    = targetSize.y / 2;
        int   times90    = (int)(deltaAngle / 90);

        if (times90 % 2 != 0)
        {
            times90 += 1;
        }
        deltaAngle = times90 * 90;
        //int times180 = times90 / 2;
        float dis = xifudis + wall.width / 2;

        if (wall.GetDis(world) < dis)
        {
            Vector2 pos = wall.GetDisPoint(world);
            if (wallFunc.PointOnWall(pos, wall) || (wall.point1.pos - pos).magnitude < xifudis ||
                (wall.point2.pos - pos).magnitude < xifudis)
            {
                world = pos;//wall.GetDisPoint(world, dis);
                if (targetWall == null)
                {
                    //int intvalue = deltaAngle >= 0 ? 1 : -1;
                    //times45 += bool2 == true ? 0 : intvalue;
                    Vector3 eulerAngles = targetObj.transform.rotation.eulerAngles;
                    Angle         = angle - deltaAngle;//times45 * 45f;
                    eulerAngles.z = Angle;
                    //Debug.LogWarning(eulerAngles);
                    targetObj.transform.rotation = Quaternion.Euler(eulerAngles);
                    targetSize.y = wall.width;
                    targetObj.transform.localScale = targetSize;
                    targetWall = wall;
                }
            }
        }
    }
Beispiel #7
0
    private void GoodsOnWall(WallData wall, ref Vector3 world, ref float Angle)
    {
        float angle      = wall.GetWallAngle();
        float deltaAngle = angle - Angle;
        float xifudis    = targetSize.y / 2;
        int   times45    = (int)(deltaAngle / 45);

        if (times45 % 2 != 0)
        {
            times45 += 1;
        }
        deltaAngle = times45 * 45;
        int times90 = times45 / 2;

        if (times90 % 2 != 0)
        {
            xifudis = targetSize.x / 2;
        }
        float dis = xifudis + wall.width / 2;

        if (wall.GetDis(world) < dis)
        {
            Vector2 pos = wall.GetDisPoint(world);
            if (wallFunc.PointOnWall(pos, wall) || (wall.point1.pos - pos).magnitude < xifudis ||
                (wall.point2.pos - pos).magnitude < xifudis)
            {
                world = wall.GetDisPoint(world, dis);
                //if (targetWall == null)
                //{
                Vector3 eulerAngles = targetObj.transform.rotation.eulerAngles;
                Angle         = angle - deltaAngle;
                eulerAngles.z = Angle;
                targetObj.transform.rotation = Quaternion.Euler(eulerAngles);
                //    targetWall = wall;
                //}
            }
        }
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="point"></param>
    /// <param name="mousePos">鼠标位置</param>
    /// <returns></returns>
    private Vector2 AdjustPoint(ref Point point, ref OnWallType type, Vector2 mousePos)
    {
        Vector2 v2     = mousePos;
        float   minDis = 0.06f;

        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.OnWallPoint;
            }
        }

        if (point == null)
        {
            minDis = 0.25f;
            for (int i = 0; i < data.wallList.Count; i++)
            {
                WallData wall = data.wallList[i];
                float    dis  = wall.GetDis(mousePos);
                if (dis < minDis)
                {
                    v2     = wall.GetDisPoint(mousePos);
                    minDis = dis;

                    if (wallfunc.PointOnWall(v2, wall))
                    {
                        type = OnWallType.OnWallSide;
                    }
                }
            }
        }
        return(v2);
    }
Beispiel #9
0
    private void ResetWallByPoint(Point point)
    {
        WallData wall = null;
        Vector2  pos  = Vector2.zero;

        for (int i = 0; i < data.wallList.Count; i++)
        {
            WallData item = data.wallList[i];
            if (item.point1 == point || item.point2 == point)
            {
                return;
            }
            if (item.GetDis(point.pos) < 0.01f)
            {
                Vector2 itemPos = item.GetDisPoint(point.pos);
                if (wallfunc.PointOnWall(itemPos, item))
                {
                    wall = item;
                    pos  = itemPos;
                    break;
                }
            }
        }

        //墙体被分割
        if (wall != null)
        {
            data.CombinePointWall(point, wall);
            //data.RemoveWall(wall);
            ////wall.point1.nearList.Remove(wall.point2);
            ////wall.point2.nearList.Remove(wall.point1);

            //data.AddWall(wall.point1, point, wall.height, wall.width);

            //data.AddWall(point, wall.point2, wall.height, wall.width);
        }
    }
Beispiel #10
0
    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
            //{
            //}
        }
    }
Beispiel #11
0
    /// <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);
    }
Beispiel #12
0
    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);
    }
Beispiel #13
0
    public override void mUpdate()
    {
        base.mUpdate();

        if (Input.GetMouseButtonDown(1))
        {
            if (helperData.helpLineList.Count <= 0)
            {
                setState(FreeState2D.NAME);
                setState(SetFirstPointState.NAME);
                //machine.dispatchEvent(new InputStateEvent(InputStateEvent.DrawWallEnd, true));
            }
            else
            {
                helperData.endOnWallType = OnWallType.NotOnWall;
                //machine.dispatchEvent(new InputStateEvent(InputStateEvent.DrawWallEnd, false));
                ChoseWallDirect();
                setState(SetFirstPointState.NAME);
            }
            return;
        }

        Vector2 v2 = GetScreenToWorldPos(Input.mousePosition);

        if (lastInputPos == v2 && Input.GetMouseButtonDown(0) == false &&
            Input.GetKeyDown(KeyCode.Return) == false && helpView2D.getInputChange() == false)
        {
            return;
        }

        lastInputPos = v2;
        //if (Input.GetMouseButtonDown(0))
        //{
        //    Debug.Log("000");
        //}

        Point      point   = null;
        OnWallType type    = OnWallType.NotOnWall;
        bool       crossed = false;

        v2 = AdjustPoint(ref point, ref crossed, ref type, v2);

        if (crossed == false && Input.GetMouseButtonDown(0))
        {
            if (uguiHitUI.uiHited == false)
            {
                if (point == null)
                {
                    point     = new Point();
                    point.pos = v2;
                    data.AddPoint(point);

                    ///点在helpLine上时候切割helpLine
                    WallData wall = null;
                    Vector2  pos  = Vector2.zero;
                    for (int i = 0; i < helperData.helpLineList.Count; i++)
                    {
                        WallData itemWall = helperData.helpLineList[i];
                        if (itemWall.GetDis(v2) < 0.01f)
                        {
                            Vector2 itemPos = itemWall.GetDisPoint(v2);
                            if (wallfunc.PointOnWall(itemPos, itemWall))
                            {
                                wall = itemWall;
                                pos  = itemPos;
                                break;
                            }
                        }
                    }

                    if (wall != null)
                    {
                        helperData.helpLineList.Remove(wall);
                        WallData data1 = new WallData();
                        data1.point1 = wall.point1;
                        data1.point2 = point;
                        data1.height = wall.height;
                        data1.width  = wall.width;
                        helperData.helpLineList.Add(data1);

                        WallData data2 = new WallData();
                        data2.point1 = point;
                        data2.point2 = wall.point2;
                        data2.height = wall.height;
                        data2.width  = wall.width;
                        helperData.helpLineList.Add(data2);
                    }
                }
                else
                {
                    if (point == helperData.currentPoint)
                    {
                        Debug.Log("point == helperData.currentPoint");
                        return;
                    }
                    for (int i = 0; i < helperData.helpLineList.Count; i++)
                    {
                        WallData wall = helperData.helpLineList[i];
                        if (wall.equle(point, helperData.currentPoint))
                        {
                            Debug.Log("the line has already contions");
                            return;
                        }
                    }
                }

                WallData line = new WallData();
                line.point1 = helperData.currentPoint;
                line.point2 = point;
                line.height = defaultSetting.DefaultHeight;
                line.width  = defaultSetting.DefaultWidth;
                helperData.helpLineList.Add(line);
                helperData.currentPoint = point;

                if (type != OnWallType.NotOnWall)
                {
                    helperData.endOnWallType = type;
                    //machine.dispatchEvent(new InputStateEvent(InputStateEvent.DrawWallEnd, false));
                    ChoseWallDirect(false);
                    if (GetRoom(line) == true)
                    {
                        mianpageMachine.setState(MainPageFreeState.Name);
                        //setState(FreeState2D.NAME);
                    }
                    return;
                }
            }
        }

        cursor.position = v2;
        helpView2D.RefreshView(v2);

        if (crossed == true)
        {
            if (helperData.mouseLineDisable == false)
            {
                helpView2D.SetMouseLineDisable();
                helperData.mouseLineDisable = true;
            }
        }
        else
        {
            if (helperData.mouseLineDisable == true)
            {
                helpView2D.SetMouseLineable();
                helperData.mouseLineDisable = false;
            }
        }
    }