Exemple #1
0
        public void RoadSplitterNoSplitAtStartTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
                new GpsCoordinate()
                {
                    x = 3
                },

                new GpsCoordinate()
                {
                    x = 0, y = 0.1
                },
                new GpsCoordinate()
                {
                    x = 1, y = 0.5
                },
                new GpsCoordinate()
                {
                    x = 2, y = 1
                },
                new GpsCoordinate()
                {
                    x = 3, y = 2
                },
            }, 2);

            var splitter = new RoadSplitter(1, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(4, pathList[0].Points.Count);
            Assert.AreEqual(0, pathList[0].Points[0].x);
            Assert.AreEqual(1, pathList[0].Points[1].x);
            Assert.AreEqual(2, pathList[0].Points[2].x);
            Assert.AreEqual(3, pathList[0].Points[3].x);

            Assert.AreEqual(4, pathList[1].Points.Count);
            Assert.AreEqual(0.1, pathList[1].Points[0].y);
            Assert.AreEqual(0.5, pathList[1].Points[1].y);
            Assert.AreEqual(1, pathList[1].Points[2].y);
            Assert.AreEqual(2, pathList[1].Points[3].y);
        }
Exemple #2
0
    private void OnEnable()
    {
        roadSplitter = (RoadSplitter)target;

        if (roadSplitter.globalSettings == null)
        {
            roadSplitter.globalSettings = GameObject.FindObjectOfType <GlobalSettings>();
        }

        if (roadSplitter.transform.childCount == 0)
        {
            GameObject connections = new GameObject("Connections");
            connections.transform.SetParent(roadSplitter.transform);
            connections.transform.localPosition = Vector3.zero;
            connections.transform.localRotation = Quaternion.Euler(Vector3.zero);

            AddConnection("Left");
            AddConnection("Upper Right");
            AddConnection("Lower Right");

            GameObject mesh = new GameObject("Mesh");
            mesh.transform.SetParent(roadSplitter.transform);
            mesh.transform.localPosition = Vector3.zero;
            mesh.transform.localRotation = Quaternion.Euler(Vector3.zero);
            mesh.AddComponent <MeshFilter>();
            mesh.AddComponent <MeshRenderer>();
            mesh.AddComponent <MeshCollider>();
        }

        lastTool      = Tools.current;
        Tools.current = Tool.None;

        roadSplitter.GenerateMesh();
    }
Exemple #3
0
        public void RoadSplitterOnePathTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
            }, 2);

            var splitter = new RoadSplitter(2, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(1, pathList.Count);
            Assert.AreEqual(3, pathList[0].Points.Count);
            Assert.AreEqual(0, pathList[0].Points[0].x);
            Assert.AreEqual(1, pathList[0].Points[1].x);
            Assert.AreEqual(2, pathList[0].Points[2].x);
        }
Exemple #4
0
        public void RoadSplitterCrossNoConnectionTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = -1
                },
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },

                new GpsCoordinate()
                {
                    y = -1
                },
                new GpsCoordinate()
                {
                    y = 0
                },
                new GpsCoordinate()
                {
                    y = 1
                },
            }, 1);

            var splitter = new RoadSplitter(0.5f, new PathConnections());

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(3, pathList[0].Points.Count);
            Assert.AreEqual(-1, pathList[0].Points[0].x);
            Assert.AreEqual(0, pathList[0].Points[1].x);
            Assert.AreEqual(1, pathList[0].Points[2].x);

            Assert.AreEqual(3, pathList[1].Points.Count);
            Assert.AreEqual(-1, pathList[1].Points[0].y);
            Assert.AreEqual(0, pathList[1].Points[1].y);
            Assert.AreEqual(1, pathList[1].Points[2].y);
        }
Exemple #5
0
        public void RoadSplitterTooFarTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = -1
                },
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },

                new GpsCoordinate()
                {
                    y = -1
                },
                new GpsCoordinate()
                {
                    y = 0.2
                },
                new GpsCoordinate()
                {
                    y = 1
                },
            }, 1.2f);

            var splitter = new RoadSplitter(0.1f, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(3, pathList[0].Points.Count);
            Assert.AreEqual(-1, pathList[0].Points[0].x);
            Assert.AreEqual(0, pathList[0].Points[1].x);
            Assert.AreEqual(1, pathList[0].Points[2].x);

            Assert.AreEqual(3, pathList[1].Points.Count);
            Assert.AreEqual(-1, pathList[1].Points[0].y);
            Assert.AreEqual(0.2, pathList[1].Points[1].y);
            Assert.AreEqual(1, pathList[1].Points[2].y);
        }
