Exemplo n.º 1
0
    private void OnEnable()
    {
        roundabout = (Roundabout)target;

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

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

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

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

        roundabout.GenerateMeshes();
    }
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        settings.pointSize = Mathf.Max(0.2f, EditorGUILayout.FloatField("Point Size", settings.pointSize));
        if (EditorGUI.EndChangeCheck() == true)
        {
            Transform[] objects = GameObject.FindObjectsOfType <Transform>();

            for (int i = 0; i < objects.Length; i++)
            {
                if (objects[i].name.Contains("Connection Point") || objects[i].name == "Start Point" || objects[i].name == "Control Point" || objects[i].name == "End Point")
                {
                    objects[i].GetComponent <BoxCollider>().size = new Vector3(settings.pointSize, settings.pointSize, settings.pointSize);
                }
            }
        }

        EditorGUI.BeginChangeCheck();
        settings.resolution = Mathf.Clamp(EditorGUILayout.FloatField("Resolution", settings.resolution), 0.01f, 2f);
        if (EditorGUI.EndChangeCheck() == true)
        {
            Transform[] objects = GameObject.FindObjectsOfType <Transform>();

            for (int i = 0; i < objects.Length; i++)
            {
                RoadCreator road = objects[i].GetComponent <RoadCreator>();
                if (road != null)
                {
                    road.CreateMesh();
                }
                else
                {
                    Roundabout roundabout = objects[i].GetComponent <Roundabout>();

                    if (roundabout != null)
                    {
                        roundabout.GenerateMeshes();
                    }
                }
            }
        }

        settings.ignoreMouseRayLayer     = Mathf.Clamp(EditorGUILayout.IntField("Ignore Mouse Ray Layer", settings.ignoreMouseRayLayer), 9, 31);
        settings.roadLayer               = Mathf.Clamp(EditorGUILayout.IntField("Road Layer", settings.roadLayer), 9, 31);
        settings.intersectionPointsLayer = Mathf.Clamp(EditorGUILayout.IntField("Intersection Points Layer", settings.intersectionPointsLayer), 9, 31);

        EditorGUI.BeginChangeCheck();
        settings.amountRoadGuidelines = Mathf.Clamp(EditorGUILayout.IntField("Amount Of Road Guidelines (each side)", settings.amountRoadGuidelines), 0, 15);
        if (EditorGUI.EndChangeCheck() == true)
        {
            settings.UpdateRoadGuidelines();
        }

        settings.debug = EditorGUILayout.Toggle("Debug", settings.debug);
    }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        roundabout.centerMaterial = (Material)EditorGUILayout.ObjectField("Center Material", roundabout.centerMaterial, typeof(Material), false);
        roundabout.diameter       = Mathf.Max(1.2f, EditorGUILayout.FloatField("Diameter", roundabout.diameter));
        roundabout.width          = Mathf.Min(roundabout.diameter / 2, Mathf.Max(0.1f, EditorGUILayout.FloatField("Width", roundabout.width)));
        roundabout.heightOffset   = Mathf.Max(0, EditorGUILayout.FloatField("Y Offset", roundabout.heightOffset));

        GUILayout.Label("");

        roundabout.centerPiece = EditorGUILayout.Toggle("Center Piece", roundabout.centerPiece);

        if (roundabout.centerPiece == true)
        {
            roundabout.centerPieceMaterial = (Material)EditorGUILayout.ObjectField("Center Piece Material", roundabout.centerPieceMaterial, typeof(Material), false);
        }

        GUIStyle guiStyle = new GUIStyle();

        guiStyle.fontStyle = FontStyle.Bold;

        GUILayout.Label("");
        GUILayout.Label("Connections", guiStyle);
        for (int i = 0; i < roundabout.connectionVertexIndex.Count; i++)
        {
            roundabout.connectionOpen[i] = EditorGUILayout.Foldout(roundabout.connectionOpen[i], "Connection #" + i);

            if (roundabout.connectionOpen[i] == true)
            {
                roundabout.connectionVertexIndex[i] = Mathf.Clamp(EditorGUILayout.IntField("Vertex Index", roundabout.connectionVertexIndex[i]), 0, roundabout.points.Length);
                roundabout.connectionWidth[i]       = Mathf.Max(0.1f, EditorGUILayout.FloatField("Width", roundabout.connectionWidth[i]));
                roundabout.connectionMaterial[i]    = (Material)EditorGUILayout.ObjectField("Material", roundabout.connectionMaterial[i], typeof(Material), false);

                if (GUILayout.Button("Remove Connection") == true)
                {
                    roundabout.connectionOpen.RemoveAt(i);
                    roundabout.connectionVertexIndex.RemoveAt(i);
                    roundabout.connectionWidth.RemoveAt(i);
                    roundabout.connectionMaterial.RemoveAt(i);
                    DestroyImmediate(roundabout.transform.GetChild(0).GetChild(i).gameObject);
                }
            }
        }

        if (GUILayout.Button("Add Connection"))
        {
            roundabout.connectionOpen.Add(true);
            roundabout.connectionVertexIndex.Add(0);
            roundabout.connectionWidth.Add(2);
            roundabout.connectionMaterial.Add(Resources.Load("Materials/Intersections/Intersection Connections/2L Connection") as Material);

            GameObject connection = new GameObject("Connection " + roundabout.transform.GetChild(0).childCount);
            connection.transform.SetParent(roundabout.transform.GetChild(0));
            connection.transform.localPosition = Vector3.zero;
            connection.hideFlags = HideFlags.NotEditable;

            GameObject connectionMesh = new GameObject("Mesh");
            connectionMesh.AddComponent <MeshFilter>();
            connectionMesh.AddComponent <MeshRenderer>();
            connectionMesh.AddComponent <MeshCollider>();
            connectionMesh.transform.SetParent(connection.transform);
            connectionMesh.transform.localPosition = Vector3.zero;
            connectionMesh.hideFlags = HideFlags.NotEditable;

            GameObject connectionPoint = new GameObject("Connection Point");
            connectionPoint.AddComponent <BoxCollider>();
            connectionPoint.GetComponent <BoxCollider>().size = new Vector3(roundabout.globalSettings.pointSize, roundabout.globalSettings.pointSize, roundabout.globalSettings.pointSize);
            connectionPoint.transform.SetParent(connection.transform);
            connectionPoint.transform.localPosition = Vector3.zero;
            connectionPoint.layer     = roundabout.globalSettings.intersectionPointsLayer;
            connectionPoint.hideFlags = HideFlags.NotEditable;
        }

        GUILayout.Label("");

        if (GUILayout.Button("Generate Roundabout"))
        {
            roundabout.transform.hasChanged = true;
        }

        if (GUILayout.Button("Convert To Mesh"))
        {
            Misc.ConvertToMesh(roundabout.gameObject, "Roundabout Mesh");
        }

        if (EditorGUI.EndChangeCheck() == true || roundabout.transform.hasChanged == true)
        {
            Misc.UpdateAllIntersectionConnections();
            roundabout.GenerateMeshes();
            roundabout.transform.hasChanged = false;
        }
    }
Exemplo n.º 4
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;
            }
        }
    }