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(); }
private void DropMovingPoint() { objectToMove.GetComponent <BoxCollider>().enabled = true; if (objectToMove.transform.name == "Connection Point") { int nextIndex = objectToMove.transform.GetSiblingIndex(); if (nextIndex >= connections.Count) { nextIndex = 0; } if (roundaboutMode == true) { int index = objectToMove.transform.GetSiblingIndex() - 1; if (index % 2 == 0) { connections[index / 2].curvePoint = new Vector3(objectToMove.transform.position.x, transform.position.y, objectToMove.transform.position.z); } else { connections[(index - 1) / 2].curvePoint2 = new Vector3(objectToMove.transform.position.x, transform.position.y, objectToMove.transform.position.z); } } else { connections[objectToMove.transform.GetSiblingIndex() - 1].curvePoint = new Vector3(objectToMove.transform.position.x, transform.position.y, objectToMove.transform.position.z); } objectToMove = null; CreateMesh(); CreateCurvePoints(); } else { if (objectToMove.transform.parent.parent.GetComponent <RoadSegment>().curved == false) { objectToMove.transform.parent.GetChild(1).position = Misc.GetCenter(objectToMove.transform.parent.GetChild(0).position, objectToMove.transform.parent.GetChild(2).position); } CreateMesh(); objectToMove.transform.parent.parent.parent.parent.GetComponent <RoadCreator>().CreateMesh(); if (objectToMove.transform.name == "Start Point") { objectToMove.transform.parent.parent.parent.parent.GetComponent <RoadCreator>().UpdateStartConnectionData(); } else { objectToMove.transform.parent.parent.parent.parent.GetComponent <RoadCreator>().UpdateEndConnectionData(); } objectToMove = null; Roundabout.UpdateMaxRadius(this); } }
public void AddToRoundabout(Roundabout r, float angleDeg) { angleDeg = Mathf.Repeat(angleDeg, 360); transform.eulerAngles = new Vector3(0, angleDeg, 0); Vector3 target = Polar.FromPolar(angleDeg * Mathf.Deg2Rad, r.RadiusOuter, r.transform.position); transform.position = r.transform.position; _r1 = r; }
// END CUT HERE // BEGIN CUT HERE public static void Main() { try { Roundabout ___test = new Roundabout(); ___test.run_test(-1); } catch (Exception e) { //Console.WriteLine(e.StackTrace); Console.WriteLine(e.ToString()); } }
// END CUT HERE // BEGIN CUT HERE public static void Main() { try { Roundabout ___test = new Roundabout(); ___test.run_test(-1); } catch(Exception e) { //Console.WriteLine(e.StackTrace); Console.WriteLine(e.ToString()); } }
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); }
public void CreateMesh(bool fromRoad = false) { if (settings == null) { settings = RoadCreatorSettings.GetSerializedSettings(); } for (int i = 0; i < connections.Count; i++) { if (connections[i].road == null) { connections.RemoveAt(i); } } if (connections.Count < 2 && roundaboutMode == false) { RemoveIntersection(); } else { CheckMaterialsAndPrefabs(); if (resetCurvePointsOnUpdate == true) { ResetCurvePointPositions(); } if (roundaboutMode == true) { Roundabout.GenerateRoundabout(this); } else { if (outerExtraMeshesAsRoads == true) { ResetExtraMeshes(); CreateExtraMeshesFromRoads(); } GenerateMesh(); } } if (fromRoad == false) { for (int i = 0; i < connections.Count; i++) { RoadCreator roadCreator = connections[i].road.transform.parent.parent.parent.parent.GetComponent <RoadCreator>(); roadCreator.CreateMesh(true); } } }
private void UpdaterEventHandler(object myObject, EventArgs myEventArgs) { (_roundabout as ConventionalRoundabout)?.IterateSimaultion(); if (_roundabout is IntelligentRoundabout) { _roundabout = ((IntelligentRoundabout)_roundabout).GetBestNextOptionMain(); } pictureBox3.Invalidate(); CurrTimeLabel.Text = $"Time : {Roundabout.MainCurrTime} sec"; CheckSimulationFinished(); }
public void SetActiveRoundabout(Roundabout r, bool block) { if (r == _r1) { _activeSpawnPoint = _entry2; if (block) { _block1.SetActive(true); } } else if (r == _r2) { _activeSpawnPoint = _entry1; if (block) { _block2.SetActive(true); } } }
public void CreateMesh(bool fromRoad = false) { if (settings == null) { settings = RoadCreatorSettings.GetSerializedSettings(); } for (int i = 0; i < connections.Count; i++) { if (connections[i].road == null) { connections.RemoveAt(i); } } if (connections.Count < 2 && roundaboutMode == false) { RemoveIntersection(); } else { CheckMaterialsAndPrefabs(); if (roundaboutMode == true) { Roundabout.GenerateRoundabout(this); } else { GenerateNormalMesh(); } } if (fromRoad == false) { for (int i = 0; i < connections.Count; i++) { connections[i].road.transform.parent.parent.parent.parent.GetComponent <RoadCreator>().CreateMesh(true); } } }
public void Activate() { if (Active != this) { Active = this; foreach (var r in All) { if (r != this) { Destroy(r.gameObject); } } foreach (var r in Road.All) { if (!_roads.Contains(r)) { Destroy(r.gameObject); } } } }
protected virtual void OnTriggerEnter(Collider c) { if (!_currentRoad && !_currentRoundabout) { // Just spawned if (_canStartOnRoad) { _currentRoad = c.GetComponent <Road>(); } _currentRoundabout = c.GetComponent <Roundabout>(); if (_currentRoad) { transform.position = _nearestEntry; transform.forward = _currentRoadFwd = _currentRoad.GetForward(transform.position); } else if (_currentRoundabout) { _theta = Polar.ToPolar(transform.position, _currentRoundabout.transform.position); transform.position = Polar.FromPolar(_theta, _currentRoundabout.RadiusOuter, _currentRoundabout.transform.position); transform.forward = Polar.PolarForward(_theta, _currentRoundabout.RadiusOuter); } } else if (_currentRoad) { var r = c.GetComponent <Roundabout>(); if (r) { _currentRoundabout = r; _theta = Polar.ToPolar(transform.position, _currentRoundabout.transform.position); Vector3 target = Polar.FromPolar(_theta + _entryOffsetRadians, CurrentRadius, _currentRoundabout.transform.position); Vector3 fwd = Polar.PolarForward(_theta + _entryOffsetRadians, CurrentRadius); Transfer(target, fwd, () => { _currentRoad = null; _theta = _theta + _entryOffsetRadians; }); OnEnteredRoundabout(r); } } }
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); }
private void StartButton_Click(object sender, EventArgs e) { Roundabout.SimulationDuration = (int)SimulationDurationSelector.Value; List <TrafficPattern> patterns = new List <TrafficPattern>(); //Custom car flows //NORTH if (CheckBoxNorth.Checked) { patterns.Add(new TrafficPattern(EntryPosition.North, CarPerMinN.IntVal(), ToNFromN.IntVal(), ToEFromN.IntVal(), ToSFromN.IntVal(), ToWFromN.IntVal())); } else { patterns.Add(new TrafficPattern(EntryPosition.North)); } //WEST if (CheckBoxWest.Checked) { patterns.Add(new TrafficPattern(EntryPosition.West, CarPerMinW.IntVal(), ToNFromW.IntVal(), ToEFromW.IntVal(), ToSFromW.IntVal(), ToWFromW.IntVal())); } else { patterns.Add(new TrafficPattern(EntryPosition.West)); } //SOUTH if (CheckBoxSouth.Checked) { patterns.Add(new TrafficPattern(EntryPosition.South, CarPerMinS.IntVal(), ToNFromS.IntVal(), ToEFromS.IntVal(), ToSFromS.IntVal(), ToWFromS.IntVal())); } else { patterns.Add(new TrafficPattern(EntryPosition.South)); } //SOUTH if (CheckBoxEast.Checked) { patterns.Add(new TrafficPattern(EntryPosition.East, CarPerMinE.IntVal(), ToNFromE.IntVal(), ToEFromE.IntVal(), ToSFromE.IntVal(), ToWFromE.IntVal())); } else { patterns.Add(new TrafficPattern(EntryPosition.East)); } //Custom car flows end LaneGroup1.Enabled = false; LaneGroup2.Enabled = false; LaneGroup3.Enabled = false; LaneGroup4.Enabled = false; Roundabout.SimulationDuration = SimulationDurationSelector.IntVal(); SimulationDurationSelector.Enabled = false; //Init roundabout object if (ConventialRadio.Checked) { _roundabout = new ConventionalRoundabout(); _roundabout.Init(patterns); } else { _roundabout = new IntelligentRoundabout(); _roundabout.Init(patterns); } ConventialRadio.Enabled = false; IntelligentRadio.Enabled = false; ResumeButton.Enabled = true; PauseButton.Enabled = false; ManualIterButton.Enabled = true; }
protected override void OnEnteredRoundabout(Roundabout r) { _currentRoundabout.UnregisterAi(this); r.RegisterAi(this); _currentRoadFwd = Vector3.zero; }
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; } } }
public void RoundaboutAdded(Roundabout r) { _r2 = r; }
protected virtual void OnEnteredRoundabout(Roundabout r) { }
public void SetupForRoundabout(Roundabout roundabout) { this.roundabout = roundabout; CurrentLane = this.roundabout.lanes; targetLane = CurrentLane; }