private void OnEnable()
    {
        intersection = (DiamondIntersection)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("Upper Left");
            AddSide("Upper Right");
            AddSide("Lower Left");
            AddSide("Lower Right");

            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();
    }
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        intersection.centerMaterial = (Material)EditorGUILayout.ObjectField("Center Material", intersection.centerMaterial, typeof(Material), false);
        intersection.width          = Mathf.Max(0.1f, EditorGUILayout.FloatField("Width", intersection.width));
        intersection.height         = Mathf.Max(0.1f, EditorGUILayout.FloatField("Height", intersection.height));
        intersection.heightOffset   = Mathf.Max(0, EditorGUILayout.FloatField("Y Offset", intersection.heightOffset));

        GUIStyle guiStyle = new GUIStyle();

        guiStyle.fontStyle = FontStyle.Bold;

        GUILayout.Label("");
        GUILayout.Label("Upper Left Connection", guiStyle);
        intersection.upperLeftConnection = EditorGUILayout.Toggle("Upper Left Connection", intersection.upperLeftConnection);
        if (intersection.upperLeftConnection == true)
        {
            intersection.upperLeftConnectionMaterial   = (Material)EditorGUILayout.ObjectField("Upper Left Connection Material", intersection.upperLeftConnectionMaterial, typeof(Material), false);
            intersection.upperLeftConnectionHeight     = Mathf.Max(0.1f, EditorGUILayout.FloatField("Upper Left Connection Height", intersection.upperLeftConnectionHeight));
            intersection.upperLeftConnectionWidth      = Mathf.Max(0.1f, EditorGUILayout.FloatField("Upper Left Connection Width", intersection.upperLeftConnectionWidth));
            intersection.upperLeftConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Upper Left Connection Resolution", intersection.upperLeftConnectionResolution), 2, 15);
        }

        GUILayout.Label("");
        GUILayout.Label("Upper Right Connection", guiStyle);
        intersection.upperRightConnection = EditorGUILayout.Toggle("Upper Right Connection", intersection.upperRightConnection);
        if (intersection.upperRightConnection == true)
        {
            intersection.upperRightConnectionMaterial   = (Material)EditorGUILayout.ObjectField("Upper Right Connection Material", intersection.upperRightConnectionMaterial, typeof(Material), false);
            intersection.upperRightConnectionHeight     = Mathf.Max(0.1f, EditorGUILayout.FloatField("Upper Right Connection Height", intersection.upperRightConnectionHeight));
            intersection.upperRightConnectionWidth      = Mathf.Max(0.1f, EditorGUILayout.FloatField("Upper Right Connection Width", intersection.upperRightConnectionWidth));
            intersection.upperRightConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Upper Right Connection Resolution", intersection.upperRightConnectionResolution), 2, 15);
        }

        GUILayout.Label("");
        GUILayout.Label("Lower Left Connection", guiStyle);
        intersection.lowerLeftConnection = EditorGUILayout.Toggle("Lower Left Connection", intersection.lowerLeftConnection);
        if (intersection.lowerLeftConnection == true)
        {
            intersection.lowerLeftConnectionMaterial   = (Material)EditorGUILayout.ObjectField("Lower Left Connection Material", intersection.lowerLeftConnectionMaterial, typeof(Material), false);
            intersection.lowerLeftConnectionHeight     = Mathf.Max(0.1f, EditorGUILayout.FloatField("Lower Left Connection Height", intersection.lowerLeftConnectionHeight));
            intersection.lowerLeftConnectionWidth      = Mathf.Max(0.1f, EditorGUILayout.FloatField("Lower Left Connection Width", intersection.lowerLeftConnectionWidth));
            intersection.lowerLeftConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Lower Left Connection Resolution", intersection.lowerLeftConnectionResolution), 2, 15);
        }

        GUILayout.Label("");
        GUILayout.Label("Lower Right Connection", guiStyle);
        intersection.lowerRightConnection = EditorGUILayout.Toggle("Lower Right Connection", intersection.lowerRightConnection);
        if (intersection.lowerRightConnection == true)
        {
            intersection.lowerRightConnectionMaterial   = (Material)EditorGUILayout.ObjectField("Lower Right Connection Material", intersection.lowerRightConnectionMaterial, typeof(Material), false);
            intersection.lowerRightConnectionHeight     = Mathf.Max(0.1f, EditorGUILayout.FloatField("Lower Right Connection Height", intersection.lowerRightConnectionHeight));
            intersection.lowerRightConnectionWidth      = Mathf.Max(0.1f, EditorGUILayout.FloatField("Lower Right Connection Width", intersection.lowerRightConnectionWidth));
            intersection.lowerRightConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Lower Right Connection Resolution", intersection.lowerRightConnectionResolution), 2, 15);
        }

        if (EditorGUI.EndChangeCheck() == true || intersection.transform.hasChanged == true)
        {
            Misc.UpdateAllIntersectionConnections();
            intersection.GenerateMeshes();
            intersection.transform.hasChanged = false;
        }

        if (GUILayout.Button("Generate Intersection"))
        {
            intersection.GenerateMeshes();
        }
    }
Exemple #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;
            }
        }
    }