示例#1
0
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        roadSplitter.material     = (Material)EditorGUILayout.ObjectField("Material", roadSplitter.material, typeof(Material), false);
        roadSplitter.leftWidth    = Mathf.Max(0.1f, EditorGUILayout.FloatField("Left Width", roadSplitter.leftWidth));
        roadSplitter.rightWidth   = Mathf.Max(0.1f, EditorGUILayout.FloatField("Right Width", roadSplitter.rightWidth));
        roadSplitter.height       = Mathf.Max(0.1f, EditorGUILayout.FloatField("Height", roadSplitter.height));
        roadSplitter.heightOffset = Mathf.Max(0, EditorGUILayout.FloatField("Y Offset", roadSplitter.heightOffset));

        roadSplitter.rightXOffset      = EditorGUILayout.FloatField("Right X Offset", roadSplitter.rightXOffset);
        roadSplitter.lowerRightXOffset = EditorGUILayout.FloatField("Lower Right X Offset", roadSplitter.lowerRightXOffset);
        roadSplitter.upperRightXOffset = EditorGUILayout.FloatField("Upper Right X Offset", roadSplitter.upperRightXOffset);

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

        if (GUILayout.Button("Generate Mesh"))
        {
            roadSplitter.GenerateMesh();
        }
    }
示例#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();
    }
示例#3
0
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        roadSplitter.material     = (Material)EditorGUILayout.ObjectField("Material", roadSplitter.material, typeof(Material), false);
        roadSplitter.leftWidth    = Mathf.Max(0.1f, EditorGUILayout.FloatField("Left Width", roadSplitter.leftWidth));
        roadSplitter.rightWidth   = Mathf.Max(0.1f, EditorGUILayout.FloatField("Right Width", roadSplitter.rightWidth));
        roadSplitter.height       = Mathf.Max(0.1f, EditorGUILayout.FloatField("Height", roadSplitter.height));
        roadSplitter.heightOffset = Mathf.Max(0, EditorGUILayout.FloatField("Y Offset", roadSplitter.heightOffset));

        roadSplitter.rightXOffset      = EditorGUILayout.FloatField("Right X Offset", roadSplitter.rightXOffset);
        roadSplitter.lowerRightXOffset = EditorGUILayout.FloatField("Lower Right X Offset", roadSplitter.lowerRightXOffset);
        roadSplitter.upperRightXOffset = EditorGUILayout.FloatField("Upper Right X Offset", roadSplitter.upperRightXOffset);

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

        if (GUILayout.Button("Generate Mesh"))
        {
            roadSplitter.GenerateMesh();
        }

        if (GUILayout.Button("Convert To Mesh"))
        {
            GameObject mesh = roadSplitter.transform.GetChild(1).gameObject;
            Undo.SetTransformParent(mesh.transform, null, "Created Road Splitter Mesh");
            mesh.hideFlags             = HideFlags.None;
            mesh.name                  = "Road Splitter Mesh";
            Selection.activeGameObject = mesh;

            Undo.DestroyObjectImmediate(roadSplitter.gameObject);
        }
    }
示例#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;
            }
        }
    }