Exemple #6
0
        public void RoadSplitterComplexConnectionTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },                                // 0
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
                new GpsCoordinate()
                {
                    x = 3
                },
                new GpsCoordinate()
                {
                    x = 4
                },
                new GpsCoordinate()
                {
                    x = 5
                },
                new GpsCoordinate()
                {
                    x = 6
                },

                new GpsCoordinate()
                {
                    x = 1, y = 2
                },                                       // 1
                new GpsCoordinate()
                {
                    x = 1, y = 1
                },
                new GpsCoordinate()
                {
                    x = 1, y = 0.1
                },

                new GpsCoordinate()
                {
                    x = 3, y = -0.1
                },                                          // 2
                new GpsCoordinate()
                {
                    x = 3, y = -1
                },
                new GpsCoordinate()
                {
                    x = 3, y = -2
                },

                new GpsCoordinate()
                {
                    x = 5, y = 2
                },                                       // 3
                new GpsCoordinate()
                {
                    x = 5, y = 1
                },
                new GpsCoordinate()
                {
                    x = 5, y = 0.1
                },

                new GpsCoordinate()
                {
                    x = 6.1
                },                                  //4
                new GpsCoordinate()
                {
                    x = 7
                },

                new GpsCoordinate()
                {
                    x = -2
                },                                 // 5
                new GpsCoordinate()
                {
                    x = -1
                },
                new GpsCoordinate()
                {
                    x = -0.1
                },
            }, 1);

            var pathConnections = new PathConnections();

            pathConnections.Add(0, 4);
            pathConnections.Add(1, 0);
            pathConnections.Add(0, 2);
            pathConnections.Add(3, 0);
            pathConnections.Add(5, 0);

            var splitter = new RoadSplitter(0.5f, pathConnections);

            splitter.Process(paths);

            var connectionsTracker = new PathConnectionsChecksTracker(pathConnections);

            Assert.IsTrue(connectionsTracker.HasConnection(5, 0));
            Assert.IsTrue(connectionsTracker.HasConnection(0, 6));
            Assert.IsTrue(connectionsTracker.HasConnection(1, 6));
            Assert.IsTrue(connectionsTracker.HasConnection(6, 7));
            Assert.IsTrue(connectionsTracker.HasConnection(6, 2));
            Assert.IsTrue(connectionsTracker.HasConnection(3, 8));
            Assert.IsTrue(connectionsTracker.HasConnection(7, 8));
            Assert.IsTrue(connectionsTracker.HasConnection(8, 4));
            Assert.IsTrue(connectionsTracker.AllConnectionsChecked());
        }
Exemple #7
0
        public void RoadSplitterZigZagTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
                new GpsCoordinate()
                {
                    x = 3
                },
                new GpsCoordinate()
                {
                    x = 4
                },
            }, 1);

            paths.AddRange(PointUtils.CreateFromPoints(
                               new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0, y = 0.5
                },
                new GpsCoordinate()
                {
                    x = 1, y = 2
                },
                new GpsCoordinate()
                {
                    x = 2, y = -0.5
                },
                new GpsCoordinate()
                {
                    x = 3, y = -2
                },
                new GpsCoordinate()
                {
                    x = 4, y = 0.5
                },
            }, 3));

            var splitter = new RoadSplitter(1, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(5, pathList[0].Points.Count);
            Assert.AreEqual(0, pathList[0].Points[0].x);
            Assert.AreEqual(1, pathList[0].Points[1].x);
            Assert.AreEqual(2, pathList[0].Points[2].x);
            Assert.AreEqual(3, pathList[0].Points[3].x);
            Assert.AreEqual(4, pathList[0].Points[4].x);

            Assert.AreEqual(5, pathList[1].Points.Count);
            Assert.AreEqual(0.5, pathList[1].Points[0].y);
            Assert.AreEqual(2, pathList[1].Points[1].y);
            Assert.AreEqual(-0.5, pathList[1].Points[2].y);
            Assert.AreEqual(-2, pathList[1].Points[3].y);
            Assert.AreEqual(0.5, pathList[1].Points[4].y);
        }
