示例#1
0
    private void OnEnable()
    {
        intersection = (SquareIntersection)target;

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

        if (intersection.transform.childCount == 0)
        {
            GameObject sides = new GameObject("Sides");
            sides.transform.SetParent(intersection.transform);
            sides.transform.localPosition = Vector3.zero;
            sides.transform.localRotation = Quaternion.Euler(Vector3.zero);

            AddSide("Up").transform.localRotation    = Quaternion.Euler(new Vector3(0, 0, 0));
            AddSide("Down").transform.localRotation  = Quaternion.Euler(new Vector3(0, 180, 0));
            AddSide("Left").transform.localRotation  = Quaternion.Euler(new Vector3(0, 270, 0));
            AddSide("Right").transform.localRotation = Quaternion.Euler(new Vector3(0, 90, 0));

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

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

        intersection.GenerateMeshes();
    }
示例#2
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);
    }
示例#3
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;
            }
        }
    }