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(); }
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("Up Connection", guiStyle); intersection.upConnection = EditorGUILayout.Toggle("Up Connection", intersection.upConnection); if (intersection.upConnection == true) { intersection.upConnectionMaterial = (Material)EditorGUILayout.ObjectField("Up Connection Material", intersection.upConnectionMaterial, typeof(Material), false); intersection.upConnectionHeight = Mathf.Max(0.1f, EditorGUILayout.FloatField("Up Connection Height", intersection.upConnectionHeight)); intersection.upConnectionWidth = Mathf.Max(0.1f, EditorGUILayout.FloatField("Up Connection Width", intersection.upConnectionWidth)); intersection.upConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Up Connection Resolution", intersection.upConnectionResolution), 2, 15); } GUILayout.Label(""); GUILayout.Label("Down Connection", guiStyle); intersection.downConnection = EditorGUILayout.Toggle("Down Connection", intersection.downConnection); if (intersection.downConnection == true) { intersection.downConnectionMaterial = (Material)EditorGUILayout.ObjectField("Down Connection Material", intersection.downConnectionMaterial, typeof(Material), false); intersection.downConnectionHeight = Mathf.Max(0.1f, EditorGUILayout.FloatField("Down Connection Height", intersection.downConnectionHeight)); intersection.downConnectionWidth = Mathf.Max(0.1f, EditorGUILayout.FloatField("Down Connection Width", intersection.downConnectionWidth)); intersection.downConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Down Connection Resolution", intersection.downConnectionResolution), 2, 15); } GUILayout.Label(""); GUILayout.Label("Left Connection", guiStyle); intersection.leftConnection = EditorGUILayout.Toggle("Left Connection", intersection.leftConnection); if (intersection.leftConnection == true) { intersection.leftConnectionMaterial = (Material)EditorGUILayout.ObjectField("Left Connection Material", intersection.leftConnectionMaterial, typeof(Material), false); intersection.leftConnectionHeight = Mathf.Max(0.1f, EditorGUILayout.FloatField("Left Connection Height", intersection.leftConnectionHeight)); intersection.leftConnectionWidth = Mathf.Max(0.1f, EditorGUILayout.FloatField("Left Connection Width", intersection.leftConnectionWidth)); intersection.leftConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Left Connection Resolution", intersection.leftConnectionResolution), 2, 15); } GUILayout.Label(""); GUILayout.Label("Right Connection", guiStyle); intersection.rightConnection = EditorGUILayout.Toggle("Right Connection", intersection.rightConnection); if (intersection.rightConnection == true) { intersection.rightConnectionMaterial = (Material)EditorGUILayout.ObjectField("Right Connection Material", intersection.rightConnectionMaterial, typeof(Material), false); intersection.rightConnectionHeight = Mathf.Max(0.1f, EditorGUILayout.FloatField("Right Connection Height", intersection.rightConnectionHeight)); intersection.rightConnectionWidth = Mathf.Max(0.1f, EditorGUILayout.FloatField("Right Connection Width", intersection.rightConnectionWidth)); intersection.rightConnectionResolution = Mathf.Clamp(EditorGUILayout.IntField("Right Connection Resolution", intersection.rightConnectionResolution), 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(); } }
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; } } }