Exemple #8
0
    private Vector3 GetIntersectionPoint(Vector3 position, GameObject intersection, string connectionPointName)
    {
        SquareIntersection   squareIntersection   = intersection.transform.parent.GetComponent <SquareIntersection>();
        TriangleIntersection triangleIntersection = intersection.transform.parent.GetComponent <TriangleIntersection>();
        DiamondIntersection  diamondIntersection  = intersection.transform.parent.GetComponent <DiamondIntersection>();
        Roundabout           roundabout           = intersection.transform.parent.GetComponent <Roundabout>();
        RoadSplitter         roadSplitter         = intersection.GetComponent <RoadSplitter>();

        if (squareIntersection != null)
        {
            return(intersection.transform.position + new Vector3(0, squareIntersection.heightOffset - position.y, 0));
        }
        else if (roundabout != null)
        {
            return(roundabout.transform.position + new Vector3(0, roundabout.heightOffset - position.y, 0));
        }
        else if (triangleIntersection != null)
        {
            if (connectionPointName == "Down Connection Point")
            {
                return(intersection.transform.position + intersection.transform.rotation * new Vector3(0, triangleIntersection.heightOffset - position.y, -triangleIntersection.height));
            }
            else if (connectionPointName == "Left Connection Point")
            {
                return(intersection.transform.position + intersection.transform.rotation * Misc.GetCenter(new Vector3(-triangleIntersection.width, triangleIntersection.heightOffset - position.y, -triangleIntersection.height), new Vector3(0, triangleIntersection.heightOffset - position.y, triangleIntersection.height)));
            }
            else if (connectionPointName == "Right Connection Point")
            {
                return(intersection.transform.position + intersection.transform.rotation * Misc.GetCenter(new Vector3(triangleIntersection.width, triangleIntersection.heightOffset - position.y, -triangleIntersection.height), new Vector3(0, triangleIntersection.heightOffset - position.y, triangleIntersection.height)));
            }
        }
        else if (diamondIntersection != null)
        {
            if (connectionPointName == "Upper Left Connection Point")
            {
                return(intersection.transform.position + intersection.transform.rotation * Misc.GetCenter(new Vector3(0, diamondIntersection.heightOffset - position.y, diamondIntersection.height), new Vector3(-diamondIntersection.width, diamondIntersection.heightOffset - position.y, 0)));
            }
            else if (connectionPointName == "Upper Right Connection Point")
            {
                return(intersection.transform.position + intersection.transform.rotation * Misc.GetCenter(new Vector3(0, diamondIntersection.heightOffset - position.y, diamondIntersection.height), new Vector3(diamondIntersection.width, diamondIntersection.heightOffset - position.y, 0)));
            }
            else if (connectionPointName == "Lower Left Connection Point")
            {
                return(intersection.transform.position + intersection.transform.rotation * Misc.GetCenter(new Vector3(0, diamondIntersection.heightOffset - position.y, -diamondIntersection.height), new Vector3(-diamondIntersection.width, diamondIntersection.heightOffset - position.y, 0)));
            }
            else if (connectionPointName == "Lower Right Connection Point")
            {
                return(intersection.transform.position + intersection.transform.rotation * Misc.GetCenter(new Vector3(0, diamondIntersection.heightOffset - position.y, -diamondIntersection.height), new Vector3(diamondIntersection.width, diamondIntersection.heightOffset - position.y, 0)));
            }
        }
        else if (roadSplitter != null)
        {
            if (connectionPointName == "Left Connection Point")
            {
                return(intersection.transform.position + roadSplitter.transform.forward);
            }
            else if (connectionPointName == "Upper Right Connection Point")
            {
                Vector3 up   = (roadSplitter.transform.GetChild(0).GetChild(1).position - roadSplitter.transform.GetChild(0).GetChild(2).position).normalized;
                Vector3 left = new Vector3(-up.z, 0, up.x);
                return(roadSplitter.transform.GetChild(0).GetChild(1).position + left - new Vector3(0, roadSplitter.heightOffset - position.y, 0));
            }
            else if (connectionPointName == "Lower Right Connection Point")
            {
                Vector3 up   = (roadSplitter.transform.GetChild(0).GetChild(1).position - roadSplitter.transform.GetChild(0).GetChild(2).position).normalized;
                Vector3 left = new Vector3(-up.z, 0, up.x);
                return(roadSplitter.transform.GetChild(0).GetChild(2).position + left - new Vector3(0, roadSplitter.heightOffset - position.y, 0));
            }
        }

        return(Misc.MaxVector3);
    }
Exemple #9
0
    private void DetectIntersectionConnection(GameObject gameObject)
    {
        RaycastHit raycastHit2;

        if (Physics.Raycast(new Ray(gameObject.transform.position + Vector3.up, Vector3.down), out raycastHit2, 100f, ~(1 << globalSettings.ignoreMouseRayLayer)))
        {
            if (raycastHit2.collider.name.Contains("Connection Point"))
            {
                // Change width/height
                SquareIntersection   squareIntersection   = raycastHit2.collider.transform.parent.parent.parent.GetComponent <SquareIntersection>();
                TriangleIntersection triangleIntersection = raycastHit2.collider.transform.parent.parent.parent.GetComponent <TriangleIntersection>();
                DiamondIntersection  diamondIntersection  = raycastHit2.collider.transform.parent.parent.parent.GetComponent <DiamondIntersection>();
                Roundabout           roundabout           = raycastHit2.collider.transform.parent.parent.parent.GetComponent <Roundabout>();
                RoadSplitter         roadSplitter         = raycastHit2.collider.transform.parent.parent.GetComponent <RoadSplitter>();
                string connectionName = raycastHit2.collider.name;

                if ((roadSplitter != null && raycastHit2.collider.transform.parent.parent.GetChild(1).GetComponent <MeshFilter>().sharedMesh != null) || raycastHit2.collider.transform.parent.GetChild(0).GetComponent <MeshFilter>().sharedMesh != null)
                {
                    gameObject.GetComponent <Point>().intersectionConnection = raycastHit2.collider.gameObject;
                    gameObject.transform.position = raycastHit2.collider.transform.position;

                    float roadWidth = gameObject.transform.parent.parent.GetComponent <RoadSegment>().startRoadWidth;
                    if (gameObject.name == "End Point")
                    {
                        roadWidth = gameObject.transform.parent.parent.GetComponent <RoadSegment>().endRoadWidth;
                    }

                    if (squareIntersection != null)
                    {
                        if (connectionName == "Up Connection Point")
                        {
                            squareIntersection.upConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Down Connection Point")
                        {
                            squareIntersection.downConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Left Connection Point")
                        {
                            squareIntersection.leftConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Right Connection Point")
                        {
                            squareIntersection.rightConnectionWidth = roadWidth;
                        }

                        squareIntersection.GenerateMeshes();
                    }
                    else if (triangleIntersection != null)
                    {
                        if (connectionName == "Down Connection Point")
                        {
                            triangleIntersection.downConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Left Connection Point")
                        {
                            triangleIntersection.leftConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Right Connection Point")
                        {
                            triangleIntersection.rightConnectionWidth = roadWidth;
                        }

                        triangleIntersection.GenerateMeshes();
                    }
                    else if (diamondIntersection != null)
                    {
                        if (connectionName == "Upper Left Connection Point")
                        {
                            diamondIntersection.upperLeftConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Upper Right Connection Point")
                        {
                            diamondIntersection.upperRightConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Lower Left Connection Point")
                        {
                            diamondIntersection.lowerLeftConnectionWidth = roadWidth;
                        }
                        else if (connectionName == "Lower Right Connection Point")
                        {
                            diamondIntersection.lowerRightConnectionWidth = roadWidth;
                        }

                        diamondIntersection.GenerateMeshes();
                    }
                    else if (roundabout != null)
                    {
                        roundabout.connectionWidth[raycastHit2.transform.GetSiblingIndex() - 1] = roadWidth;

                        roundabout.GenerateMeshes();
                    }
                    else if (roadSplitter != null)
                    {
                        if (connectionName == "Left Connection Point")
                        {
                            roadSplitter.leftWidth = roadWidth;
                        }
                        else if (connectionName == "Lower Right Connection Point")
                        {
                            roadSplitter.lowerRightXOffset = -roadSplitter.rightWidth + roadWidth;
                        }
                        else if (connectionName == "Upper Right Connection Point")
                        {
                            roadSplitter.upperRightXOffset = roadSplitter.rightWidth - roadWidth;
                        }
                        roadSplitter.GenerateMesh();
                    }
                }
            }
            else
            {
                gameObject.GetComponent <Point>().intersectionConnection = null;
            }
        }
    }